Skip to content

Instantly share code, notes, and snippets.

@dunn
Created February 10, 2022 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dunn/6783ea68a9cd9d2cc31ad72b9c70e121 to your computer and use it in GitHub Desktop.
Save dunn/6783ea68a9cd9d2cc31ad72b9c70e121 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