-
Notifications
You must be signed in to change notification settings - Fork 19
Animated GIF Creation
The first step is to record a demo movie, the current video is produced by installing the demo app on device, then running through the local images demo and recording using Quicktime.
To create a better animated gif, I adapted the example FFMPEG scripts from here
The first step is to install FFMPEG, if you have homebrew installed, then run brew install ffmpeg
.
Next, copy this script:
#!/bin/sh
palette=`mktemp -d`"/palette.png"
# deletes the temp palette
function cleanup {
rm "$palette"
echo "Deleted temp palette at: $palette"
}
trap cleanup EXIT
filters="fps=5,setpts=0.8*PTS,scale=540:-1:flags=lanczos"
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
Into a movToGif.sh
, and then run chmod +x movToGif.sh
Finally run ./movToGif.sh inFile.mov outFile.gif
to convert the .mov file to a .gif
For anyone interested in what the filters in FFMPEG are doing, it's setting the output video framerate to 5 fps, speeding up the video to 1.25x to make the animation slightly snappier, scaling to the video down to 540 px wide while maintaining the aspect ratio using lanczos scaling.
During the first pass, FFMPEG is generate an optimized color palette to use when encoding, then the second pass is rendering the video to an animated gif using that palette.