Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,6 +38,15 @@ from sam2.build_sam import build_sam2_video_predictor
|
|
| 38 |
|
| 39 |
from moviepy.editor import ImageSequenceClip
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
def get_video_fps(video_path):
|
| 42 |
# Open the video file
|
| 43 |
cap = cv2.VideoCapture(video_path)
|
|
@@ -401,9 +410,9 @@ def propagate_to_all(video_in, checkpoint, stored_inference_state, stored_frame_
|
|
| 401 |
elif vis_frame_type == "render":
|
| 402 |
# Create a video clip from the image sequence
|
| 403 |
original_fps = get_video_fps(video_in)
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
clip = ImageSequenceClip(jpeg_images, fps=fps)
|
| 407 |
# Write the result to a file
|
| 408 |
final_vid_output_path = "output_video.mp4"
|
| 409 |
|
|
@@ -521,7 +530,10 @@ with gr.Blocks(css=css) as demo:
|
|
| 521 |
with gr.Group():
|
| 522 |
with gr.Row():
|
| 523 |
vis_frame_type = gr.Radio(label="Propagation level", choices=["check", "render"], value="check", scale=2)
|
| 524 |
-
|
|
|
|
|
|
|
|
|
|
| 525 |
reset_prpgt_brn = gr.Button("Reset", visible=False)
|
| 526 |
output_propagated = gr.Gallery(label="Propagated Mask samples gallery", columns=4, visible=False)
|
| 527 |
output_video = gr.Video(visible=False)
|
|
|
|
| 38 |
|
| 39 |
from moviepy.editor import ImageSequenceClip
|
| 40 |
|
| 41 |
+
def sparse_sampling(jpeg_images, original_fps, target_fps=5):
|
| 42 |
+
# Calculate the frame interval for sampling based on the target fps
|
| 43 |
+
frame_interval = int(original_fps // target_fps)
|
| 44 |
+
|
| 45 |
+
# Sparse sample the jpeg_images by selecting every 'frame_interval' frame
|
| 46 |
+
sampled_images = [jpeg_images[i] for i in range(0, len(jpeg_images), frame_interval)]
|
| 47 |
+
|
| 48 |
+
return sampled_images
|
| 49 |
+
|
| 50 |
def get_video_fps(video_path):
|
| 51 |
# Open the video file
|
| 52 |
cap = cv2.VideoCapture(video_path)
|
|
|
|
| 410 |
elif vis_frame_type == "render":
|
| 411 |
# Create a video clip from the image sequence
|
| 412 |
original_fps = get_video_fps(video_in)
|
| 413 |
+
sampled_images = sparse_sampling(jpeg_images, original_fps, target_fps=6)
|
| 414 |
+
clip = ImageSequenceClip(sampled_images, fps=6)
|
| 415 |
+
# clip = ImageSequenceClip(jpeg_images, fps=fps)
|
| 416 |
# Write the result to a file
|
| 417 |
final_vid_output_path = "output_video.mp4"
|
| 418 |
|
|
|
|
| 530 |
with gr.Group():
|
| 531 |
with gr.Row():
|
| 532 |
vis_frame_type = gr.Radio(label="Propagation level", choices=["check", "render"], value="check", scale=2)
|
| 533 |
+
# Use gr.Column to center the button vertically
|
| 534 |
+
with gr.Column():
|
| 535 |
+
propagate_btn = gr.Button("Propagate", scale=2)
|
| 536 |
+
|
| 537 |
reset_prpgt_brn = gr.Button("Reset", visible=False)
|
| 538 |
output_propagated = gr.Gallery(label="Propagated Mask samples gallery", columns=4, visible=False)
|
| 539 |
output_video = gr.Video(visible=False)
|