Skip to main content
Split the nicely documented commands over several lines so the viewer doesn't need to scroll
Source Link
ffmpeg -ss 30 -t 3 -i input.mp4 \
    -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
    -loop 0 output.gif
 ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" -c:v pam \
    -f image2pipe - | \
    convert -delay 10 - -loop 0 -layers optimize output.gif
ffmpeg -ss 30 -t 3 -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif
 ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" -c:v pam -f image2pipe - | convert -delay 10 - -loop 0 -layers optimize output.gif
ffmpeg -ss 30 -t 3 -i input.mp4 \
    -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
    -loop 0 output.gif
ffmpeg -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos" -c:v pam \
    -f image2pipe - | \
    convert -delay 10 - -loop 0 -layers optimize output.gif
beyer/bayer typo
Source Link
llogan
  • 60.6k
  • 17
  • 130
  • 152

ffmpeg can output high quality GIF. It'sBefore you start it is always recommended to use a recent version: download or compile.

  • stats_mode (palettegen). You can force the filters to focus the palette on the general picture (full which is the default), only the moving parts (diff), or each individual frame (single). For example, to generate a palette for each individual frame use palettegen=stats_mode=single & paletteuse=new=1.

  • dither (paletteuse). Choose the dithering algorithm. There are three main types: deterministic (beyerbayer), error diffusion (all the others including the default sierra2_4a), and none. Your GIF may look better using a particular dithering algorithm, or no dithering at all. If you want to try beyerbayer be sure to test the beyer_scalebayer_scale option too.

ffmpeg can output high quality GIF. It's always recommended to use a recent version: download or compile.

  • stats_mode (palettegen). You can force the filters to focus the palette on the general picture (full which is the default), only the moving parts (diff), or each individual frame (single). For example, to generate a palette for each individual frame use palettegen=stats_mode=single & paletteuse=new=1.

  • dither (paletteuse). Choose the dithering algorithm. There are three main types: deterministic (beyer), error diffusion (all the others including the default sierra2_4a), and none. Your GIF may look better using a particular dithering algorithm, or no dithering at all. If you want to try beyer be sure to test the beyer_scale option too.

ffmpeg can output high quality GIF. Before you start it is always recommended to use a recent version: download or compile.

  • stats_mode (palettegen). You can force the filters to focus the palette on the general picture (full which is the default), only the moving parts (diff), or each individual frame (single). For example, to generate a palette for each individual frame use palettegen=stats_mode=single & paletteuse=new=1.

  • dither (paletteuse). Choose the dithering algorithm. There are three main types: deterministic (bayer), error diffusion (all the others including the default sierra2_4a), and none. Your GIF may look better using a particular dithering algorithm, or no dithering at all. If you want to try bayer be sure to test the bayer_scale option too.

mentioned stats_mode and dither options. added conver options. other minor changes.
Source Link
llogan
  • 60.6k
  • 17
  • 130
  • 152
  • This example will skip the first 30 seconds (-ss 30) of the input and create a 3 second output (-t 3).
  • fps filter sets the frame rate. A rate of 10 frames per second is used in the example.
  • scale filter will resize the output to 320 pixels wide and automatically determine the height while preserving the aspect ratio. The lanczos scaling algorithm is used in this example.
  • palettegenpalettegen and paletteusepaletteuse filters will generate and use a custom palette generated from your input. These filters have many options, so refer to the links for a list of all available options and values. Also see the Advanced options section below.
  • split filter will allow everything to be done in one command and avoids having to create a temporary PNG file of the palette.
  • Control looping with -loop output option but the values are confusing. A value of 0 is infinite looping, -1 is no looping, and 1 will loop once meaning it will play twice. So a value of 10 will cause the GIF to play 11 times.

Advanced options

The palettegen and paletteuse filters have many additional options. The most important are:

  • stats_mode (palettegen). You can force the filters to focus the palette on the general picture (full which is the default), only the moving parts (diff), or each individual frame (single). For example, to generate a palette for each individual frame use palettegen=stats_mode=single & paletteuse=new=1.

  • dither (paletteuse). Choose the dithering algorithm. There are three main types: deterministic (beyer), error diffusion (all the others including the default sierra2_4a), and none. Your GIF may look better using a particular dithering algorithm, or no dithering at all. If you want to try beyer be sure to test the beyer_scale option too.

See High quality GIF with FFmpeg for manyexplanations, example images, and more examplesdetailed info for advanced usage.

Also see the palettegen and paletteuse documentation for all available options and values.

ImagemagickImageMagick convert example

ffmpeg options:

  • -vf "fps=10,scale=320:-1:flags=lanczos" a filtergraph using the fps and scale filters. fps sets frame rate to 10, and scale sets the size to 320 pixels wide and height is automatically determined and uses a value that preserves the aspect ratio. The lanczos scaling algorithm is used in this example.

  • -c:v pam Chooses the pam image encoder. The example outputs the PAM (Portable AnyMap) image format which is a simple, lossless RGB format that supports transparency (alpha) and is supported by convert. It is faster to encode than PNG.

  • -f image2pipe chooses the image2pipe muxer because when outputting to a pipe ffmpeg needs to be told which muxer to use.

