Created
September 12, 2015 18:16
-
-
Save andyman/8c8ab869fbcaca9126b1 to your computer and use it in GitHub Desktop.
Converts a video file to a gif. Needs 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/bash | |
echo "USAGE" | |
echo "convert_to_gif.sh <video_file_name> <frames_per_second> <width> <start_second> <duration>" | |
echo "--------------------" | |
# from here: | |
# http://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality | |
INPUT_FILE=$1 | |
FPS=$2 | |
# width (it will keep the aspect ratio) | |
WIDTH=$3 | |
# start time in seconds | |
START_TIME=$4 | |
# duration after the start time | |
DURATION=$5 | |
ffmpeg -ss $START_TIME -t $DURATION -y -i $INPUT_FILE \ | |
-vf fps=$FPS,scale=$WIDTH:-1:flags=lanczos,palettegen palette.png | |
ffmpeg -ss $START_TIME -t $DURATION -i $INPUT_FILE -i palette.png -filter_complex \ | |
"fps=$FPS,scale=$WIDTH:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif | |
rm palette.png | |
convert -layers Optimize output.gif $1.gif | |
rm output.gif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment