Last active
April 4, 2016 16:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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