This question already has an answer here:
- Read binary stdout data from adb shell? 15 answers
Recently, I wrote a PC client which can display and control my android phone screen in real-time using adb. I use the monkey to control the device and it works fine. The problem is how to grab the phone screen and display it smoothly.
The first solution I have come up with is to continually grab the framebuffer
through adb
(like DDMS's screen capture function). Now when I do it, the performance is quite unacceptable. The frame rate captured from framebuffer
is as low as 5 per second (the frame size is 800 * 480). My program looks like its hiccuping when I slide on the phone.
My program is written in java using ddmslib
to grab framebuffer
.
add:
I found it much slow to encoding the raw framebuffer
data into .png
format, otherwise this will be a fast way to transmit a compress raw image.
How can I improve the speed of capturing the screen to a smooth level?
From docs :
Taking a device screenshot
The screencap command is a shell utility for taking a screenshot of a device display. While in a shell, the syntax is:
To use the screencap from the command line, type the following:
Here's an example screenshot session, using the adb shell to capture the screenshot and the pull command to download the file from the device:
Recording a device screen
The screenrecord command is a shell utility for recording the display of devices running Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4 file.
A developer can use this file to create promotional or training videos. While in a shell, the syntax is:
To use screenrecord from the command line, type the following:
Stop the screen recording by pressing Ctrl-C, otherwise the recording stops automatically at three minutes or the time limit set by --time-limit.
To begin recording your device screen, run the screenrecord command to record the video. Then, run the pull command to download the video from the device to the host computer. Here's an example recording session:
The screenrecord utility can record at any supported resolution and bit rate you request, while retaining the aspect ratio of the device display. The utility records at the native display resolution and orientation by default, with a maximum length of three minutes.
There are some known limitations of the screenrecord utility that you should be aware of when using it:
Some devices may not be able to record at their native display resolution. If you encounter problems with screen recording, try using a lower screen resolution. Rotation of the screen during recording is not supported. If the screen does rotate during recording, some of the screen is cut off in the recording.
Source:
http://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html
In .bash_profile on my mac:
usage:
and the file shows up in whatever.png
adb shell screenrecord --bit-rate 8000000 --time-limit 30 /sdcard/example.mp4
You can change the bit rate and change the video duration also.
if the slow part is raw to png conversion (
time adb shell screencap -p /sdcard/x.png
is considerably slower thantime adb shell screencap /sdcard/nonpng.raw
, as I have it in games) and png is not necessary, then you can do like here https://github.com/sowcow/shot. It converts raw data to simple ppm format and converts ppm to bmp using imagemagick with almost no overhead after it gets raw dataupd:
This shell script by max_plenert is a better example: