Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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