Skip to content

Instantly share code, notes, and snippets.

@greymeister
Created July 23, 2014 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greymeister/687a6ffd9f26777b88a7 to your computer and use it in GitHub Desktop.
Save greymeister/687a6ffd9f26777b88a7 to your computer and use it in GitHub Desktop.
gif_to_mpeg - convert gif to mpeg video file using imagemagick and ffmpeg
#!/bin/bash
## gif_to_mpeg
## Based on http://stackoverflow.com/a/3212958 and http://apple.stackexchange.com/a/103834
## charles.erwin@vendscreen.com
## Take first argument which should be a filename
if [ -z "$1" ]
then
echo "Usage: $0 'filename.gif'"
exit 1
else
filename=$1
fi
## Use imagemagick to convert to individual frames
timestamp="$(date +%s)"
echo "Starting $filename gif --> mpeg processing at $(date)"
convert -coalesce "$filename" "/tmp/${timestamp}temp%05d.png"
## Use ffmpeg to convert frames into video
ffmpeg -f image2 -i "/tmp/${timestamp}temp%05d.png" "${filename}_video.mpg" -y
## Cleanup
rm /tmp/"${timestamp}temp"*.png
echo "DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment