Skip to content

Instantly share code, notes, and snippets.

@kfei
Last active April 25, 2020 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kfei/5dbb32f118f373fc1a47 to your computer and use it in GitHub Desktop.
Save kfei/5dbb32f118f373fc1a47 to your computer and use it in GitHub Desktop.
Convert GIF using ffmpeg and ImageMagick
# Use ffmpeg to decode input video (GIF in this case)
ffmpeg -i input.gif decode/%d.png
# Use ImageMagick to crop, format: (W)x(H)+(W_SFHIT)+(H_SHIFT)
# Note the {from..to..skip} usage of Bash
convert decoded/{1..759..5}.png -crop 315x172+20+40 resized/%d.png
# An resize option
# convert decoded/{1..759..5}.png -crop 315x172+20+40 -resize 30% resized/%d.png
# (Optional) Tune brightness/saturation/contrase
# convert decode/{1..759..5}.png -modulate 200,150 -contrast-stretch 1% converted/%d.png
# Generate GIF. delay=10 if for browser, loop=0 means infinite.
convert -delay 10 -loop 0 resized/{1..151..3}.png output.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment