Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
@@ -29,6 +29,7 @@ from sam2.build_sam import build_sam2_video_predictor
|
|
29 |
|
30 |
from moviepy.editor import ImageSequenceClip
|
31 |
from tqdm import tqdm
|
|
|
32 |
|
33 |
def get_video_fps(video_path):
|
34 |
# Open the video file
|
@@ -335,13 +336,28 @@ def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_
|
|
335 |
clip = ImageSequenceClip(jpeg_images, fps=fps)
|
336 |
# Write the result to a file
|
337 |
final_vid_output_path = "output_video.mp4"
|
338 |
-
|
339 |
-
with
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
|
346 |
|
347 |
|
|
|
29 |
|
30 |
from moviepy.editor import ImageSequenceClip
|
31 |
from tqdm import tqdm
|
32 |
+
import re
|
33 |
|
34 |
def get_video_fps(video_path):
|
35 |
# Open the video file
|
|
|
336 |
clip = ImageSequenceClip(jpeg_images, fps=fps)
|
337 |
# Write the result to a file
|
338 |
final_vid_output_path = "output_video.mp4"
|
339 |
+
|
340 |
+
# Initialize the tqdm progress bar with the total number of frames
|
341 |
+
pbar = tqdm(total=total_frames, desc="Rendering video")
|
342 |
+
|
343 |
+
# Define a function to update the progress bar
|
344 |
+
def update_progress(txt):
|
345 |
+
# Extract progress from the log message
|
346 |
+
progress_match = re.search(r"frame\s+(\d+)", txt)
|
347 |
+
if progress_match:
|
348 |
+
current_frame = int(progress_match.group(1))
|
349 |
+
pbar.n = current_frame
|
350 |
+
pbar.refresh()
|
351 |
+
|
352 |
+
# Write the result to a file
|
353 |
+
clip.write_videofile(
|
354 |
+
final_vid_output_path,
|
355 |
+
codec='libx264',
|
356 |
+
logger=lambda txt: update_progress(txt)
|
357 |
+
)
|
358 |
+
|
359 |
+
# Close the progress bar after the process is finished
|
360 |
+
pbar.close()
|
361 |
|
362 |
|
363 |
|