Skip to content

Instantly share code, notes, and snippets.

@j3j5
Last active March 25, 2016 21:04
Show Gist options
  • Save j3j5/eb2fefc1a2f9012337d4 to your computer and use it in GitHub Desktop.
Save j3j5/eb2fefc1a2f9012337d4 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
if (( $# != 1 )); then
echo "Converts ANIMATED-GIF to a video file."
echo 1>&2
echo "Usage: gif2mp4 ANIMATED-GIF" 1>&2
exit 1
fi
INFILE="${1}"
OUTFILE="${INFILE%.gif}.mp4"
# Stick the .mp4 in the same directory as the original .gif, regardless of
# current directory
OUTFILE="$(dirname -- "${OUTFILE}")/$(basename -- "${OUTFILE}")"
# the scale bit is because x264 (yuv420p, to be exats) needs image dimensions divisible by 2
ffmpeg -i "${INFILE}" -c:v libx264 -an -movflags +faststart -vf 'scale=-2:ih' -pix_fmt yuv420p "${OUTFILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment