From bc254157c726e3731321bcec92299b924540dbd9 Mon Sep 17 00:00:00 2001 From: ChengZi Date: Mon, 31 Jul 2023 11:10:42 +0800 Subject: [PATCH] fix towhee.glob issue Signed-off-by: ChengZi --- .../video_deduplication_at_segment_level.ipynb | 14 ++++++++------ .../video_deduplication_at_video_level.ipynb | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/video/video_copy_detection/segment_level/video_deduplication_at_segment_level.ipynb b/video/video_copy_detection/segment_level/video_deduplication_at_segment_level.ipynb index 708a2ef..06fa3e7 100644 --- a/video/video_copy_detection/segment_level/video_deduplication_at_segment_level.ipynb +++ b/video/video_copy_detection/segment_level/video_deduplication_at_segment_level.ipynb @@ -141,6 +141,7 @@ "from IPython import display\n", "from pathlib import Path\n", "import towhee\n", + "from towhee import pipe, ops\n", "from PIL import Image as PILImage\n", "import os\n", "\n", @@ -152,12 +153,13 @@ " return display.HTML(html)\n", "\n", "def convert_video2gif(video_path, output_gif_path, start_time=0.0, end_time=1000.0, num_samples=16):\n", - " frames = (\n", - " towhee.glob(video_path)\n", - " .video_decode.ffmpeg(start_time=start_time, end_time=end_time, sample_type='time_step_sample', args={'time_step': 3})\n", - " .to_list()[0]\n", + " p = (\n", + " pipe.input('video_file')\n", + " .flat_map('video_file', 'frame', ops.video_decode.ffmpeg(start_time=start_time, end_time=end_time, sample_type='time_step_sample', args={'time_step': 3}))\n", + " .output('frame')\n", " )\n", - " imgs = [PILImage.fromarray(frame) for frame in frames]\n", + " frames = p(video_path).to_list()\n", + " imgs = [PILImage.fromarray(frame[0]) for frame in frames]\n", " imgs = [img.resize((int(img.width/6), int(img.height/6)), PILImage.NEAREST) for img in imgs]\n", " imgs[0].save(fp=output_gif_path, format='GIF', append_images=imgs[1:], save_all=True, loop=0)\n", "\n", @@ -695,4 +697,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file diff --git a/video/video_copy_detection/video_level/video_deduplication_at_video_level.ipynb b/video/video_copy_detection/video_level/video_deduplication_at_video_level.ipynb index 8e485e2..5fb8731 100644 --- a/video/video_copy_detection/video_level/video_deduplication_at_video_level.ipynb +++ b/video/video_copy_detection/video_level/video_deduplication_at_video_level.ipynb @@ -313,6 +313,7 @@ "from IPython import display\n", "from pathlib import Path\n", "import towhee\n", + "from towhee import pipe, ops\n", "from PIL import Image\n", "\n", "def display_gif(video_path_list, text_list):\n", @@ -324,12 +325,13 @@ "\n", " \n", "def convert_video2gif(video_path, output_gif_path, num_samples=16):\n", - " frames = (\n", - " towhee.glob(video_path)\n", - " .video_decode.ffmpeg(start_time=0.0, end_time=1000.0, sample_type='time_step_sample', args={'time_step': 5})\n", - " .to_list()[0]\n", + " p = (\n", + " pipe.input('video_file')\n", + " .flat_map('video_file', 'frame', ops.video_decode.ffmpeg(start_time=0.0, end_time=1000.0, sample_type='time_step_sample', args={'time_step': 5}))\n", + " .output('frame')\n", " )\n", - " imgs = [Image.fromarray(frame) for frame in frames]\n", + " frames = p(video_path).to_list()\n", + " imgs = [Image.fromarray(frame[0]) for frame in frames]\n", " imgs[0].save(fp=output_gif_path, format='GIF', append_images=imgs[1:], save_all=True, loop=0)\n", "\n", "\n", @@ -839,4 +841,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file