控制VirtualDisplay的帧速率 [英] Controlling Frame Rate of VirtualDisplay

查看:4588
本文介绍了控制VirtualDisplay的帧速率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Android应用程序,并在它,我有一个 VirtualDisplay 来反映的是在屏幕上,然后我从屏幕发送帧的的媒体codeC实例。它的工作原理,但是,我要添加指定EN codeD的视频的FPS的一种方式,但我不确定如何做到这一点。

I'm writing an Android application, and in it, I have a VirtualDisplay to mirror what is on the screen and I then send the frames from the screen to an instance of a MediaCodec. It works, but, I want to add a way of specifying the FPS of the encoded video, but I'm unsure how to do so.

这是我读过的和试行,下降EN codeD架(以presentation次)不好用,因为它最终以块状/神器缠身的视频,而不是平稳在一个较低的帧率视频。其他读数表明,只有这样,才能做我想做的(限制FPS)是将输入的FPS限制为媒体codeC ,而 VirtualDisplay 只得到了表面这是从媒体codeC 如下

From what I've read and experimented with, dropping encoded frames (based on the presentation times) doesn't work well as it ends up with blocky/artifact ridden video as opposed to a smooth video at a lower framerate. Other reading suggests that the only way to do what I want (limit the FPS) would be to limit the incoming FPS to the MediaCodec, but the VirtualDisplay just receives a Surface which is constructed from the MediaCodec as below

mSurface = <instance of MediaCodec>.createInputSurface();
mVirtualDisplay = mMediaProjection.createVirtualDisplay(
    "MyDisplay",
    screenWidth,
    screenHeight,
    screenDensity,
    DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
    mSurface,
    null,
    null);

我也试着子类表面和限制被馈送到帧媒体codeC 通过 unlockCanvasAndPost(帆布油画)但功能似乎从来没有叫我的实例,因此,有可能是我如何延长表面的一些怪事并用的互动包裹 writeToParcel 函数的叫上我的实例,但是那是在叫我的实例(即我可以告诉)的唯一功能。

I've also tried subclassing Surface and limit the frames that are fed to the MediaCodec via the unlockCanvasAndPost(Canvas canvas) but the function never seems to be called on my instance, so, there may be some weirdness in how I extended Surface and the interaction with the Parcel as writeToParcel function is called on my instance, but that is the only function that is called in my instance (that I can tell).

其他的阅读建议我可以从连接codeR - >德codeR - >连接codeR和限制,其中第二EN codeR被送入帧的速度,但是这是一个很多额外的计算,我宁愿不要做,如果我能避免它。

Other reading suggests that I can go from encoder -> decoder -> encoder and limit the rate in which the second encoder is fed frames, but that's a lot of extra computation that I'd rather not do if I can avoid it.

有没有人成功地限制在哪个 VirtualDisplay 饲料的表面率?任何帮助将大大AP preciated!

Has anyone successfully limited the rate at which a VirtualDisplay feeds its Surface? Any help would be greatly appreciated!

推荐答案

与你的出发不能的DO ...

Starting off with what you can't do...

您不能删除的EN codeD流的内容。大多数在连接codeD流的框架基本上都是从其他帧diff文件。如果不知道如何帧互动,你不能安全地丢弃的内容,最终会与损坏的宏块的样子。

You can't drop content from the encoded stream. Most of the frames in the encoded stream are essentially "diffs" from other frames. Without knowing how the frames interact, you can't safely drop content, and will end up with that corrupted macroblock look.

您不能指定帧速率的媒体codeC连接codeR。它可能的东西,到元数据的地方,但真正重要的codeC的唯一的事情就是你喂到它的框架,和presentation时间戳与每个帧相关联。带连接codeR不会丢帧。

You can't specify the frame rate to the MediaCodec encoder. It might stuff that into metadata somewhere, but the only thing that really matters to the codec is the frames you're feeding into it, and the presentation time stamps associated with each frame. The encoder will not drop frames.

您不能做任何事情由子类表面有用。仅用于软件渲染,这是不相关的,以从照相机或虚拟显示在帧馈送画布操作

You can't do anything useful by subclassing Surface. The Canvas operations are only used for software rendering, which is unrelated to feeding in frames from a camera or virtual display.

您的能有什么的做的就是发送帧到中间面,然后选择是否将其转发给媒体codeC的输入表面。一种方法是创建一个表面纹理,从它构建一个表面,并传递到虚拟显示。当表面纹理的框架提供回调火灾,你要么不予理睬,或使纹理到媒体codeC输入表面与GLES。

What you can do is send the frames to an intermediate Surface, and then choose whether or not to forward them to the MediaCodec's input Surface. One approach would be to create a SurfaceTexture, construct a Surface from it, and pass that to the virtual display. When the SurfaceTexture's frame-available callback fires, you either ignore it, or render the texture onto the MediaCodec input Surface with GLES.

各种实例可以在 Grafika 和的 bigflake ,其中没有一个是完全相符,但所有必要的EGL和GLES类的都在那里。

Various examples can be found in Grafika and on bigflake, none of which are an exact fit, but all of the necessary EGL and GLES classes are there.

这篇关于控制VirtualDisplay的帧速率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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