From 95f0afcb1e71b59c59e04e289e57eda1f94b04f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Caetano?= Date: Tue, 16 Jul 2019 16:08:11 -0300 Subject: [PATCH] feat(Args): allow available ffmpeg arguments to be sent to the script --- bin/ios-simulator-gif | 59 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/bin/ios-simulator-gif b/bin/ios-simulator-gif index 018bc76..4ec72b5 100755 --- a/bin/ios-simulator-gif +++ b/bin/ios-simulator-gif @@ -3,8 +3,63 @@ # Records iOS simulator screen and saves as a gif to simulator.gif # A new file name may be passed as argument -FILE_NAME=${1-simulator.gif} +######################### +# The command line help # +######################### +display_help() { + echo "Usage: $0 [options] {out_file}" >&2 + echo + echo " out_file The output file name (default: simulator.gif)" + echo + echo " -r, --rate Framerate of the output (default: 6)" + echo " -f, --format Output format (default: gif)" + echo " -vf, --video-filter Video filter for ffmpeg (default: scale=320:-1)" + echo " -h, --help Outputs this help message" + echo + exit 0 +} +######################## +### ARGS PARSING ### +######################## +FILE_NAME=() +while [[ $# -gt 0 ]] +do +key="$1" + +case $key in + -r|--rate) + RATE="$2" + shift 2 + ;; + -f|--format) + FORMAT="$2" + shift 2 + ;; + -vf) + VIDEOFILTER="$2" + shift 2 + ;; + -h|--help) + display_help + shift + ;; + *) # unknown option + FILE_NAME+=("$1") # save it in an array for later + shift + ;; +esac +done +set -- "${FILE_NAME[@]}" + +FILE_NAME=${FILE_NAME-simulator.gif} +RATE=${RATE-6} +VIDEOFILTER=${VIDEOFILTER-'scale=320:-1'} +FORMAT=${FORMAT-gif} + +################## +### RECORD ### +################## echo 'Recording...\n\n[Press any key to stop recording]' xcrun simctl io booted recordVideo /tmp/simulator.mov & @@ -14,7 +69,7 @@ read -n1 kill -2 $PID echo "Converting and saving to ${FILE_NAME}\n" -ffmpeg -i /tmp/simulator.mov -vf scale=320:-1 -r 6 -f gif -y $FILE_NAME &> /tmp/ffmpeg.log +ffmpeg -i /tmp/simulator.mov -vf $VIDEOFILTER -r $RATE -f $FORMAT -y $FILE_NAME &> /tmp/ffmpeg.log if [[ $? -eq 0 ]]; then echo "Gif saved to ${FILE_NAME}"