сжать ADB ScreenCap на Python - PullRequest
       18

сжать ADB ScreenCap на Python

0 голосов
/ 26 февраля 2019

Да, я могу получить png-поток из оболочки

adb exec-out screencap -p

такой код Python

start_time = time()

pipe = subprocess.Popen("adb exec-out screencap -p", stdout=subprocess.PIPE, shell=True)
img_bytes = pipe.stdout.read()
read_time = time()

img = cv2.imdecode(np.frombuffer(img_bytes, np.uint8), cv2.IMREAD_COLOR)
end_time = time()

print('stream size', len(img_bytes))
print('read cost', read_time - start_time)
print('decode cost', end_time - read_time)
print('screencap cost', end_time - start_time)

И все же он все еще слишком медленный

size 2452217
read cost 2.630615234375
decode cost 0.0625
screencap cost 2.693115234375

Могу ли я сжать screencap перед выводом?

1 Ответ

0 голосов
/ 26 февраля 2019

Если ваше устройство поддерживает его, попробуйте использовать:

adb exec-out screenrecord --output-format=h264 -

Вместо этого будет выведен поток фильма h264, который будет сжат значительно меньше как на хосте adb, так и на мобильном устройстве.

Для получения дополнительной информации, проверьте Используйте команду adb screenrecord для зеркального отображения экрана Android на ПК через USB

Кроме того, вы также можете указать несколько аргументов:

--help  Displays command syntax and options
--size WidthxHeight     Sets the video size: 1280x720. The default value is the device's native display resolution (if supported), 1280x720 if not. For best results, use a size supported by your device's Advanced Video Coding (AVC) encoder.
--bit-rate rate     Sets the video bit rate for the video, in megabits per second. The default value is 4Mbps.
--time-limit time   Sets the maximum recording time, in seconds. The default and maximum value is 180 (3 minutes).
--rotate    Rotates the output 90 degrees. This feature is experimental.
--verbose   Displays log information on the command-line screen. If you do not set this option, the utility does not display any information while running.

Источник: https://developer.android.com/studio/command-line/adb#screenrecord

...