Skip to content

Instantly share code, notes, and snippets.

@derak-kilgo
Created August 17, 2016 18:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save derak-kilgo/96d3d3e05058ad81d8d32c539248f00a to your computer and use it in GitHub Desktop.
Save derak-kilgo/96d3d3e05058ad81d8d32c539248f00a to your computer and use it in GitHub Desktop.
Convert a mp4 clip into a gif with php, imagemagick and ffmpeg. From OSX, these are easy to install with homebrew.
<?php
$video = __DIR__ . '/video.mp4';
$fps = 4;
# Convert an MP4 to a GIF - Requires ffmpeg
`ffmpeg -i "$video" -pix_fmt rgb24 -r $fps "$video.gif"`
# optimize the gif - Requires imagemagick
# via http://superuser.com/questions/436056/how-can-i-get-ffmpeg-to-convert-a-mov-to-a-gif
`convert -layers Optimize "$video.gif" "$video.gif"`
@derak-kilgo
Copy link
Author

derak-kilgo commented Aug 17, 2016

Based on https://gist.github.com/seyhunak/a5ccc3693bb1aae1787c
Thanks for showing this is possible with ffmpeg.

@RyderMais
Copy link

Theres a way to do the reverse process (.gif to .mp4)?

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