首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在python上压缩adb录屏

在python上压缩adb录屏
EN

Stack Overflow用户
提问于 2019-02-26 12:28:11
回答 1查看 1.4K关注 0票数 0

是的,我可以从shell获取png流。

代码语言:javascript
复制
adb exec-out screencap -p

如下所示的python代码

代码语言:javascript
复制
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)

然而,它仍然太慢了

代码语言:javascript
复制
size 2452217
read cost 2.630615234375
decode cost 0.0625
screencap cost 2.693115234375

可以在输出前压缩录屏吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-26 12:39:37

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

代码语言:javascript
复制
adb exec-out screenrecord --output-format=h264 -

相反,这将输出一个h264电影流,它在adb主机和移动设备上的压缩要求将大大降低。

有关更多信息,请查看Use adb screenrecord command to mirror Android screen to PC via USB

此外,您还可以指定多个参数:

代码语言:javascript
复制
--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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54878453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档