'ADB exec-out not working

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?



Solution 1:[1]

You need a one line only:

adb exec-out screencap -p > [path]

Example:

adb exec-out screencap -p > d:\screenshot.png

Solution 2:[2]

"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?

Solution 3:[3]

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

Solution 4:[4]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 M. A.
Solution 2 Community
Solution 3 user25917
Solution 4 Diego Torres Milano