Skip to content

Instantly share code, notes, and snippets.

@derekbrameyer
Created May 7, 2014 18:45
Show Gist options
  • Save derekbrameyer/ac0a8c5478ec099f9ee2 to your computer and use it in GitHub Desktop.
Save derekbrameyer/ac0a8c5478ec099f9ee2 to your computer and use it in GitHub Desktop.
Creating a GIF from an MP4

Crop the video:

ffmpeg -i inputfile.mp4 -aspect 1:1 -r 18.84 -vf "crop=440:440:320:750" outputfile.mp4

Arguments:

  • -aspect (aspect ratio, required or error)
  • -r (framerate, required or error)
  • "crop=440:440:320:750" corresponds to width:height:topleftx:toplefty

Shorten the video:

ffmpeg -ss 0:00:00 -i inputfile.mp4 -t 0:0:10 outputfile.mp4

Arguments:

  • -ss start time (h : m : s)
  • -t length (h : m : s)

Export the video to individual frames:

ffmpeg -i inputfile.mp4 -f image2 %03d.gif

Convert the frames to a gif:

gifsicle --delay=6 --loop *.gif > animation.gif

Notes:

  • --delay=6 had to be fudged a little to look right

Optimize the gif:

convert -layers Optimize animation.gif animation_optimized.gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment