在应用中使用Android屏幕录​​像捕捉到每秒15帧捉到、屏幕、Android

2023-09-07 15:47:13 作者:Attack丶放肆

很多搜索和实验天之后,我还没有找到一个直接的解决方案。

After a lot of searching and days of experiments I haven't found a straight-forward solution.

我开发一个应用程序,用户与屏幕上的宠物互动,我希望让他将其保存为视频。

I'm developing an app that user will interact with a pet on the screen and i want to let him save it as video.

有没有简单的方法来捕获应用程序本身的屏幕?

Is there any "simple" way to capture the screen of the app itself?

我发现了一个解决方法(以节省一些位图每一秒,然后将它们传递到一间codeR),但似乎太重了。我会即使有每秒15帧的帧率

I found a workaround (to save some bitmaps every second and then pass them to an encoder) but it seems too heavy. I will happy even with a framerate of 15fps

这似乎是可能的,即有一个类似的应用程序,这样做,它被称为会说话的汤姆

It seems to be possible, i.e. there is a similar app that does this, its called "Talking Tom"

推荐答案

这真的取决于你实现你的宠物观的方式。你在绘图画布? OpenGL ES的?普通的Andr​​oid视图层次?

It really depends on the way you implement your "pet view". Are you drawing on a Canvas? OpenGl ES? Normal Android view hierarchy?

不管怎样,有没有神奇的recordScreenToVideo()之类的评论一说。

Anyway, there is no magical "recordScreenToVideo()" like one of the comments said.

您需要:

获取位图重新presenting你的画面。这取决于你如何实现你的看法。如果绘制自己(帆布或OpenGL),那么你的原始像素缓冲区保存为帧。如果使用普通视图层次,Android的子类的OnDraw并保存你的画布上的画面。该系统的调用的onDraw的频率将不超过屏幕实际的帧率少。如果需要的话,重复帧之后提供一个15fps的视频。

Obtain bitmaps representing your "frames". This depends on how you implement your view. If you draw yourself (Canvas or OpenGL), then save your raw pixel buffers as frames. If you use the normal view hierarchy, subclass Android's onDraw and save the "frames" that you get on the canvas. The frequency of the system's call to onDraw will be no less than the actual "framerate" of the screen. If needed, duplicate frames afterwards to supply a 15fps video.

恩code你的帧。好像你已经有一个机制来做到这一点,你只需要它是更有效的。

Encode your frames. Seems like you already have a mechanism to do that, you just need it to be more efficient.

办法可以优化编码:

缓存你的位图(帧)和EN code之后。这将工作只有当你的预计视频将是比较短的,否则你会得到出入库。只在您的应用程序实际生成(取决于你画的方式)帧率记录和使用EN codeR参数生成15fps的视频(不每秒实际提供15帧)。调整质量设置为当前设备。可以通过执行应用程序启动时隐藏的CPU循环试验和定义一些阈值来完成。恩code仅在屏幕的最相关的部分。同样,真的取决于你实现的方式 - 如果你可以节省一些历史数据,然后将其转换为框架,而无需做实时的,这将是最好的。例如,移动,微笑,改变颜色 - 无论你的业务逻辑是,因为你并没有详细说明这一点。你的生成电影功能将动画这段历史数据作为帧序列(不绘制到屏幕),然后连接code。

希望帮助