Last active
February 20, 2019 23:06
-
-
Save stoggi/a45b1e3402d4eb76d2b270fc6a742386 to your computer and use it in GitHub Desktop.
Create a gif from a video using ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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