Recording Android Screen with ADB and FFPlay
This is an old trick I used several years ago, and I am not sure if it is still relevant.
Google allows Android developers to record their Android device screen on their compiters using the ADB tool. This is quite useful, and woild be morr useful if they didn’t prevent recordings that last over 3 minutes.
It is not clear to me why Google decided to limit the recording time, but the hard limit is 3 minutes.
However, using the following script, and perhaps a tool like FFMPEG we can record the device’s screen for an arbitrarily long period of time.
To run the script you will need the android ADB tool (comes with Android SDK), and FFPLAY installed on your machine.
#!/bin/bash
#-------------------------------------------------------------------------------
# Script to pipe output of ADB shell screenrecord to FFPlay.
# This is a simple hack to circumvent the 3 minute max screenrecord
# record time enforced by the Android ADB tool.
#-------------------------------------------------------------------------------
if [ -z "$1" ]; then
echo "Please supply FFPlay location.";
exit 1;
fi
if [ -z "$2" ]; then
echo "Please supply iteration count. One iteration lasts for 3 minutes.";
exit 1;
fi
FFPLAY=$1
ITER=$2
TL=180
BR=1000000
VIDEOPIPE=/tmp/videopipe
function cleanup {
echo "Finishing recording session.";
rm $VIDEOPIPE;
exit 1;
}
trap cleanup INT
mkfifo $VIDEOPIPE
"$FFPLAY" - < $VIDEOPIPE &
for i in `seq 1 $ITER`
do
./adb shell screenrecord --bit-rate=$BR --size=1600x2560 \
--time-limit=$TL \
--output-format=h264 - > $VIDEOPIPE
done
With the above script you can record your android device’s screen indefinitely through ADB utils, and store the recording on your machine.