Created
March 3, 2016 13:40
-
-
Save jgwhite/c5d79eab960299fabaa8 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 | |
# vi: set ft=sh : | |
if [ $# -lt 2 ]; then | |
echo "Usage: movgif [options] | |
-i, --input | |
-o, --ouput | |
-w, --width | |
-h, --height | |
" | |
exit 0 | |
fi | |
RED="\033[31m" | |
ORANGE="\033[38;5;208m" | |
GREEN="\033[32m" | |
RESET="\033[0m" | |
input="" | |
output="" | |
palette="/tmp/palette.png" | |
fps=30 | |
width=375 | |
height=-1 | |
loglevel=warning | |
while [[ $# > 1 ]]; do | |
key="$1" | |
case $key in | |
-i|--input) | |
input="$2" | |
shift | |
;; | |
-o|--output) | |
output="$2" | |
shift | |
;; | |
-w|--width) | |
width="$2" | |
shift | |
;; | |
-h|--height) | |
height="$2" | |
shift | |
;; | |
*) | |
echo -e "${RED}Unknown option $1$RESET" | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
filters="fps=$fps,scale=$width:$height:flags=lanczos" | |
if [ ! $input ]; then | |
echo -e "${RED}Please specify input file with -i path/to/file.mov$RESET" | |
exit 1 | |
fi | |
if [ ! $output ]; then | |
echo -e "${RED}Please specify output file with -o path/to/file.gif$RESET" | |
exit 1 | |
fi | |
echo -e "$ORANGE==> $input -> $output$RESET" | |
echo -e "$ORANGE==> Generating palette$RESET" | |
ffmpeg \ | |
-loglevel $loglevel \ | |
-y \ | |
-i $input \ | |
-vf "$filters,palettegen" \ | |
$palette | |
echo -e "$ORANGE==> Generating gif$RESET" | |
ffmpeg \ | |
-y \ | |
-loglevel $loglevel \ | |
-i $input \ | |
-i $palette \ | |
-lavfi "$filters [x]; [x][1:v] paletteuse" \ | |
$output | |
echo -e "$GREEN==> Written to $output$RESET" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment