A quick reference guide for converting video files to high-quality animated GIFs using terminal CLI utilities.
Modern FFmpeg Approach (Recommended)
Generate optimized animated GIFs with palette generation in a single command pipeline:
ffmpeg -ss 00:00:02 -to 00:00:08 -i input.mp4 \
-vf "fps=15,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
-loop 0 output.gif
Classic ImageMagick & Gifsicle Pipeline
Converting MP4 to GIF via mplayer & gifsicle
mkdir -p gif
mplayer -ao null -vo gif89a:outdir=gif "$INPUT"
mogrify -format gif *.png
gifsicle --colors=256 --delay=4 --loopcount=0 --dither -O3 gif/*.gif > "${INPUT%.*}.gif"
rm -rf gif
Requires mplayer, imagemagick, and gifsicle. Extracts individual video frames and merges them into an optimized GIF.
Trimming Time Ranges
Extract only a specific section of the video using timestamps:
mplayer -ao null -ss 0:02:06 -endpos 0:00:15 -vo gif89a:outdir=gif videofile.mp4
-ss [time]: Start seek timestamp.-endpos [duration]: Duration of the segment to process.
Gifsicle Optimization
Lossy compression and color reduction to drastically shrink GIF file sizes:
# Reduce colors and optimize compression
gifsicle -O3 --colors 128 input.gif -o output.gif
# Lossy compression (great size reduction)
gifsicle -O3 --lossy=80 input.gif -o output.gif