Skip to content

Instantly share code, notes, and snippets.

@lighterowl
Created June 16, 2020 20:48
Show Gist options
  • Save lighterowl/1132d01b687429e2cf9c11df8ed11265 to your computer and use it in GitHub Desktop.
Save lighterowl/1132d01b687429e2cf9c11df8ed11265 to your computer and use it in GitHub Desktop.
Handy script for converting stuff to GIFs
#!/usr/bin/env bash
set -e
delpalette() {
rm -f "$palette"
}
usage() {
echo >&2 "Usage : $0 [-f fps] [-x xres] <input> <output>"
exit 1
}
fps=10
xres=320
while getopts 'f:x:' arg; do
echo "$@"
case "$arg" in
f) fps="$OPTARG" ;;
x) xres="$OPTARG" ;;
*) usage ;;
esac
done
shift $((OPTIND-1))
[[ $# -eq 2 ]] || usage
palette=$(mktemp /tmp/paletteXXXXX.png)
trap delpalette EXIT
ffmpeg -y -i "$1" -vf "fps=${fps},scale=${xres}:-1:flags=lanczos,palettegen" "$palette"
ffmpeg -i "$1" -i "$palette" \
-filter_complex "fps=${fps},scale=${xres}:-1:flags=lanczos[x];[x][1:v]paletteuse" \
"$2"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment