Last active
September 4, 2019 10:55
-
-
Save tristan/0fca623e360087f66c369e772c1b41e0 to your computer and use it in GitHub Desktop.
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/bash | |
# Usage: | |
# ./convert_to_gif <INPUT> [ffmpeg args] | |
# e.g. to specify the length of the output: use ffmpeg arg `-t seconds` | |
# ./convert_to_gif some_long_video.mp4 -t 10 | |
FPS=15 | |
PTS=0.5 # https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video | |
OUTPUT_WIDTH=400 | |
THREADS=8 | |
INFILE=$1 | |
shift | |
OUTFILE=${INFILE%.*}.gif | |
PALETTE=/tmp/palette.$RANDOM.png | |
ffmpeg "$@" -threads $THREADS -i "$INFILE" -vf setpts=$PTS*PTS,fps=$FPS,scale=$OUTPUT_WIDTH:-1:flags=lanczos,palettegen "$PALETTE" | |
ffmpeg "$@" -threads $THREADS -i "$INFILE" -i "$PALETTE" \ | |
-filter_complex "setpts=$PTS*PTS,fps=$FPS,scale=$OUTPUT_WIDTH:-1:flags=lanczos[x];[x][1:v]paletteuse" \ | |
"$OUTFILE" | |
rm $PALETTE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment