Skip to content

Commit

Permalink
Merge pull request #222 from zc277584121/main
Browse files Browse the repository at this point in the history
fix towhee.glob issue
  • Loading branch information
jaelgu authored Jul 31, 2023
2 parents 2629e37 + bc25415 commit 27bda6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -695,4 +697,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -839,4 +841,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}

0 comments on commit 27bda6d

Please sign in to comment.