Skip to content

Commit

Permalink
feat(Args): allow available ffmpeg arguments to be sent to the script
Browse files Browse the repository at this point in the history
  • Loading branch information
fjcaetano committed Jul 16, 2019
1 parent c0b235a commit 95f0afc
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions bin/ios-simulator-gif
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand All @@ -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}"
Expand Down

0 comments on commit 95f0afc

Please sign in to comment.