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 15:56

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:

screencap <filename>

To use the screencap from the command line, type the following:

$ adb shell screencap /sdcard/screen.png

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:

$ adb shell
shell@ $ screencap /sdcard/screen.png
shell@ $ exit
$ adb pull /sdcard/screen.png

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.

Note: Audio is not recorded with the video file.

A developer can use this file to create promotional or training videos. While in a shell, the syntax is:

screenrecord [options] <filename>

To use screenrecord from the command line, type the following:

$ adb shell screenrecord /sdcard/demo.mp4

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:

$ adb shell
shell@ $ screenrecord --verbose /sdcard/demo.mp4
(press Ctrl-C to stop)
shell@ $ exit
$ adb pull /sdcard/demo.mp4

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.

查看更多
何必那么认真
3楼-- · 2019-01-30 15:58
adb shell screencap /sdcard/screen.png && adb pull /sdcard/screen.png my_screen01.png
查看更多
兄弟一词,经得起流年.
4楼-- · 2019-01-30 15:59
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png

Source:

http://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html

查看更多
不美不萌又怎样
5楼-- · 2019-01-30 16:07

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
}

usage:

droidshot whatever

and the file shows up in whatever.png

查看更多
爷的心禁止访问
6楼-- · 2019-01-30 16:07

adb shell screenrecord --bit-rate 8000000 --time-limit 30 /sdcard/example.mp4

You can change the bit rate and change the video duration also.

查看更多
Summer. ? 凉城
7楼-- · 2019-01-30 16:09

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

upd:

This shell script by max_plenert is a better example:

adb shell screencap /sdcard/mytmp/rock.raw
adb pull /sdcard/mytmp/rock.raw
adb shell rm /sdcard/mytmp/rock.raw

// remove the header
tail -c +13 rock.raw > rock.rgba

// extract width height and pixelformat:
hexdump -e '/4 "%d"' -s 0 -n 4 rock.raw
hexdump -e '/4 "%d"' -s 4 -n 4 rock.raw
hexdump -e '/4 "%d"' -s 8 -n 4 rock.raw

convert -size 480x800 -depth 8 rock.rgba rock.png
查看更多
登录 后发表回答