如何减少MediaCodec H264编码器延迟 [英] how to reduce MediaCodec H264 encoder latency

查看:1716
本文介绍了如何减少MediaCodec H264编码器延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Android6.0的MediaCodec将h264编码为实时低延迟流. 编码器大约有6帧延迟,我想知道如何减少

I'm trying to encode h264 into stream in real-time low latency with Android6.0's MediaCodec. There are about 6 frames latency from encoder which I wanna know how to reduce

代码来自 screenrecord.cpp

部分代码为:

while (true) {
     encoder->dequeueOutputBuffer(&bufIndex);
}

编码器以320x480 60 fps的分辨率通过屏幕表面馈送,并通过dequeueOutputBuffer()输出流数据. 大约有6帧输入到编码器,其数据不会通过dequeueOutputBuffer()立即返回. 换句话说,当馈送第N帧时,编码器输出第(N-6)帧的数据.

the encoder is feed by Surface of screen in 320x480 60 fps, and it outputs stream data by dequeueOutputBuffer(). There are about 6 frames feed to encoder whose data are not return immedately by dequeueOutputBuffer(). In other words, when the N-th frame are feeded, the encoder output data of the (N-6)th frame.

问题1-如何减少编码器中缓冲的帧?在将第N帧馈入编码器后是否可以输出第N帧?

Question 1 - How to reduce frames buffered in encoder? Is it possible to output the N-th frame just after N-th frame is feed to encoder?

PS:问题1与此问题相同. (尚无好的解决方案).

PS: Question 1 is the same to this question.(no good solution yet).

当表面图形内容突然变为静态时,不再有帧输入到编码器.奇怪的是,最新的6帧数据无法以其正常速度"输出,它们会在大约10秒钟内缓慢输出.

When surface graphic content suddenly become static, no more frames are feed to encoder. It's strange that the latest 6 frames data cannot output on it's "usual speed", they are slowly outputted in about 10 seconds.

问题2-当突然没有数据馈送到编码器时,如何减少最新帧输出的延迟?

Question 2 - How to reduce the latency of latest frames output when suddenly no data feed to encoder?

推荐答案

缓冲由视频编码器确定.除了选择不以这种方式运行的视频编码器外,我认为您没有太多可以做的事情.

The buffering is determined by the video encoder. I don't think there's much you can do about it, other than select a video encoder that doesn't behave this way.

如果您不希望输出暂停,最简单的解决方法是不暂停输入.继续馈入相同的帧.编码器应识别出什么都没有改变,并且几乎不会产生输出. screenrecord无法以这种方式工作-它只是在获取帧时提交帧-因此您必须添加超时以重新提交帧.

If you don't want the output to pause, the easiest fix is to not pause the input. Keep feeding the same frame in. The encoder should recognize that nothing has changed and generate very little output. screenrecord doesn't work this way -- it just submits frames as it gets them -- so you'd have to add a timeout that re-submits frames.

这篇关于如何减少MediaCodec H264编码器延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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