How to do I convert an webm (video) to a (animated) gif on the command line?
33,323
Solution 1
From here:
ffmpeg -i input.webm -pix_fmt rgb24 output.gif
Solution 2
Barafu's answer is alright. But, the resulting gif may have color conversion issue as ffmpeg complains on Incompatible pixel format 'rgb24' for codec 'gif'
. Here is what I find works:
First, create PNG Palette:
ffmpeg -y -i input.webm -vf palettegen palette.png
Then, use the palette to produce gif:
ffmpeg -y -i input.webm -i palette.png -filter_complex paletteuse -r 10 output.gif
Source:
Covert MP4/Webm - ubuntubuzz.com
Solution 3
Extending Raynal's answer, here's a script one can add to .bashrc
to do the conversion:
function webm2gif() {
ffmpeg -y -i "$1" -vf palettegen _tmp_palette.png
ffmpeg -y -i "$1" -i _tmp_palette.png -filter_complex paletteuse -r 10 "${1%.webm}.gif"
rm _tmp_palette.png
}
e.g.
webm2gif recording.webm
will create recording.gif
.
Related videos on Youtube
Author by
brubaker
Updated on September 18, 2022Comments
-
brubaker almost 2 years
I suppose ffmpeg is the weapon of choice but I didn't find out how to reach my goal.
-
llogan almost 10 yearsSee How do I convert a video to GIF using ffmpeg, with reasonable quality? for some additional information.
-
-
brubaker almost 10 yearsI am already testing your solution. Just a moment.
-
brubaker almost 10 yearsWow! It works! AND.. 2.6 MB webm -> 48 MB gif ^^ -- any thought to reduce this?
-
brubaker almost 10 yearsI suggest to change your command in your answer to: "ffmpeg -i input.webm -pix_fmt rgb24 output.gif".
-
kenn almost 10 yearsgifsicle is a fantastic tool to reduce gif size
gifsicle -O2 input.gif -o output.gif
-
Barafu Albino almost 10 yearsTry
-pix_fmt rgb16
-
brubaker almost 10 yearsThanks @kenn but it only reduces the file size in this particular example down to 46 MB. I think it is maybe better trying to reduce ffmpeg output in the first place.
-
brubaker almost 10 years@BarafuAlbino Thanks buddy, but I got an error: "Unknown pixel format requested: rgb16."
-
wchargin over 8 years@brubaker I think I got you beat: 120K
.webm
→ 2.7G.gif
. Yes, that's with a G. -
Kane Blueriver over 7 years
rgb24
is not supported for gif, ffmpeg would usergb8
instead automatically. -
Sudhir Singh Khanger over 6 years@BarafuAlbino will this only work for webm or will it also work for other containers like mp4, mkv, ogg, etc.
-
Barafu Albino over 6 yearsShould work for anything ffmpeg can understand. And you should omit -pix_fmt these days.
-
rodrigob over 6 yearsworks with avconv too (same command line options). gifsicle is awesome indeed !
-
Dan Dascalescu over 5 yearsTo crop the video, pass the starting second via
-ss
and the length via the-t
option:ffmpeg input.web -ss 1 -t 10 output.gif
. -
Dan Dascalescu over 5 yearsPassing
-pix_fmt rgb16
produced "Unknown pixel format requested", and passing rgb24 warned "Incompatible pixel format 'rgb24' for codec 'gif', auto-selecting format 'rgb8'". If you don't mind, I'll edit your answer to remove the-pix_fmt
option. -
Eugene almost 5 yearsproduced a much better result in my case than the accepted answer
-
Lok about 3 yearsConfirmed that this also works on Windows 10😂