Take the 2-minute tour ×

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.

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?

share|improve this question
Also looking for an answer to this. –  Ron Dec 21 '12 at 3:55
possible duplicate of Read binary stdout data from adb shell? –  Sergei Feb 1 at 18:16

7 Answers 7

if the slow part is raw to png conversion (time adb shell screencap -p /sdcard/x.png is considerably slower than time 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 data

share|improve this answer

Using this method, my app continues to run at it's full framerate

adb pull /dev/graphics/fb0

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.

share|improve this answer

In .bash_profile on my mac:

function droidShot() {
  /full_path_to_droid_sdk/platform-tools/adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > $1.png


droidshot whatever

and the file shows up in whatever.png

share|improve this answer

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):

adb shell screencap -p | perl -pe 'BEGIN { $/="\cM\cJ"; $\="\cJ"; } chomp;' > screen-$(date +%Y%m%d_%H%M%S).png
share|improve this answer

I have improved on @steveha's solution:

Create a shell script say: 'android-screenshot' with the following contents:

adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen-`date +%Y-%m-%d_%X`.png

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

chmod +x android-screenshot
share|improve this answer



share|improve this answer
For me (Windows 7 using Cygwin) the one with sed worked whereas perl resulted in corrupted file: adb shell screencap -p | sed 's/\r$//' > screen.png –  Mikaël Mayer Feb 20 at 6:53

You could use:

$ adb shell screencap -p > sc.png

which unfortunately doesn't work (file is corrupted), so your option left is

$ adb shell screencap -p /mnt/sdcard/sc.png
$ adb pull /mnt/sdcard/sc.png

while this is relatively fast, it's probably not as fast as you need.

share|improve this answer
Yeah, this is a feasible way to do it. But it is almost as the same speed as grabing framebuffer. –  Robot Dreamer Dec 21 '12 at 6:18

Your Answer


