All posts
Convert video to GIF via CLI
ffmpeg: build a palette, then encode a looping animated GIF.
Open online converterPackages to install
Only ffmpeg is required. palettegen and paletteuse keep GIF colors closer to the source.
ffmpeg
sudo apt-get update
sudo apt-get install -y ffmpegHow to run the command
Trim with -ss start and -to end before -i. Use -vf with fps, scale, palettegen, and paletteuse. -loop 0 repeats forever; -loop -1 plays once.
ffmpeg -y -i input.mp4 -vf "fps=10,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gifDockerfile example
Build a minimal Ubuntu image with the required packages and run the conversion inside the container.
FROM ubuntu:24.04
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ffmpeg && \
rm -rf /var/lib/apt/lists/*
WORKDIR /work
docker build -t video-to-gif .
docker run --rm -v "$PWD:/work" -w /work video-to-gif \
ffmpeg -y -i input.mp4 -vf "fps=10,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gifExample commands
Run these locally after installing the packages, or inside the container from the Dockerfile.
ffmpeg -y -i input.mp4 -vf "fps=10,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gifffmpeg -y -ss 1.5 -to 4 -i input.mp4 -vf "fps=10,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 clip.gifffmpeg -y -i input.webm -vf "fps=15,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gifffmpeg -y -i input.avi -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop -1 output.gif