Skip to content

Instantly share code, notes, and snippets.

@imkevinxu
Last active April 4, 2016 16:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imkevinxu/e0b51ddeb5b877ed4fae to your computer and use it in GitHub Desktop.
Save imkevinxu/e0b51ddeb5b877ed4fae to your computer and use it in GitHub Desktop.
Convert a live action video to gif from http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
# Convert a live action video to gif
# Works best for videos with high color palettes like videos from your phone
#
# @param $1 - video file name like `video.mp4`
# @param @optional $2 - width size like `720`
#
# Example: ffmpegtogif video.mp4 720
# Requirements: ffmpeg. Can be downloaded via homebrew
#
# http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
function ffmpegtogif() {
if [ -n "$1" ]
then
if [ -n "$2" ]
then
ffmpeg -v warning -i "$1" -vf "fps=24,scale=$2:-1:flags=lanczos,palettegen" -y "/tmp/palette.png"
ffmpeg -v warning -i "$1" -i "/tmp/palette.png" -lavfi "fps=24,scale=$2:-1:flags=lanczos [x]; [x][1:v] paletteuse" -y video.gif
else
echo "Use width as second parameter"
fi
else
echo "Use video file as first parameter"
fi
}
@imkevinxu
Copy link
Author

Source this in you .bash_profile for an easy shortcut to turn any live action video into a high-quality gif!

If you want to convert an animated video try out https://gist.github.com/imkevinxu/96e3cb1d7e308f867a0f

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