[英]Android mediacodec decoding h264 stream in real time with about 1 second latency
I am trying to decode h264 live stream from WIFI camera by madiacodec in Galaxy S3, the video plays OK, but it seems that mediacode low level always buffers 1 second of video frames, a new frame can be decoded only by a new incoming NAL unit. 我试图通过Galaxy S3中的madiacodec从WIFI摄像头解码h264直播流,视频播放正常,但似乎mediacode低电平总是缓冲1秒视频帧,新帧只能由新传入的NAL单元解码。 This causes about 1 second of latency. 这导致大约1秒的延迟。
When MediaCodec.createDecoderByType("video/avc");
当MediaCodec.createDecoderByType("video/avc");
is called I can see from logcat that 22 buffers are allocated, 调用我可以从logcat看到分配了22个缓冲区,
01-04 15:39:02.799: I/ExtendedCodec(13374): Smoothstreaming Enabled
01-04 15:39:02.809: I/ACodec(13374): [OMX.qcom.video.decoder.avc] Now Loaded->Idle
01-04 15:39:02.809: I/ACodec(13374): [OMX.qcom.video.decoder.avc] Allocating 22 buffers from a native window of size 245760 on output port
01-04 15:39:02.889: D/DecodeActivity(13374): Decoder started at --- 1388867942894
01-04 15:39:02.889: I/ACodec(13374): [OMX.qcom.video.decoder.avc] Now Idle->Executing
01-04 15:39:03.019: I/ACodec(13374): [OMX.qcom.video.decoder.avc] Now Executing
And I can see about 16 NAL units need to be pushed into decoder before I can get any frame out. 我可以看到在我可以取出任何帧之前需要将16个NAL单元推入解码器。
My question is that why this video buffering? 我的问题是为什么这个视频缓冲? any way I can try to allocate less buffer if that is the problem. 如果这是问题,我可以尝试分配更少的缓冲区。 Is there anyway I can reduce this video buffering? 无论如何,我可以减少这个视频缓冲?
First of all, are you sure that each NAL unit corresponds to one frame? 首先,你确定每个NAL单元对应一个帧吗? H.264 doesn't dictates how many NAL unit will be there for each frame, it depends on encoder implementation. H.264没有规定每帧有多少NAL单元,它取决于编码器的实现。 Second thing, I'm having similar issues when using a device with Qualcomm chipset. 第二件事,我在使用Qualcomm芯片组的设备时遇到了类似的问题。 I'm not using MediaCodec, but IOMX interface, but basically I get the same latency. 我没有使用MediaCodec,而是使用IOMX接口,但基本上我得到了相同的延迟。 I wonder if you you have prints in logcat saying how mnay input buffers are allocated. 我想知道你是否在logcat中有关于如何分配mnay输入缓冲区的打印件。 Those will be more relevant to the issue, and not the buffers on the output port. 这些与问题更相关,而不是输出端口上的缓冲区。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.