Spaces:
Running
on
Zero
Running
on
Zero
take every n frame
Browse files- app.py +6 -4
- utils/video.py +5 -2
app.py
CHANGED
@@ -77,19 +77,21 @@ def process_video(
|
|
77 |
# cleanup of old video files
|
78 |
remove_files_older_than(RESULTS, 30)
|
79 |
|
|
|
|
|
80 |
video_info = sv.VideoInfo.from_video_path(input_video)
|
81 |
-
video_info.fps = video_info.fps //
|
82 |
-
total = calculate_end_frame_index(input_video)
|
83 |
frame_generator = sv.get_video_frames_generator(
|
84 |
source_path=input_video,
|
85 |
end=total,
|
86 |
-
stride=
|
87 |
)
|
88 |
result_file_name = generate_file_name(extension="mp4")
|
89 |
result_file_path = os.path.join(RESULTS, result_file_name)
|
90 |
TRACKER.reset()
|
91 |
with sv.VideoSink(result_file_path, video_info=video_info) as sink:
|
92 |
-
for _ in tqdm(range(total //
|
93 |
frame = next(frame_generator)
|
94 |
caption = run_captioning(
|
95 |
model=MODEL,
|
|
|
77 |
# cleanup of old video files
|
78 |
remove_files_older_than(RESULTS, 30)
|
79 |
|
80 |
+
OUTPUT_LENGTH = 4
|
81 |
+
|
82 |
video_info = sv.VideoInfo.from_video_path(input_video)
|
83 |
+
video_info.fps = video_info.fps // OUTPUT_LENGTH
|
84 |
+
total = calculate_end_frame_index(input_video, OUTPUT_LENGTH)
|
85 |
frame_generator = sv.get_video_frames_generator(
|
86 |
source_path=input_video,
|
87 |
end=total,
|
88 |
+
stride=OUTPUT_LENGTH
|
89 |
)
|
90 |
result_file_name = generate_file_name(extension="mp4")
|
91 |
result_file_path = os.path.join(RESULTS, result_file_name)
|
92 |
TRACKER.reset()
|
93 |
with sv.VideoSink(result_file_path, video_info=video_info) as sink:
|
94 |
+
for _ in tqdm(range(total // OUTPUT_LENGTH), desc="Processing video..."):
|
95 |
frame = next(frame_generator)
|
96 |
caption = run_captioning(
|
97 |
model=MODEL,
|
utils/video.py
CHANGED
@@ -47,11 +47,14 @@ def remove_files_older_than(directory: str, diff_minutes: int) -> None:
|
|
47 |
)
|
48 |
|
49 |
|
50 |
-
def calculate_end_frame_index(
|
|
|
|
|
|
|
51 |
video_info = sv.VideoInfo.from_video_path(source_video_path)
|
52 |
return min(
|
53 |
video_info.total_frames,
|
54 |
-
video_info.fps *
|
55 |
)
|
56 |
|
57 |
|
|
|
47 |
)
|
48 |
|
49 |
|
50 |
+
def calculate_end_frame_index(
|
51 |
+
source_video_path: str,
|
52 |
+
max_video_length_sec: int = MAX_VIDEO_LENGTH_SEC
|
53 |
+
) -> int:
|
54 |
video_info = sv.VideoInfo.from_video_path(source_video_path)
|
55 |
return min(
|
56 |
video_info.total_frames,
|
57 |
+
video_info.fps * max_video_length_sec
|
58 |
)
|
59 |
|
60 |
|