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
|
|
@@ -333,15 +334,34 @@ def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_
|
|
| 333 |
fps = original_fps # Frames per second
|
| 334 |
total_frames = len(jpeg_images)
|
| 335 |
clip = ImageSequenceClip(jpeg_images, fps=fps)
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
# Write the result to a file
|
| 340 |
final_vid_output_path = "output_video.mp4"
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
|
|
|
|
|
|
| 345 |
return gr.update(value=None), gr.update(value=final_vid_output_path)
|
| 346 |
|
| 347 |
def update_ui(vis_frame_type):
|
|
|
|
| 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 |
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 |
+
# Close the progress bar after the process is finished
|
| 364 |
+
logger.close()
|
| 365 |
return gr.update(value=None), gr.update(value=final_vid_output_path)
|
| 366 |
|
| 367 |
def update_ui(vis_frame_type):
|