Skip to content

Instantly share code, notes, and snippets.

@bbody
Created December 22, 2018 08:41
Show Gist options
  • Save bbody/f59441370dd4c7ce0109949d78e21544 to your computer and use it in GitHub Desktop.
Save bbody/f59441370dd4c7ce0109949d78e21544 to your computer and use it in GitHub Desktop.
Video to GIF with colour optimization
#!/bin/sh
# Arguments:
# First argument: input file
# -ss: start time [optional]
# -t: end time [optional]
# Example usage:
# ./video_to_gif.sh input_file.mov
# ./video_to_gif.sh input_file.mov -ss 1.00
# ./video_to_gif.sh input_file.mov -t 5.00
# ./video_to_gif.sh input_file.mov -ss 1.00 -t 5.00
# Build a colour palette from video
`ffmpeg $2 $3 -i $1 -filter_complex "[0:v] palettegen" palette.png`
# Generate the gif
`ffmpeg $2 $3 -i $1 -i palette.png -filter_complex "[0:v]fps=10[x];[x]scale=800:-1[y];[y]paletteuse" -f gif output.gif`
# Delete the colour pallete
rm palette.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment