160

I'm trying to convert a .mov to a .gif and I'm not having success.

Here's the error:

ffmpeg -pix_fmt rgb24 -i yesbuddy.mov output.gif
ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
  built on Jun 12 2012 17:47:34 with clang 2.1 (tags/Apple/clang-163.7.1)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/0.11.1 --enable-shared --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-libfreetype --cc=/usr/bin/clang --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libass --enable-libvo-aacenc --disable-ffplay
  libavutil      51. 54.100 / 51. 54.100
  libavcodec     54. 23.100 / 54. 23.100
  libavformat    54.  6.100 / 54.  6.100
  libavdevice    54.  0.100 / 54.  0.100
  libavfilter     2. 77.100 /  2. 77.100
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
Option pixel_format not found.

If I leave out the -pix_fmt rgb24 part it complains. Thoughts on how to fix?

1
  • 6
    FYI, There is an excellent solution for high quality conversions given here. Mar 28, 2014 at 13:37

5 Answers 5

229

The order of command line arguments matters. This command line should work but will generate a giant file:

ffmpeg -i yesbuddy.mov -pix_fmt rgb24 output.gif

Note that you probably want to reduce the frame rate and size when you convert, as well as specify a start time and duration. You probably do not want to convert the entire file at its original resolution and frame rate.

ffmpeg -ss 00:00:00.000 -i yesbuddy.mov -pix_fmt rgb24 -r 10 -s 320x240 -t 00:00:10.000 output.gif

The file size will still be huge. You may be able to use ImageMagick's GIF optimizer to reduce the size:

convert -layers Optimize output.gif output_optimized.gif
6
  • 3
    Awesome answer, thanks :) GIF is a crazy format... the original .mov was 250k, the converted .gif from ffmpeg was 8mb, and the convert-optimized version was an astounding 10k! Impressive! Jan 22, 2013 at 1:37
  • 24
    ffmpeg complains about the pixel format, and switches from rgb24 to pal8; should the command in the answer be updated? Mar 17, 2014 at 20:39
  • 10
    Incompatible pixel format 'rgb24' for codec 'gif'
    – pronebird
    Jul 18, 2014 at 10:15
  • 3
    @Andy auto-fixed to rgb8 in my version of ffmpeg.
    – james-see
    Sep 6, 2017 at 22:46
  • 1
    My macbook is high cpu usage when run convert -layers Optimize output.gif output_optimized.gif
    – Moon soon
    Sep 5, 2019 at 15:09
26

After converting:

ffmpeg -i input.mp4 input.gif 

Try optimize frames:

convert input.gif -verbose -coalesce -layers OptimizeFrame input_optframe.gif

And use gifsicle to make final optimization:

gifsicle -O2 input_optframe.gif -o optimized.gif

Got 6.8mb GIF from 12.2mb video with almost the same quality!

2
17
ffmpeg -i <input source> -filter_complex "[0:v] fps=12,scale=<width>:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" <output file>

In this command there are 3 tokens you need to plug in. The <input source> will be something like your-recording.mov, the <width> should be the width you want the final gif to be, and <output file> will be something like recording.gif.

This command breaks down to mean:

  • filter_complex we're going to be chaining some filters together
  • [0:v] fps=12 take the first video stream in the container at 12 frames per second
  • scale=1024:-1 resize to width of 1024 and keep aspect ratio for the height
  • split [a][b] take the current stream and split it into two (basically clone it)
  • ; new filter incoming
  • [a] palettegen [p] take the "a" stream and generate a color palette called "p"
  • ; new filter incoming
  • [b][p] paletteuse take the "b" stream and apply "p" color palette

The color palette stuff isn't always necessary for screen recordings, but is definitely required to have better colors for recorded video.

You can also plug in -ss 00:00:00.000 and -t 00:00:00.000 as needed if you are going to be clipping it as well.

1
  • 1
    This is awesome. Thank you :). Dec 13, 2022 at 13:46
11

I made a tool that bundles FFmpeg, ImageMagick and giflossy into a single easy to use command line program that you can install in one line: Abandonware: gifify

I recommend anyone willing to turn videos => GIF to use it instead of trying to spend a lot of time browsing 3 documentation websites to understand how to resize the GIF or change the start/end time.

3
  • 2
    And if you have Docker running on your machine, just do an alias like so: alias gifify='docker run -it --rm -v $(pwd):/data maxogden/gifify' then use it gifify screencast.mkv -o screencast.gif --resize 800:-1
    – sabbour
    May 28, 2018 at 6:38
  • 1
    "I am no more using this project or providing any support to it, if you want to maintain it, ping me" Dec 1, 2019 at 14:29
  • Still works great—just ran docker run -it --rm -v $(pwd):/data maxogden/gifify my.mov -o my.gif --speed 1.5 --resize 1000:-1 --colors 255 --fps 6 Nov 2, 2020 at 20:47
7
ffmpeg -y -i input.mp4 -f image2pipe -vcodec ppm - | convert -delay 2 -loop 0 -layers Optimize - gif:- | gifsicle -d 3 -O3 -o optimized.gif

first use ffmpeg to convert mp4 file to images via pipe then use imagemagick to compress it to gif at last optimized it with gifsicle

I don't know why using gifscicle directly won't work.

or you can make the gif smaller by this

convert -dither none -matte -depth 8 -deconstruct -layers optimizePlus -colors 32 in.gif out.gif
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .