How to capture the screen as fast as possible thro

2019-01-30 15:29发布

This question already has an answer here:

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?

标签: android adb
12条回答
家丑人穷心不美
2楼-- · 2019-01-30 16:11

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
查看更多
小情绪 Triste *
3楼-- · 2019-01-30 16:13

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
查看更多
等我变得足够好
4楼-- · 2019-01-30 16:15

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.

查看更多
Root(大扎)
5楼-- · 2019-01-30 16:17

This a slow solution, i am sure it is the faster way you may find in adb based solutions,

# this line require a superuser privilege:
adb shell "su -c 'cat /dev/graphics/fb0 > /sdcard/capture.raw'"

adb pull /sdcard/capture.raw

ffmpeg -loglevel panic -f rawvideo -pix_fmt bgr32 -s 320x480 -i \ 
    capture.raw -vcodec png -vframes 1 capture.png; 

this is the same code into my web application

查看更多
一夜七次
6楼-- · 2019-01-30 16:20

There is a screenrecord program as of Android 4.4

adb shell screenrecord /data/local/tmp/test-video.m4v
adb pull /data/local/tmp/test-video.m4v ~/test-video.m4v
查看更多
Evening l夕情丶
7楼-- · 2019-01-30 16:23

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.

查看更多
登录 后发表回答