相关文章推荐
率性的红酒  ·  Creating a Child ...·  5 月前    · 
大方的香烟  ·  Class Activation ...·  1 年前    · 
强悍的松鼠  ·  python编码转换(unicode ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm trying to get a screenshot of the phone screen as fast as possible. Currently, I am doing:

adb shell screencap -p /sdcard/screencap.png && adb pull /sdcard/screencap.png         

However it is too slow and takes up to 3 seconds. Is there any better way to do this? I intend to use this function with an unrooted phone.

Also what are the different arguments I can use for screencap?

Thanks.

EDIT (extra information): I intend to use this method to be able to get a live feed of the screen onto my pc. The current method works however it is too slow. I can't use adb shell screenrecord because I won't be able to access the video file while it is being recorded.

I intended to get a live feed of the screen onto my pc.. Is this a stupid way of doing this? adb shell screenrecord was an option but it wouldn't be able to be accessed during the recording. – user2513924 Jan 4, 2015 at 15:08 Do you need a live feed of only one application (that you develop), or it should work for anything that is running on that device? – dragi Jan 4, 2015 at 15:10 Then screenrecord should be your solution. Did you check this developer.android.com/tools/help/adb.html#screenrecord ? I have used Android Studio to record and I guess it uses the same thing. I was able to use the device while recording the screen. What device do you use for this and what OS version is there? – dragi Jan 4, 2015 at 15:32 Btw, because I use this frequently for sharing with designers and for product tutorials, I created a bash alias in my ~/.bash_profile that looks like this: alias adb_screenshot="adb -d shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > $(date +"%Y-%m-%d_%H-%M-%S").png". You call it with adb_screenshot in the terminal and it will save a .png file with the current timestamp as the filename. The -d option in the adb command means it will default to physical device (not the emulator). You can remove that if you are using this for an emulator. – Joshua Pinter Jul 22, 2017 at 0:39
$ snap_screen
11272 KB/s (256237 bytes in 0.022s)
Saved to /Users/worker8/desktop/screenshot.png

Usage with a filename:

$ snap_screen mega_screen_capture
11272 KB/s (256237 bytes in 0.022s)
Saved to /Users/worker8/desktop/mega_screen_capture.png

Hope it helps!

** This will not work if multiple devices are plugged in

To start recording your device’s screen, run the following command:

adb shell screenrecord /sdcard/example.mp4

This command will start recording your device’s screen using the default settings and save the resulting video to a file at /sdcard/example.mp4 file on your device.

When you’re done recording, press Ctrl+C in the Command Prompt window to stop the screen recording. You can then find the screen recording file at the location you specified. Note that the screen recording is saved to your device’s internal storage, not to your computer.

The default settings are to use your device’s standard screen resolution, encode the video at a bitrate of 4Mbps, and set the maximum screen recording time to 180 seconds. For more information about the command-line options you can use, run the following command:

adb shell screenrecord --help

This works without rooting the device. Hope this helps.

I won't be able to get a live feed of the video unless the file is being recorded directly to my pc. Thanks anyway though. – user2513924 Jan 4, 2015 at 16:34

You can read the binary from stdout instead of saving the png to the sdcard and then pulling it:

adb shell screencap -p | sed 's|\r$||' > screenshot.png

This should save a little time, but not much.

source: Read binary stdout data from adb shell?

This always worked for me, but I just had to change this to sed 's|\r\r$||' (to remove TWO carriage returns) because I started getting corrupt PNGs. Not sure what changed (New version of ADB? New version of cygwin?) but something did. – Karu May 8, 2017 at 23:47

Using some of the knowledge from this and a couple of other posts, I found the method that worked the best for me was to:

adb shell 'stty raw; screencap -p'

I have posted a very simple Python script on GitHub that essentially mirrors the screen of a device connected over ADB:

https://github.com/baitisj/android_screen_mirror

Unfortunately, the version of adb that I have either does not properly support exec-out, or the option isn't properly supported under FreeBSD. The script that I posted does include comments indicating that exec-out is a better choice if it is supported in your environment. – baitisj Dec 7, 2016 at 18:54

Sorry to tell you screencap just a simple command, only accept few arguments, but none of them can save time for you, here is the -h help output.

$ adb shell screencap -h
usage: screencap [-hp] [-d display-id] [FILENAME]
-h: this message
-p: save the file as a png.
-d: specify the display id to capture, default 0.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.

Besides the command screencap, there is another command screenshot, I don't know why screenshot was removed from Android 5.0, but it's avaiable below Android 4.4, you can check the source from here. I didn't make my comparison which is faster between these two commands, but you can give your try in your real environment and make the final decision.

Thanks for that. Turns out the screenshot function is the actual device screenshot function (where it can play a sound) whereas screencap just takes a screenshot silently. It doesn't look like it's any faster but thanks anyway. – user2513924 Jan 4, 2015 at 15:30