Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,7 +29,6 @@ from sam2.build_sam import build_sam2_video_predictor
|
|
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
|
@@ -334,34 +333,18 @@ def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_
|
|
334 |
fps = original_fps # Frames per second
|
335 |
total_frames = len(jpeg_images)
|
336 |
clip = ImageSequenceClip(jpeg_images, fps=fps)
|
337 |
-
|
338 |
-
# Create a custom logger class to use tqdm for progress display
|
339 |
-
class TqdmLogger:
|
340 |
-
def __init__(self, total):
|
341 |
-
self.pbar = tqdm(total=total)
|
342 |
-
|
343 |
-
def __call__(self, message):
|
344 |
-
# Extract progress percentage from the message
|
345 |
-
progress_match = re.search(r"frame\s+(\d+)", message)
|
346 |
-
if progress_match:
|
347 |
-
current_frame = int(progress_match.group(1))
|
348 |
-
self.pbar.n = current_frame
|
349 |
-
self.pbar.refresh()
|
350 |
-
|
351 |
-
def close(self):
|
352 |
-
self.pbar.close()
|
353 |
-
|
354 |
-
# Initialize the custom logger with total frames
|
355 |
-
logger = TqdmLogger(total_frames)
|
356 |
-
|
357 |
# Write the result to a file
|
358 |
final_vid_output_path = "output_video.mp4"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
359 |
|
360 |
-
# Write the result to a file using the custom logger for progress
|
361 |
-
clip.write_videofile(final_vid_output_path, codec='libx264', logger=logger)
|
362 |
|
363 |
-
|
364 |
-
logger.close()
|
365 |
return gr.update(value=None), gr.update(value=final_vid_output_path)
|
366 |
|
367 |
def update_ui(vis_frame_type):
|
|
|
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
|
|
|
333 |
fps = original_fps # Frames per second
|
334 |
total_frames = len(jpeg_images)
|
335 |
clip = ImageSequenceClip(jpeg_images, fps=fps)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
# Write the result to a file
|
337 |
final_vid_output_path = "output_video.mp4"
|
338 |
+
# Use tqdm progress bar while writing the video file
|
339 |
+
with tqdm(total=total_frames, desc="Rendering video") as pbar:
|
340 |
+
def update_progress(current_frame):
|
341 |
+
pbar.update(current_frame - pbar.n)
|
342 |
+
|
343 |
+
clip.write_videofile("output_video.mp4", codec='libx264', progress_bar=False, verbose=False, logger=None, progress_callback=update_progress)
|
344 |
+
|
345 |
|
|
|
|
|
346 |
|
347 |
+
|
|
|
348 |
return gr.update(value=None), gr.update(value=final_vid_output_path)
|
349 |
|
350 |
def update_ui(vis_frame_type):
|