Created
September 2, 2020 19:49
-
-
Save levilansing/5f0a4ff82ff42fa07c8ced290fb78376 to your computer and use it in GitHub Desktop.
Bash script to convert mov screen recordings to gifs
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/sh | |
if [ -z $1 ] | |
then | |
echo 'Usage: mov2gif [50%] [15fps] source_file [destination_file]' | |
exit 1 | |
fi | |
scale=1 | |
scale_pat='^[0-9]+%$' | |
if [[ $1 =~ $scale_pat ]] | |
then | |
scale=`echo $1 | tr -d % | sed -E 's/$/\/100/' | bc -l` | |
set -- ${@:2:4} | |
fi | |
fps=30 | |
fps_pat='^[0-9]+fps$' | |
if [[ $1 =~ $fps_pat ]] | |
then | |
fps=`echo $1 | tr -d 'fps'` | |
set -- ${@:2:3} | |
fi | |
source=$1 | |
source_gif=`echo $source | sed -E 's/\..{1,4}$|$/.gif/'` | |
dest=${2:-$source_gif} | |
palette="/tmp/palette.png" | |
filters="fps=$fps,scale=iw*$scale:ih*$scale:flags=lanczos" | |
ffmpeg -v warning -i "$source" -vf "$filters,palettegen" -y "$palette" | |
ffmpeg -v warning -i "$source" -i "$palette" -lavfi "$filters [x]; [x][1:v] paletteuse" -y "$dest" | |
echo "wrote $dest at ${fps}fps, scale of $scale" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment