Skip to content

Instantly share code, notes, and snippets.

@Om4ar
Forked from kfei/gist:5dbb32f118f373fc1a47
Last active April 25, 2020 03:26
Show Gist options
  • Save Om4ar/4f0aa9207779839f0a8dda899ee97081 to your computer and use it in GitHub Desktop.
Save Om4ar/4f0aa9207779839f0a8dda899ee97081 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