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?
I have improved on @steveha's solution:
Create a shell script say: 'android-screenshot' with the following contents:
Place this file in your local bin directory or any other $PATH you prefer.
This would allow you to save the files with a timestamp in the current directory.
Remember to make the shell script executable using
Well some people said in Perl there is many ways to do one thing. :-) Anyway, this one may perform better (since there is no regular expression), and may resolve the issue in Cygwin in MS Windows (whose Perl define
\n
as CRLF):Using this method, my app continues to run at it's full framerate
This will pull down the raw data from the frame buffer. It seems to be the same width as the screen, but the height is padded out. The frame buffer on my device seems to be in RGBA8888 format. To get exactly what is displayed on screen, you should ignore the alpha channel.
Note that this does take ~0.8 seconds to download for me (resoultion: 480x854) but if i have it downloading on a continuous loop, it doesn't affect the device's frame rate.
This a slow solution, i am sure it is the faster way you may find in adb based solutions,
There is a
screenrecord
program as of Android 4.4You could use:
$ adb shell screencap -p > sc.pngwhich unfortunately doesn't work (file is corrupted), so your option left is
while this is relatively fast, it's probably not as fast as you need.