Update app.py
Browse files
app.py
CHANGED
|
@@ -28,6 +28,7 @@ from PIL import Image, ImageFilter
|
|
| 28 |
from sam2.build_sam import build_sam2_video_predictor
|
| 29 |
|
| 30 |
from moviepy.editor import ImageSequenceClip
|
|
|
|
| 31 |
|
| 32 |
def get_video_fps(video_path):
|
| 33 |
# Open the video file
|
|
@@ -330,10 +331,17 @@ def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_
|
|
| 330 |
# Create a video clip from the image sequence
|
| 331 |
original_fps = get_video_fps(video_in)
|
| 332 |
fps = original_fps # Frames per second
|
|
|
|
| 333 |
clip = ImageSequenceClip(jpeg_images, fps=fps)
|
|
|
|
|
|
|
|
|
|
| 334 |
# Write the result to a file
|
| 335 |
final_vid_output_path = "output_video.mp4"
|
| 336 |
-
|
|
|
|
|
|
|
|
|
|
| 337 |
return gr.update(value=None), gr.update(value=final_vid_output_path)
|
| 338 |
|
| 339 |
def update_ui(vis_frame_type):
|
|
@@ -342,6 +350,7 @@ def update_ui(vis_frame_type):
|
|
| 342 |
elif vis_frame_type == "render":
|
| 343 |
return gr.update(visible=False), gr.update(visible=True)
|
| 344 |
|
|
|
|
| 345 |
with gr.Blocks() as demo:
|
| 346 |
first_frame_path = gr.State()
|
| 347 |
tracking_points = gr.State([])
|
|
|
|
| 28 |
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
|
|
|
|
| 331 |
# Create a video clip from the image sequence
|
| 332 |
original_fps = get_video_fps(video_in)
|
| 333 |
fps = original_fps # Frames per second
|
| 334 |
+
total_frames = len(jpeg_images)
|
| 335 |
clip = ImageSequenceClip(jpeg_images, fps=fps)
|
| 336 |
+
# Define a callback function to update the tqdm progress bar
|
| 337 |
+
def tqdm_callback(progress):
|
| 338 |
+
pbar.update(progress - pbar.n)
|
| 339 |
# Write the result to a file
|
| 340 |
final_vid_output_path = "output_video.mp4"
|
| 341 |
+
# Create a tqdm progress bar with the total set to the number of frames
|
| 342 |
+
with tqdm(total=total_frames) as pbar:
|
| 343 |
+
# Write the result to a file with the progress callback
|
| 344 |
+
clip.write_videofile(final_vid_output_path, codec='libx264', progress_bar=False, verbose=False, logger=None, progress_callback=tqdm_callback)
|
| 345 |
return gr.update(value=None), gr.update(value=final_vid_output_path)
|
| 346 |
|
| 347 |
def update_ui(vis_frame_type):
|
|
|
|
| 350 |
elif vis_frame_type == "render":
|
| 351 |
return gr.update(visible=False), gr.update(visible=True)
|
| 352 |
|
| 353 |
+
|
| 354 |
with gr.Blocks() as demo:
|
| 355 |
first_frame_path = gr.State()
|
| 356 |
tracking_points = gr.State([])
|