Skip to content

Instantly share code, notes, and snippets.

@stephenlb
Last active October 31, 2020 22:57
  • Star 17 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stephenlb/decba54c329529c3c807 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

inputfile=$1
outputfile=$2
fps=$3
res=$4
loop=""
[ -z "$5" ] || loop="-loop $5"
txt=$6
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 $loop $2
else
    ffmpeg -v warning -i $1 -i $palette -lavfi "$drawtext,$filters [x]; [x][1:v] paletteuse" -y $loop $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.

#!/bin/sh
## echo "USAGE"
## echo
## echo "./easy source.mp4 dest.gif FPS RESOLUTION"
## echo "./easy video.mp4 animated.gif 30 480"
## echo
inputfile=$1
outputfile=$2
fps=$3
res=$4
loop=""
[ -z "$5" ] || loop="-loop $5"
txt=$6
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 $loop $2
else
ffmpeg -v warning -i $1 -i $palette -lavfi "$drawtext,$filters [x]; [x][1:v] paletteuse" -y $loop $2
fi
@stephenlb
Copy link
Author

qwc8i1j

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