I suppose ffmpeg is the weapon of choice but I didn't find out how to reach my goal.
Asked
Active
Viewed 4.7k times
61
-
2See How do I convert a video to GIF using ffmpeg, with reasonable quality? for some additional information. – llogan Aug 04 '14 at 16:20
3 Answers
78
From here:
ffmpeg -i input.webm -pix_fmt rgb24 output.gif

Barafu Albino
- 6,541
-
-
8Wow! It works! AND.. 2.6 MB webm -> 48 MB gif ^^ -- any thought to reduce this? – brubaker Aug 04 '14 at 11:47
-
I suggest to change your command in your answer to: "ffmpeg -i input.webm -pix_fmt rgb24 output.gif". – brubaker Aug 04 '14 at 11:50
-
8gifsicle is a fantastic tool to reduce gif size
gifsicle -O2 input.gif -o output.gif
– kenn Aug 04 '14 at 11:52 -
-
Thanks @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 Aug 04 '14 at 11:59
-
1@BarafuAlbino Thanks buddy, but I got an error: "Unknown pixel format requested: rgb16." – brubaker Aug 04 '14 at 12:01
-
3@brubaker I think I got you beat: 120K
.webm
→ 2.7G.gif
. Yes, that's with a G. – wchargin Nov 01 '15 at 23:19 -
6
rgb24
is not supported for gif, ffmpeg would usergb8
instead automatically. – Kane Blueriver Jan 22 '17 at 08:59 -
1@BarafuAlbino will this only work for webm or will it also work for other containers like mp4, mkv, ogg, etc. – Sudhir Singh Khanger Oct 10 '17 at 04:19
-
1Should work for anything ffmpeg can understand. And you should omit -pix_fmt these days. – Barafu Albino Oct 10 '17 at 06:29
-
works with avconv too (same command line options). gifsicle is awesome indeed ! – rodrigob Feb 07 '18 at 17:43
-
To 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 Nov 06 '18 at 22:19 -
Passing
-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. – Dan Dascalescu Nov 06 '18 at 22:22
50
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:

Raynal Gobel
- 657
17
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
.

SMoenig
- 103

Max Ghenis
- 271