

The lanczos scaling algorithm is used in this example. scale filter will resize the output to 320 pixels wide and automatically determine the height while preserving the aspect ratio.A rate of 10 frames per second is used in the example. This example will skip the first 30 seconds ( -ss 30) of the input and create a 3 second output ( -t 3).Note that the output from the -layers Optimize may not always provide a smaller file size, so you may want to try converting to a gif without optimization first to be sure.įfmpeg -ss 30 -t 3 -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos,split palettegen paletteuse" -loop 0 output.gif The gif:- tells convert to pipe its output as gif formatted data and -layers Optimize tells the second convert to perform optimize-frame and optimize-transparancy methods (see the ImageMagick Introduction to Animation Optimization). To optimize the result without saving a file, you can pipe the output from convert to a second convert command: ffmpeg -i input.flv -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 10 -loop 0 - gif:- | convert -layers Optimize - output.gif


The - for both commands specifies that a pipe will be used for output and input respectively. The -f image2pipe tells ffmpeg to split the video into images and make it suitable to be piped out, and -vcodec ppm specifies the output format to be ppm (for some reason if the format is png, either convert does not read all the images from the pipe, or ffmpeg does not output them all). If you would prefer to avoid intermediate image files, the commands provided by LordNeckBeard can be piped between ffmpeg and ImageMagick’s convert so that no intermediate files are required: ffmpeg -i input.flv -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 10 -loop 0 - output.gif
