2

I'm trying to capture my android emulator screen using ADB commands, but when I execute the command nothing happens, no error and no image, this is the command I'm running:

adb exec-out screencap -p /sdcard/Pictures/test.png

I tried to use "adb shell....", but it is too slow for me.

Do I need something to run the "exec-out"? Or am I doing something wrong?

Kyore
  • 388
  • 2
  • 7
  • 29
  • Could you try quoting the subcommand? `adb "exec-out screencap -p /sdcard/Pictures/test.png"`, also, what is the return code of both versions? After running the command, `echo $?` – Matt Clark Mar 02 '17 at 19:57
  • ADB Version 1.0.31, I just realized that running the command from command line directly, it lists all adb command, it kinda means "exec-out" does not exists, do I need to install something else? – Kyore Mar 04 '17 at 13:59
  • Did you get this figured out? I'm having the exact same issue. "exec-out" does exist, as 'adb exec-out pwd' prints 'error: closed' - NOT 'command not found' or something like that. – jcovert May 25 '18 at 20:08
  • @jcovert, https://stackoverflow.com/a/13587203/1778421 – Alex P. Jul 26 '18 at 00:12

4 Answers4

2

You need a one line only:

adb exec-out screencap -p > [path]

Example:

adb exec-out screencap -p > d:\screenshot.png
M. A.
  • 424
  • 6
  • 21
  • @Chris623 - 'exec-out' was added to adb as a command in a later version of Android. I don't remember exactly, but Android < 5.0 definitely doesn't have exec-out. So while this solution would work if I had 'exec-out', my question was different. – jcovert May 13 '19 at 17:15
0

"adb exec-out" gives binary output.

You can use below commands to save the screens

adb shell screencap -p /sdcard/screencap.png

adb pull /sdcard/screencap.png C:\\Users\\<username>\\Pictures\\screencap.png

More info :

Read binary stdout data from adb shell?

Community
  • 1
  • 1
krrishna
  • 2,050
  • 4
  • 47
  • 101
  • As I said in the first post, I did use "adb shell screencap...", but it is too slow, it takes like ~500ms to create the .png file, it's too slow. – Kyore May 04 '17 at 01:14
  • @Kyore Did you find a solution? I need help on this too. – sguan Jun 23 '17 at 21:18
  • Not really, exec-out never works and I couldn't find anything helpfull in the internet, so I gaveup for now hahaha – Kyore Jul 05 '17 at 16:12
  • 1
    @Kyore if you are windows, try `adb exec-out "screencap -p | base64"` and then decode the output with base64,. – Ian Hu Jan 02 '18 at 07:14
  • @lan Hu: I get the error: "base64: not found". And if I remove the quotes: "'base64' is not recognized as an internal or external command, operable program or batch file." – Elmue Jun 04 '18 at 14:20
0

adb exec-out screencap is a safe way to generate screenshot in bitmap format.

You can use pipe read that raw data. The first 4 bytes mark the little-endian integer for width. The next 4 bytes is the height. The next 4 bytes indicate the image format. Following bytes is raw data for the images like RGBA8888.

Note: Do not use raw data from adb shell screencap. The shell will insert some line breaks so data could broke.

Ref: https://github.com/aosp-mirror/platform_system_core/blob/46f281edf5e78a51c5c1765460cddcf805e88d48/adb/daemon/framebuffer_service.cpp#L88-L91

user25917
  • 797
  • 7
  • 18
0

If you find that adb exec-out screencap is too slow or problematic for your case you can try CulebraTester2-public which would be much faster.

You can even use curl or any other HTTP client to take the screenshot like this

curl -sf -H 'accept: image/png' -H 'Content-Type: application/json' -X GET 'http://localhost:9987/v2/uiDevice/screenshot' > img.png

See the complete example at take-screenshot.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134