Convert video to gif

April 21, 2025 Β· Tyler Yeager

Convert video to gif
ffgif() { p="fps=10,scale=${4:-320}:-1:flags=lanczos"; ffmpeg -y -ss ${2:-0} -i "$1" -to ${3:-0} -vf ${p},palettegen -loglevel error .p.png \ && ffmpeg -ss ${2:-0} -i "$1" -i .p.png -to ${3:-0} -loglevel error -filter_complex "${p}[x];[x][1:v]paletteuse" "${1%.*}".gif \ && rm .p.png; }

Requires ffmpeg to be installed. Here is a nicer layout of the command:

Terminal window
ffgif() {
p="fps=10,scale=${4:-320}:-1:flags=lanczos";
ffmpeg -y -ss ${2:-0} -i "$1" -to ${3:-0} -vf ${p},palettegen -loglevel error .p.png \
&& ffmpeg -ss ${2:-0} -i "$1" -i .p.png -to ${3:-0} -loglevel error -filter_complex "${p}[x];[x][1:v]paletteuse" "${1%.*}".gif \
&& rm .p.png;
}

This command takes up to 4 arguments. Here’s a quick example:

Terminal window
ffgif my_video.mp4 00:00:10 00:00:20 720

In short, it takes my_video.mp4, starts the gif encoding at timestamp 00:00:10, and encodes until 00:00:20 with the scale 720. Higher scale means higher resolution.

Useful for a quick gif of a video!

Did you find this interesting?

Consider subscribing 😊

No AI-generated content or SEO garbage.

Unsubscribe anytime