From 2a2ef320b632b6d52bf668d41edd703fdb57ba41 Mon Sep 17 00:00:00 2001 From: Zhichao Date: Wed, 28 Aug 2024 18:15:53 +0800 Subject: [PATCH] also save video --- vision_agent/tools/tools.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vision_agent/tools/tools.py b/vision_agent/tools/tools.py index 07f6a1aa..403d2271 100644 --- a/vision_agent/tools/tools.py +++ b/vision_agent/tools/tools.py @@ -1222,6 +1222,13 @@ def extract_frames( video_file_path = video.download(output_path=temp_dir) return extract_frames_from_video(video_file_path, fps) + elif str(video_uri).startswith(("http", "https")): + _, image_suffix = os.path.splitext(video_uri) + with tempfile.NamedTemporaryFile(delete=False, suffix=image_suffix) as tmp_file: + # Download the video and save it to the temporary file + with urllib.request.urlopen(str(video_uri)) as response: + tmp_file.write(response.read()) + return extract_frames_from_video(tmp_file.name, fps) return extract_frames_from_video(str(video_uri), fps)