Skip to content

Instantly share code, notes, and snippets.

@tomnomnom
Last active December 4, 2022 09:59
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tomnomnom/79b0b6ac2ef7035d867dc2f19e30549d to your computer and use it in GitHub Desktop.
Save tomnomnom/79b0b6ac2ef7035d867dc2f19e30549d to your computer and use it in GitHub Desktop.
Crop an mp4 and convert it to a gif

Because I'll forget how to do this...

Crop

crop=w:h:x:y

ffmpeg -i in.mp4 -filter:v "crop=900:700:0:50" out.mp4

Generate Palette

ffmpeg -y -i out.mp4 -vf fps=5,scale=600:-1:flags=lanczos,palettegen palette.png

Convert to gif

ffmpeg -i out.mp4 -i palette.png -filter_complex "fps=5,scale=600:-1:flags=lanczos[x];[x][1:v]paletteuse" out.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment