Spaces:
Sleeping
Sleeping
Update video_processing.py
Browse files- video_processing.py +7 -6
video_processing.py
CHANGED
@@ -14,6 +14,8 @@ from cachetools import cached, TTLCache
|
|
14 |
import numpy as np
|
15 |
import logging
|
16 |
from multiprocessing import Pool
|
|
|
|
|
17 |
|
18 |
|
19 |
# Setup basic logging
|
@@ -103,18 +105,17 @@ def convert_timestamp_to_seconds(timestamp):
|
|
103 |
h, m, s = map(float, timestamp.split(':'))
|
104 |
return int(h) * 3600 + int(m) * 60 + s
|
105 |
|
106 |
-
def extract_frame_at_time(
|
107 |
-
video_clip, t = args
|
108 |
return video_clip.get_frame(t / video_clip.fps)
|
109 |
|
110 |
def extract_frames(video_path, start_time, end_time):
|
111 |
video_clip = VideoFileClip(video_path).subclip(start_time, end_time)
|
112 |
frame_times = range(0, int(video_clip.duration * video_clip.fps), int(video_clip.fps / 10))
|
113 |
|
114 |
-
|
115 |
-
with
|
116 |
-
#
|
117 |
-
frames =
|
118 |
|
119 |
return frames
|
120 |
|
|
|
14 |
import numpy as np
|
15 |
import logging
|
16 |
from multiprocessing import Pool
|
17 |
+
from concurrent.futures import ThreadPoolExecutor
|
18 |
+
|
19 |
|
20 |
|
21 |
# Setup basic logging
|
|
|
105 |
h, m, s = map(float, timestamp.split(':'))
|
106 |
return int(h) * 3600 + int(m) * 60 + s
|
107 |
|
108 |
+
def extract_frame_at_time(video_clip, t):
|
|
|
109 |
return video_clip.get_frame(t / video_clip.fps)
|
110 |
|
111 |
def extract_frames(video_path, start_time, end_time):
|
112 |
video_clip = VideoFileClip(video_path).subclip(start_time, end_time)
|
113 |
frame_times = range(0, int(video_clip.duration * video_clip.fps), int(video_clip.fps / 10))
|
114 |
|
115 |
+
frames = []
|
116 |
+
with ThreadPoolExecutor() as executor:
|
117 |
+
# Using threads to handle frame extraction
|
118 |
+
frames = list(executor.map(lambda t: extract_frame_at_time(video_clip, t), frame_times))
|
119 |
|
120 |
return frames
|
121 |
|