Skip to content

Instantly share code, notes, and snippets.

@JCBuck
Forked from stephenlb/animated-gif.md
Created May 31, 2017 22:59
Show Gist options
  • Save JCBuck/ce789aed93e1c3073b67f1d2845ea06a to your computer and use it in GitHub Desktop.
Save JCBuck/ce789aed93e1c3073b67f1d2845ea06a to your computer and use it in GitHub Desktop.
DIY How to make your own HD Animated GIF Generator

HD Animated GIF Generator

You can make your own HD animated GIF generator.
Follow along with these commands to get started.

HD Animated GIF Generator

git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
./configure --disable-yasm --enable-libfreetype
sudo make install

Create the HD Animated GIF Generator

Make a new file called hd-gif and add the following text.

#!/bin/sh

## echo "USAGE"
## echo
## echo "./easy source.mp4 dest.gif FPS RESOLUTION"
## echo "./easy video.mp4 animated.gif 30 480"
## echo

fps=$3
res=$4
txt=$5
palette="/tmp/palette.png"
filters="fps=$fps,scale=$res:-1:flags=lanczos"
paletteops="stats_mode=diff"
paletteops=""
drawtext="
    drawbox=y=ih/PHI:color=black@0.4:width=iw:height=160:t=max,\
    drawtext=fontfile=/Library/Fonts/AppleMyungjo.ttf:\
    text='$txt':\
    fontcolor=white:\
    fontsize=60:\
    x=(w-tw)/2:\
    y=(h/PHI)+th"

./ffmpeg -v warning -i $1 -vf "$filters,palettegen=$paletteops" -y $palette
if [[ -z "$txt" ]]; then
    ./ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
else
    ./ffmpeg -v warning -i $1 -i $palette -lavfi "$drawtext,$filters [x]; [x][1:v] paletteuse" -y $2
fi

Make Executable: chmod +x hd-gif

Now you can use your hd-gif script like this: ./hd-gif video.mkv anim.gif 24 480

Source Blog

http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html#usage

Upload to imgur for Hosting and .webm

You will finally want to upload to http://imgur.com to provide free hosting and easy quick links. If your gif is over 7mb then Imgur will convert it to WebM format for performance.

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