适用于Android 4.4屏幕录制的API? [英] API's for Android 4.4 screen recording?

查看:90
本文介绍了适用于Android 4.4屏幕录制的API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其中一个 Android 4.4(Kit Kat)功能是它为开发人员提供了一种使用 adb shell screenrecord 捕获屏幕上的MP4视频的方法.Android 4.4是否为应用程序提供了任何新的API来捕获和编码视频,还是仅提供了 screenrecord 实用工具/二进制文件?

One of the features of Android 4.4 (Kit Kat) is that it provides a way for developers to capture an MP4 video of the screen using adb shell screenrecord. Does Android 4.4 provide any new API's for applications to capture and encode video, or does it just provide the screenrecord utility/binary?

我问是因为我想在我正在编写的应用程序中做一些屏幕捕获工作.在任何人问之前,是的,应用程序具有帧缓冲区访问权限.但是,我见过的唯一Android提供的捕获/编码API( MediaRecorder )似乎仅限于从设备的摄像头录制视频 .

I ask because I would like to do some screen capture work in an application I'm writing. Before anyone asks, yes, the application would have framebuffer access. However, the only Android-provided capturing/encoding API that I've seen (MediaRecorder) seems to be limited to recording video from the device's camera.

我在StackOverfow上看到的唯一的屏幕捕获解决方案似乎围绕定期捕获屏幕快照或使用JNI通过ffmpeg的移植版本对帧缓冲区进行编码.是否有更优雅的本地解决方案?

The only screen capture solutions I've seen mentioned on StackOverfow seem to revolve around taking screenshots at a regular interval or using JNI to encode the framebuffer with a ported version of ffmpeg. Are there more elegant, native solutions?

推荐答案

screenrecord 实用程序使用私有API,因此您无法完全 进行操作.

The screenrecord utility uses private APIs, so you can't do exactly what it does.

它的工作方式是创建虚拟显示,将虚拟显示路由到视频编码器,然后将输出保存到文件.您基本上可以做同样的事情,但是由于您不是以外壳"用户身份运行的,因此只能看到创建的图层.相关API是围绕创建演示而设计的正是您想要的.

The way it works is to create a virtual display, route the virtual display to a video encoder, and then save the output to a file. You can do essentially the same thing, but because you're not running as the "shell" user you'd only be able to see the layers you created. The relevant APIs are designed around creating a Presentation, which may not be exactly what you want.

请参见

See the source code for a CTS test with a trivial example (just uses an ImageView).

当然,如果您碰巧是GLES应用程序,则可以直接记录输出(请参见例如EncodeAndMuxTest Grafika )中的"Record GL app"活动.

Of course, if you happen to be a GLES application, you can just record the output directly (see e.g. EncodeAndMuxTest and the "Record GL app" activity in Grafika).

这篇关于适用于Android 4.4屏幕录制的API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