【问题标题】:compress adb screencap on python在 python 上压缩 adb screencap
【发布时间】:2019-02-26 04:28:10
【问题描述】:

是的,我可以从 shell 中获取 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

我可以在输出前压缩屏幕截图吗?

【问题讨论】:

    标签: python adb screenshot


    【解决方案1】:

    如果您的设备支持,请尝试使用:

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

    这将改为输出 h264 电影流,该流在 adb 主机和移动设备上的压缩要求将大大降低。

    欲了解更多信息,请查看Use adb screenrecord command to mirror Android screen to PC via 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

    【讨论】:

    • 谢谢,但是视频比截图慢
    • 您使用的是什么设备以及如何通过 ADB、Wi-Fi 或 USB 连接?
    • 模拟器。现在我找到了最好的方法:使用uiautomator2,只需要0.2s
    • @molysama 我正在寻找相同的解决方案,您如何使用 uiautomator2 截屏请分享一些资源。
    猜你喜欢
    • 2015-07-31
    • 2014-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多