Skip to content

Commit

Permalink
recover to use moviepy to save video
Browse files Browse the repository at this point in the history
  • Loading branch information
yzld2002 committed Aug 5, 2024
1 parent fbb7b45 commit 9757ed2
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions vision_agent/tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import cv2
import numpy as np
import requests
from moviepy.editor import ImageSequenceClip
from PIL import Image, ImageDraw, ImageFont
from pillow_heif import register_heif_opener # type: ignore
from pytube import YouTube # type: ignore
Expand Down Expand Up @@ -1063,20 +1064,15 @@ def save_video(
_LOGGER.warning(f"Invalid fps value: {fps}. Setting fps to 4 (default value).")
fps = 4

if not output_video_path:
output_video_path = tempfile.NamedTemporaryFile(
suffix=".mp4", delete=False
).name

height, width, layers = frames[0].shape if frames else (0, 0, 0)
fourcc = cv2.VideoWriter_fourcc(*"X264") # type: ignore
video = cv2.VideoWriter(output_video_path, fourcc, fps, (width, height))
for frame in frames:
video.write(cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))
video.release()

_save_video_to_result(output_video_path)
return output_video_path
with ImageSequenceClip(frames, fps=fps) as video:
if output_video_path:
f = open(output_video_path, "wb")
else:
f = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) # type: ignore
video.write_videofile(f.name, codec="libx264")
f.close()
_save_video_to_result(f.name)
return f.name


def _save_video_to_result(video_uri: str) -> None:
Expand Down

0 comments on commit 9757ed2

Please sign in to comment.