Note: Many newer Android 10+ tablets can record the screen directly from the Quick Settings panel. Read this Google help page for details. This guide is for devices that don’t have that feature enabled.
This article explains how to use the Android Debug Bridge (adb) to record a video of your screen and save it as an MP4.
While testing a new feature for our Android app at work, I needed to record the screen to share a bug with the team. Rather than install a sketchy third-party screen recording app on my Galaxy Tab A 8” 2019 tablet, I decided to use the Android SDK tools as a fun and safe alternative. Here are my notes in case they help others (and my future self).
Install the Android Debug Bridge (adb)
The choice is yours — one is very heavy, and one is extremely light.
If you install the platform tools, you’ll need to unzip them, move the containing directory or symlink the individual binaries somewhere logical like /usr/local/bin, $HOME/bin, or $HOME/Applications, and then add that path to your $PATH if it’s not already there.
Here’s a nice resource for installing the SDK tools via your favorite package manager: https://guides.codepath.com/android/installing-android-sdk-tools. That said, I received a discontinuation notice while installing the android-sdk via Homebrew:
android-sdk has been officially discontinued upstream. It may stop working correctly (or at all) in recent versions of macOS.
In the end, I decided to go with the official Android SDK Platform Tools installation.
Prepare Your Device for Debugging
As described in Google’s “Configure on-device developer options” document, enable the Developer Options panel by finding the build version and tapping it 5–7 times:
- Android 9 (API level 28) and higher: Settings > About Phone > Build Number
- Android 8.0.0 (API level 26) and Android 8.1.0 (API level 26): Settings > System > About Phone > Build Number
- Android 7.1 (API level 25) and lower: Settings > About Phone > Build Number
Go into the Developer Options panel and enable USB debugging:
- Android 9 (API level 28) and higher: Settings > System > Advanced > Developer Options > USB debugging
- Android 8.0.0 (API level 26) and Android 8.1.0 (API level 26): Settings > System > Developer Options > USB debugging
- Android 7.1 (API level 25) and lower: Settings > Developer Options > USB debugging
Connect your device via USB and open a terminal. Allow your device to connect by accepting the prompt that appears on it.
Now list the connected Android devices:
$ adb devices
List of devices attached
A0BCD0EFGHI device
If you see your device in the list without the word unauthorized next to it, continue to the next section.
If you don’t see your device at all, try reconnecting it, rebooting it, or swapping USB ports or cables. I ran into the cable issue when using a defective or power-only USB cable.
If you see unauthorized next to your device, try restarting the adb server with the following commands:
$ adb devices
List of devices attached
A0BCD0EFGHI unauthorized
$ adb kill-server
$ adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully
If you’re still stuck, Google to the rescue. Sorry…
Recording the Screen
You can create a video of your screen using the adb shell screenrecord command (see the adb shell screenrecord documentation).
To start recording, run:
$ adb shell screenrecord --verbose /sdcard/video.mp4
Main display is 1280x800 @60.00fps (orientation=1)
Configuring recorder for 1280x800 video/avc at 20.00Mbps
Content area is 1280x800 at offset x=0 y=0
Press Control+C (or Command+C) to stop the recording.
Some useful command-line options:
| Flag | Description |
|---|---|
--size widthxheight |
Specify the video size. |
--bit-rate |
Set the video bitrate in Mbps. |
--time-limit |
Set a time limit (the current max and default is 3 minutes). |
--verbose |
Display output while recording. Otherwise the command will be silent. |
Transfer the video to your Desktop with:
$ adb pull /sdcard/video.mp4 ~/Desktop
/sdcard/video.mp4: 1 file pulled, 0 sk...ed. 22.5 MB/s (306109 bytes in 0.013s)
// Not sure why `skipped` is `sk..ed`?!
Conclusion
It’s always refreshing when you don’t need to install unknown, untrustworthy apps to do common tasks like screen recording. Hope this works out for you too!