convert options:

  • -delay See Setting frame rate section below.

  • -loop 0 makes infinite loop.

  • -layers optimize Will enable the general purpose GIF optimizer. See ImageMagick Animation Optimization for more details. It is not guaranteed that it will produce a smaller output, so it is worth trying without -layers optimize and comparing results.

  • This example will skip the first 30 seconds (-ss 30) of the input and create a 3 second output (-t 3).
  • fps filter sets the frame rate. A rate of 10 frames per second is used in the example.
  • scale filter will resize the output to 320 pixels wide and automatically determine the height while preserving the aspect ratio. The lanczos scaling algorithm is used in this example.
  • palettegen and paletteuse filters will generate and use a custom palette generated from your input.
  • split filter will allow everything to be done in one command and avoids having to create a temporary PNG file of the palette.
  • Control looping with -loop output option. A value of 0 is infinite looping.

See High quality GIF with FFmpeg for many more examples and options.

Imagemagick convert example

  • -vf "fps=10,scale=320:-1:flags=lanczos" a filtergraph using the fps and scale filters. fps sets frame rate to 10, and scale sets the size to 320 pixels wide and height is automatically determined and uses a value that preserves the aspect ratio. The lanczos scaling algorithm is used in this example.

  • -c:v pam Chooses the pam image encoder. The example outputs the PAM (Portable AnyMap) image format which is a simple, lossless RGB format that supports transparency (alpha) and is supported by convert. It is faster to encode than PNG.

  • -f image2pipe chooses the image2pipe muxer because when outputting to a pipe ffmpeg needs to be told which muxer to use.

  • This example will skip the first 30 seconds (-ss 30) of the input and create a 3 second output (-t 3).
  • fps filter sets the frame rate. A rate of 10 frames per second is used in the example.
  • scale filter will resize the output to 320 pixels wide and automatically determine the height while preserving the aspect ratio. The lanczos scaling algorithm is used in this example.
  • palettegen and paletteuse filters will generate and use a custom palette generated from your input. These filters have many options, so refer to the links for a list of all available options and values. Also see the Advanced options section below.
  • split filter will allow everything to be done in one command and avoids having to create a temporary PNG file of the palette.
  • Control looping with -loop output option but the values are confusing. A value of 0 is infinite looping, -1 is no looping, and 1 will loop once meaning it will play twice. So a value of 10 will cause the GIF to play 11 times.

Advanced options

The palettegen and paletteuse filters have many additional options. The most important are:

  • stats_mode (palettegen). You can force the filters to focus the palette on the general picture (full which is the default), only the moving parts (diff), or each individual frame (single). For example, to generate a palette for each individual frame use palettegen=stats_mode=single & paletteuse=new=1.

  • dither (paletteuse). Choose the dithering algorithm. There are three main types: deterministic (beyer), error diffusion (all the others including the default sierra2_4a), and none. Your GIF may look better using a particular dithering algorithm, or no dithering at all. If you want to try beyer be sure to test the beyer_scale option too.

See High quality GIF with FFmpeg for explanations, example images, and more detailed info for advanced usage.

Also see the palettegen and paletteuse documentation for all available options and values.

ImageMagick convert example

ffmpeg options:

  • -vf "fps=10,scale=320:-1:flags=lanczos" a filtergraph using the fps and scale filters. fps sets frame rate to 10, and scale sets the size to 320 pixels wide and height is automatically determined and uses a value that preserves the aspect ratio. The lanczos scaling algorithm is used in this example.

  • -c:v pam Chooses the pam image encoder. The example outputs the PAM (Portable AnyMap) image format which is a simple, lossless RGB format that supports transparency (alpha) and is supported by convert. It is faster to encode than PNG.

  • -f image2pipe chooses the image2pipe muxer because when outputting to a pipe ffmpeg needs to be told which muxer to use.

convert options:

  • -delay See Setting frame rate section below.

  • -loop 0 makes infinite loop.

  • -layers optimize Will enable the general purpose GIF optimizer. See ImageMagick Animation Optimization for more details. It is not guaranteed that it will produce a smaller output, so it is worth trying without -layers optimize and comparing results.

added 191 characters in body
Source Link
llogan
  • 60.6k
  • 17
  • 130
  • 152
Loading
added more info as requested
Source Link
llogan
  • 60.6k
  • 17
  • 130
  • 152
Loading
updated old answer. switched to public domain video.
Source Link
llogan
  • 60.6k
  • 17
  • 130
  • 152
Loading
deverbosify edit
Source Link
llogan
  • 60.6k
  • 17
  • 130
  • 152
Loading
mention new GIF encoding features
Source Link
llogan
  • 60.6k
  • 17
  • 130
  • 152
Loading
update for newer ffmpeg versions (better default quality, yay)
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603
Loading
note about `format=rgb8,format=rgb24`
Source Link
llogan
  • 60.6k
  • 17
  • 130
  • 152
Loading
Post Migrated Here from stackoverflow.com (revisions)
Source Link
llogan
  • 60.6k
  • 17
  • 130
  • 152
Loading