Skip to content

Instantly share code, notes, and snippets.

@iilei
Created July 21, 2019 06:27
Show Gist options
  • Save iilei/0e9b1e6412ec53395bcf4492d67fd915 to your computer and use it in GitHub Desktop.
Save iilei/0e9b1e6412ec53395bcf4492d67fd915 to your computer and use it in GitHub Desktop.
Convert quicktime movies to gif on a mac
#!/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)
}
run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment