Spaces:
Running
Running
Update util.py
Browse files
util.py
CHANGED
@@ -158,10 +158,17 @@ def scatter_pitch(ax, t, f, s=60, marker="o", color="limegreen", label="Pitch"):
|
|
158 |
ax.legend(loc="upper left")
|
159 |
|
160 |
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
frame = audio_loader.crop_or_pad_to_size(frame, size=(270, 480))
|
166 |
return frame
|
167 |
|
|
|
158 |
ax.legend(loc="upper left")
|
159 |
|
160 |
|
161 |
+
def load_frame(video_path, video_backend="decord"):
|
162 |
+
if video_backend == "decord":
|
163 |
+
vr = decord.VideoReader(video_path, num_threads=1)
|
164 |
+
frame = PIL.Image.fromarray(vr[0].asnumpy())
|
165 |
+
elif video_backend == "torchvision":
|
166 |
+
import torchvision.io as tio
|
167 |
+
video, _, _ = tio.read_video(video_path, pts_unit="sec")
|
168 |
+
frame = video[0]
|
169 |
+
frame = PIL.Image.fromarray(frame.numpy())
|
170 |
+
else:
|
171 |
+
raise ValueError(f"Unknown video backend: {video_backend}")
|
172 |
frame = audio_loader.crop_or_pad_to_size(frame, size=(270, 480))
|
173 |
return frame
|
174 |
|