Spaces:
Runtime error
Runtime error
Commit ·
8805736
1
Parent(s): f244820
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,16 +22,24 @@ def get_video_length(file_path):
|
|
| 22 |
return length
|
| 23 |
|
| 24 |
def read_video_opencv(file_path, indices):
|
| 25 |
-
cap = cv2.VideoCapture(file_path)
|
| 26 |
frames = []
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
return frames
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
def sample_uniform_frame_indices(clip_len, seg_len):
|
| 36 |
if seg_len < clip_len:
|
| 37 |
repeat_factor = np.ceil(clip_len / seg_len).astype(int)
|
|
@@ -112,4 +120,4 @@ iface = gr.Interface(
|
|
| 112 |
live=False
|
| 113 |
)
|
| 114 |
|
| 115 |
-
iface.launch(
|
|
|
|
| 22 |
return length
|
| 23 |
|
| 24 |
def read_video_opencv(file_path, indices):
|
|
|
|
| 25 |
frames = []
|
| 26 |
+
with ThreadPoolExecutor() as executor:
|
| 27 |
+
futures = [executor.submit(get_frame, file_path, i) for i in indices]
|
| 28 |
+
for future in futures:
|
| 29 |
+
frame = future.result()
|
| 30 |
+
if frame is not None:
|
| 31 |
+
frames.append(frame)
|
| 32 |
return frames
|
| 33 |
|
| 34 |
+
def get_frame(file_path, index):
|
| 35 |
+
cap = cv2.VideoCapture(file_path)
|
| 36 |
+
cap.set(cv2.CAP_PROP_POS_FRAMES, index)
|
| 37 |
+
ret, frame = cap.read()
|
| 38 |
+
cap.release()
|
| 39 |
+
if ret:
|
| 40 |
+
return cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 41 |
+
return None
|
| 42 |
+
|
| 43 |
def sample_uniform_frame_indices(clip_len, seg_len):
|
| 44 |
if seg_len < clip_len:
|
| 45 |
repeat_factor = np.ceil(clip_len / seg_len).astype(int)
|
|
|
|
| 120 |
live=False
|
| 121 |
)
|
| 122 |
|
| 123 |
+
iface.launch()
|