Skip to content

Instantly share code, notes, and snippets.

@mikew
Last active January 24, 2020 20:57
Show Gist options
  • Save mikew/d2e146a8c5ad5a3db5c2b95a38830594 to your computer and use it in GitHub Desktop.
Save mikew/d2e146a8c5ad5a3db5c2b95a38830594 to your computer and use it in GitHub Desktop.
#!/bin/sh
# http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
_convert() {
palette="$(mktemp).png"
fps="15"
width="800"
# width="300"
dither="dither=bayer:bayer_scale=3"
filters="fps=$fps,scale=$width:-1:flags=lanczos"
output="$1.gif"
export PATH="$HOME/Downloads:$PATH"
ffmpeg -i "$1" -vf "$filters,palettegen=stats_mode=diff" -y "$palette"
ffmpeg -i "$1" -i "$palette" -lavfi "$filters [x]; [x][1:v] paletteuse=$dither" -y "$output"
rm "$palette"
}
for f in "$@"; do
_convert "$f"
done
#!/bin/sh
export PATH="$HOME/Downloads:$PATH"
_convert() {
output="$1.mp4"
ffmpeg -i "$1" -vcodec h264 -an "$output"
}
for f in "$@"; do
_convert "$f"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment