juanpablomesa
commited on
Commit
·
39adffa
1
Parent(s):
ccc4e99
Changed OpenCV2 for decord in extracting videoframes
Browse files- handler.py +4 -4
handler.py
CHANGED
@@ -10,6 +10,8 @@ from PIL import Image
|
|
10 |
from transformers import AutoTokenizer, XCLIPModel, XCLIPProcessor
|
11 |
from huggingface_hub import logging
|
12 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
|
|
13 |
|
14 |
import timeit
|
15 |
|
@@ -88,14 +90,12 @@ class EndpointHandler:
|
|
88 |
|
89 |
return frames
|
90 |
|
91 |
-
from decord import VideoReader
|
92 |
-
from decord import cpu
|
93 |
-
|
94 |
def extract_evenly_spaced_frames_from_bytes(
|
95 |
self, video_bytes: bytes, num_frames: int = 32
|
96 |
) -> list:
|
97 |
# Create a VideoReader object from bytes
|
98 |
-
|
|
|
99 |
|
100 |
# Get the total number of frames in the video
|
101 |
total_frames = len(vr)
|
|
|
10 |
from transformers import AutoTokenizer, XCLIPModel, XCLIPProcessor
|
11 |
from huggingface_hub import logging
|
12 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
13 |
+
from decord import VideoReader
|
14 |
+
from decord import cpu
|
15 |
|
16 |
import timeit
|
17 |
|
|
|
90 |
|
91 |
return frames
|
92 |
|
|
|
|
|
|
|
93 |
def extract_evenly_spaced_frames_from_bytes(
|
94 |
self, video_bytes: bytes, num_frames: int = 32
|
95 |
) -> list:
|
96 |
# Create a VideoReader object from bytes
|
97 |
+
file_obj = io.BytesIO(video_bytes)
|
98 |
+
vr = VideoReader(file_obj, ctx=cpu(0))
|
99 |
|
100 |
# Get the total number of frames in the video
|
101 |
total_frames = len(vr)
|