Last active
July 21, 2019 06:36
-
-
Save iilei/dce6ed2e69e95c5b21b9585e131d1db5 to your computer and use it in GitHub Desktop.
Convert quicktime movies to gif on a mac
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
#!/usr/bin/env sh | |
while [ "$#" -gt 0 ]; do | |
case "$1" in | |
-f) file="$2"; shift 2;; | |
-o) output="$2"; shift 2;; | |
--file=*) file="${1#*=}"; shift 1;; | |
--output=*) output="${1#*=}"; shift 1;; | |
--file|--output) echo "$1 requires an argument" >&2; exit 1;; | |
-*) echo "unknown option: $1" >&2; exit 1;; | |
*) handle_argument "$1"; shift 1;; | |
esac | |
done | |
join_path() { | |
echo "${1:+$1/}$2" | sed 's#//#/#g' | |
} | |
function gen_out_file_name { | |
base=$(basename -a -s .mov $file) | |
join_path $output ${base}.gif | |
} | |
function dimensions { | |
# Future Enhanceent: allow scaling | |
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $file | |
} | |
function output_full_path { | |
if [[ -d $output ]]; then | |
echo $(gen_out_file_name) | |
else | |
echo $output | |
fi | |
} | |
function run { | |
ffmpeg -i $file -s $(dimensions) -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $(output_full_path) | |
} | |
function preflight { | |
if [[ ! $output ]]; then | |
echo "No output param provided" | |
exit 1 | |
fi | |
if [[ ! $file ]]; then | |
echo "No file param provided" | |
exit 1 | |
fi | |
} | |
preflight | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment