Spaces:
Running
on
Zero
Running
on
Zero
Update src/utils.py
Browse files- src/utils.py +0 -21
src/utils.py
CHANGED
@@ -7,26 +7,6 @@ from decord import VideoReader, cpu
|
|
7 |
MAX_NUM_FRAMES = 64 # If CUDA OOM, set a smaller number
|
8 |
|
9 |
|
10 |
-
def encode_image(image):
|
11 |
-
if not isinstance(image, Image.Image):
|
12 |
-
if hasattr(image, 'path'):
|
13 |
-
image = Image.open(image.path).convert("RGB")
|
14 |
-
else:
|
15 |
-
image = Image.open(image.file.path).convert("RGB")
|
16 |
-
# resize to max_size
|
17 |
-
max_size = 448*16
|
18 |
-
if max(image.size) > max_size:
|
19 |
-
w,h = image.size
|
20 |
-
if w > h:
|
21 |
-
new_w = max_size
|
22 |
-
new_h = int(h * max_size / w)
|
23 |
-
else:
|
24 |
-
new_h = max_size
|
25 |
-
new_w = int(w * max_size / h)
|
26 |
-
image = image.resize((new_w, new_h), resample=Image.BICUBIC)
|
27 |
-
return image
|
28 |
-
|
29 |
-
|
30 |
def encode_video(video_path):
|
31 |
"""
|
32 |
Encodes a video file into a list of frames.
|
@@ -65,7 +45,6 @@ def encode_video(video_path):
|
|
65 |
# Extract frames from the video
|
66 |
frames = vr.get_batch(frame_idx).asnumpy()
|
67 |
frames = [Image.fromarray(v.astype("uint8")) for v in frames]
|
68 |
-
frames = [encode_image(v) for v in frames]
|
69 |
|
70 |
# Return video frames
|
71 |
return frames
|
|
|
7 |
MAX_NUM_FRAMES = 64 # If CUDA OOM, set a smaller number
|
8 |
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def encode_video(video_path):
|
11 |
"""
|
12 |
Encodes a video file into a list of frames.
|
|
|
45 |
# Extract frames from the video
|
46 |
frames = vr.get_batch(frame_idx).asnumpy()
|
47 |
frames = [Image.fromarray(v.astype("uint8")) for v in frames]
|
|
|
48 |
|
49 |
# Return video frames
|
50 |
return frames
|