Skip to content

Instantly share code, notes, and snippets.

@patrickhammond
Last active April 30, 2018 21:32
Show Gist options
  • Save patrickhammond/9173695 to your computer and use it in GitHub Desktop.
Save patrickhammond/9173695 to your computer and use it in GitHub Desktop.
Script to simplify screen recording with Android 4.4 and later devices. This takes care of setting the screenrecord flags, pulling files from the device, cleaning up after the recording, and optionally automatically opening the recording for you. Assumes only one connected device. Works for OSX but probably easy to make work with Linux (I believ…
#!/bin/bash
bitrate_flag=""
rotate_flag=""
open_when_done=0
OPTIND=1
while getopts "hron:" opt; do
case "$opt" in
h)
bitrate_flag="--bit-rate 8000000"
;;
r)
rotate_flag="--rotate"
;;
o)
open_when_done=1
;;
n)
name=$OPTARG
;;
esac
done
function show_help() {
echo "Script to make it easier to do screen recordings with Android 4.4 and later"
echo "Usage: $0 -n name [-h] [-o]"
echo " -n name Name of this recording. Do not include a file suffix."
echo " -r Rotate the recording."
echo " -h Use a higher quality bitrate"
echo " -o Open the file when when done."
echo
echo "Examples:"
echo " $0 -n demo"
echo " Will screen record and save the results to demo.mp4"
echo " $0 -n demo -h"
echo " Will record using high quality."
echo " $0 -n demo -h -r"
echo " Will record high quality but rotated."
echo " $0 -n demo -h -o"
echo " Will record using high quality and open the file when done."
echo
echo " You will need to press Ctrl-C when done recording."
}
if [[ -z "$name" ]] ; then
echo "Incorrect usage...showing help."
echo
show_help
exit 1
fi
trap ctrl_c INT
function ctrl_c() {
kill -INT $$
}
echo "Recording $name..."
adb shell screenrecord $bitrate_flag $rotate_flag /sdcard/$name.mp4
echo
echo
echo "Giving the device a second to wrap up the recording..."
sleep 1
echo
echo "Pulling $name.mp4 off the device..."
adb pull /sdcard/$name.mp4
echo
echo "Cleaing up the recording session..."
adb shell rm /sdcard/$name.mp4
echo
echo "Done! Created `pwd`/$name.mp4"
if [ $open_when_done == 1 ] ; then
echo
echo "Opening the recording..."
open `pwd`/$name.mp4
fi
Create a screen recording called demo.mp4:
./screenrecord.sh -n demo
Create a high quality screen recording called demo.mp4:
./screenrecord.sh -n demo -h
Create a high quality screen recording called demo.mp4 and automatically open it when done recording:
./screenrecord.sh -n demo -h o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment