Skip to content

Instantly share code, notes, and snippets.

@stoggi
Last active February 20, 2019 23:06
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 stoggi/a45b1e3402d4eb76d2b270fc6a742386 to your computer and use it in GitHub Desktop.
Save stoggi/a45b1e3402d4eb76d2b270fc6a742386 to your computer and use it in GitHub Desktop.
Create a gif from a video using ffmpeg
#!/bin/sh
# Usage:
# gif.sh input output width fps
# Example:
# 12 frame per second
# 640 width (aspect ratio is preserved. Use -1 for no change)
# gif.sh input.mp4 output.gif 640 12
palette="/tmp/palette.png"
filters="fps=$4,scale=$3:-1:flags=lanczos"
# Generate a palette file for the most frequent colors in the input
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
# Convert the video to a gif using the palette and input parameters
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment