This method extracts intermediate frames from the video that will be used to create the gif. The output folder where the frames will be saved should already exist.
ffmpeg -i <input.mp4> -r 10 <path-to-output-folder>/frame-%03d.png
convert -delay -10 loop 0 -layers Optimize <path-to-output-folder>/*.png <output.gif>
This method option forgoes the intermediate frames by piping the outputs of the ffmpeg extraction directly to the convert command.
ffmpeg -i <input.mp4> -r 10 -f image2pipe -vcodec ppm - | convert -delay 10 -loop 0 -layers Optimize - <output.gif>
You can check the help or man pages of ffmpeg and convert for more details about the available options but here are a few that I’ve found to be the most useful.
Add -ss 10 and -t 5 to the ffmpeg command.
Using method 2:
ffmpeg -ss 0 -t 25 -i <input.mp4> -r 10 -f image2pipe -vcodec ppm - | convert -delay 10 -loop 0 -layers Optimize - <output.gif>
Add -vf scale=n:-1:flags=lanczos to the ffmpeg command where n is the width you want for the output gif.
Using method 2 and assuming I want a gif with a width of 1080 pixels:
ffmpeg -i <input.mp4> -vf scale=1080:-1:flags=lanczos -r 10 -f image2pipe -vcodec ppm - | convert -delay 10 -loop 0 -layers Optimize - <output.gif>
foss linux sager np8966 clevo p960d laptop xps system76 pop! os
If you find my website or any of the materials I share useful, you can consider donating to the cause below.
Except when explicitly stated otherwise, this work and its contents by Ben Hur S. Pintor is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Other works (software, source code, etc.) referenced in this website are under their own respective licenses.
This site is powered by Jekyll and hosted on Github (view source)