Skip to content

Instantly share code, notes, and snippets.

@dunn
Last active May 29, 2020 21:16
Show Gist options
  • Save dunn/7d6e7b9ce19b32f5af8e3972ad5b0648 to your computer and use it in GitHub Desktop.
Save dunn/7d6e7b9ce19b32f5af8e3972ad5b0648 to your computer and use it in GitHub Desktop.
#!/bin/sh
start="${1}"
duration="${2}"
input="${3}"
output="${4}"
palette="$(pwd)/palette-tmp.png"
filters="fps=15,scale=800:-1:flags=lanczos"
palette_cmd="ffmpeg -v warning -ss \"${start}\" -t \"${duration}\" -i \"${input}\" -vf \"${filters},palettegen=stats_mode=diff\" -y \"${palette}\""
echo
echo 'Generating palette...'
echo "${palette_cmd}"
eval "${palette_cmd}"
echo
gif_cmd="ffmpeg -v warning -ss \"${start}\" -t \"${duration}\" -i \"${input}\" -i \"${palette}\" -lavfi \"${filters} [x]; [x][1:v] paletteuse=dither=floyd_steinberg\" -y \"${output}\""
echo 'Generating GIF...'
echo "${gif_cmd}"
eval "${gif_cmd}"
rm "${palette}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment