User Tools

Site Tools


tech:make_gif

Make a gif Using FFMPEG

ffmpeg can output high quality GIF

Command and Meanings

 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 
  • 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.

Make a gif with text Using FFMPEG

 ffmpeg -i clip.mp4 \
  -vf "fps=15,scale=480:-1:flags=lanczos,\
drawtext=fontfile=/Library/Fonts/Arial.ttf:\
textfile=subtitles1.txt:reload=1:\
enable='lt(t,1)':\
fontcolor=white@0.8:fontsize=24:\
box=1:boxcolor=black@0.5:\
x=(w-text_w)/2:y=h-(text_h*2),\
drawtext=fontfile=/Library/Fonts/Arial.ttf:\
textfile=subtitles2.txt:reload=1:\
enable='between(t,1,3)':\
fontcolor=white@0.8:fontsize=24:\
box=1:boxcolor=black@0.5:\
x=(w-text_w)/2:y=h-(text_h*2),\
drawtext=fontfile=/Library/Fonts/Arial.ttf:\
textfile=subtitle3.txt:reload=1:\
enable='gte(t,3)':\
fontcolor=white@0.8:fontsize=24:\
box=1:boxcolor=black@0.5:\
x=(w-text_w)/2:y=h-(text_h*2)" \
  -loop 0 output.gif
 
  • Create .txt files for the subtitles you want to use. (In this case, subtitles1.txt + subtitles2.txt + subtitles3.txt
  • Note the commands for time after “enable=” (it seems to use “between” at one point)
tech/make_gif.txt · Last modified: by katsimbris