Last active
April 15, 2019 13:47
-
-
Save dhoko/2a57b9b43a333c568973c26c2926d84f to your computer and use it in GitHub Desktop.
Convert a video to gif (webm/mp4)
This file contains hidden or 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/bash | |
# | |
inputFile=$1 | |
FPS=15 | |
WIDTH=$2 | |
OUTPUT='output.gif'; | |
PALETTE_OUTPUT='tmp_palette.png'; | |
# | |
# Convert mp4/webm to gif original or custom size | |
# Usage: | |
# ./convert.sh <fileName>.<ext> <size> | |
# Output file = ./output.gif | |
# | |
# | |
if [[ "$inputFile" == *.webm ]] | |
then | |
ffmpeg -threads 4 -y -i "$inputFile" -vf palettegen "$PALETTE_OUTPUT" | |
ffmpeg -threads 4 -y -i "$inputFile" -i "$PALETTE_OUTPUT" -filter_complex "fps=$FPS,scale=$WIDTH:-1:flags=lanczos[x];[x][1:v]paletteuse" -r 10 $OUTPUT | |
else | |
#Generate palette for better quality | |
ffmpeg -threads 4 -i "$inputFile" -vf fps=$FPS,scale=$WIDTH:-1:flags=lanczos,palettegen "$PALETTE_OUTPUT" -threads 4 | |
#Generate gif using palette | |
ffmpeg -threads 4 -i "$inputFile" -i "$PALETTE_OUTPUT" -loop 0 -filter_complex "fps=$FPS,scale=$WIDTH:-1:flags=lanczos[x];[x][1:v]paletteuse" $OUTPUT | |
fi; | |
rm "$PALETTE_OUTPUT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment