Skip to content

Instantly share code, notes, and snippets.

@jhallard
Created June 22, 2018 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhallard/6011379d02b6d2b936f7f3445517a962 to your computer and use it in GitHub Desktop.
Save jhallard/6011379d02b6d2b936f7f3445517a962 to your computer and use it in GitHub Desktop.
How to encode a gif from a video file using ffmpeg at a specific resolution and bitrate
gifenc ()
{
palette="/tmp/palette.png";
filters="fps=$4,scale=$3:-1:flags=lanczos";
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette;
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
}
# use like this to encode /tmp/video.mp4 to /tmp/output.gif at 240p and 12fps
# $ gifenc /tmp/video.mp4 /tmp/output.gif 240 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment