德code MP4使用不MediaExtractor媒体codeC / H.264,预计访问单元格式 [英] Decode mp4/h.264 using MediaCodec without MediaExtractor, expected access unit format

查看:343
本文介绍了德code MP4使用不MediaExtractor媒体codeC / H.264,预计访问单元格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的解码媒体codeC API不使用MediaExtractor API。相反,我使用mp4parser获得样本的MP4文件。现在,我只使用H.264 / AVC codeD的视频内容。

I am trying to use the MediaCodec API for decoding without using the MediaExtractor API. Instead, i use mp4parser to get the samples from the mp4 files. For now, i am only using h.264 / avc coded video content.

媒体codeC API的官方文档规定:

缓冲器不开始和结束在任意字节边界,这不是一个字节流,它的访问单元的流。

buffers do not start and end on arbitrary byte boundaries, this is not a stream of bytes, it's a stream of access units.

意义,我要养活接入单位到去codeR。但是,我错过了一些细节信息:

Meaning, i have to feed access units to the decoder. However, i miss some details in this information:

有关H.264,在mp4的样品,可以有多个NAL单元,是由4(默认)pceded每$ P $字节指定NAL单元长度

For h.264, in an mp4 sample, there can be multiple NAL units, that are each preceded by 4 (default) bytes specifying the NAL unit length.

现在我的问题:

  1. 可以有MP4样品,其中codeC配置的NAL单元(SPS,PPS)与含codeD(部分)帧NAL单元混合。在这种情况下,我应该通过标记 BUFFER_FLAG_ codeC_CONFIG queueInputBuffers()的调用

还可以有其他(附加)NAL单元的mp4样品中,像SEI或分隔符NAL单元存取单元。对于那些?没问题?

There can also be other (additional) NAL units in mp4 samples, like SEI or access unit delimiter NAL units. What about those? No problem?

我试过各种不同的可能性,但所有的反馈,我从安卓明白的是,的通话dequeueOutputBuffer()超时(或不返回,如果我通 1 为超时参数)。这样一来,我似乎没有办法来解决这个问题。

I tried different kinds of possibilities, but all the feedback i get from Android is that the calls of dequeueOutputBuffer() time out (or don't return, if i pass -1 as timeout parameter). As a result, i don't seem have a way to troubleshoot this issue.

任何意见,做什么或去哪里找,当然是非常欢迎的好。

Any advice what to do or where to look is of course very welcome as well.

推荐答案

该NAL长度prefixes指定NAL单元长度需要转换附件-B开始codeS(字节为0x00,0x00时,为0x00 ,0x01)的前传递给媒体codeC的解码。 (有些去codeRS实际上可能接受MP4格式的直线距离,但它不是太常见了。)

The NAL length prefixes that specify the NAL unit length need to be converted to Annex-B startcodes (bytes 0x00, 0x00, 0x00, 0x01) before passing to MediaCodec for decoding. (Some decoders might actually accept the MP4 format straight away, but it's not too common.)

的SPS / PPS存储在AVCC原子的文件中也需要被转换为使用附件-B的启动codeS。请注意,AVCC原子包含了一些其他的领域,你并不需要传递到去codeR。您可以通过SPS和PPS(他们每个人之前,启动codeS)装在一个缓冲区与BUFFER_FLAG_ codeC_CONFIG标志发送任何实际的框架之前设置,或通过他们(附件-B开始codeS)在MediaFormat用于配置去codeR(无论是在1的ByteBuffer与键CSD-0,或在两个单独的按键作为CSD-0和CSD-1)。

The SPS/PPS that is stored in the avcC atom in the file also needs to be converted to use Annex-B startcodes. Note that the avcC atom contains a few other fields that you don't need to pass on to the decoder. You can either pass the SPS and PPS packed in one buffer (with startcodes before each of them) with the BUFFER_FLAG_CODEC_CONFIG flag set before sending any actual frames, or pass them (with Annex-B startcodes) in the MediaFormat you use to configure the decoder (either in one ByteBuffer with the key "csd-0", or in two separate keys as "csd-0" and "csd-1").

如果您的文件已经得到了更多的SPS / PPS每一帧里面,你应该只能够通过他们作为框架的一部分,大部分德codeRS应该能够应付它(尤其是如果它是相同的SPS / PPS和以前一样,并没有配置更改)。

If your file has got more SPS/PPS inside each frame, you should just be able to pass them as part of the frame, and most decoders should be able to cope with it (especially if it's the same SPS/PPS as before and not a configuration change).

这样:通过属于一个样品在一个单一的缓冲区中的所有NAL单元,但改写启动codeS的所有NAL单元长度的头。而随着MP4文件,不正好有SPS / PPS流本身的内部工作,解析AVCC原子(我不知道哪种格式mp4parser返回本),并通过SPS和PPS与启动codeS到去codeR(通过MediaFormat为CSD-0或作为第一缓冲,以BUFFER_FLAG_ codeC_CONFIG集)。

Thus: Pass all NAL units belonging to one sample in one single buffer, but with all NAL unit length headers rewritten to startcodes. And to work with MP4 files that don't happen to have SPS/PPS inside the stream itself, parse the avcC atom (I don't know in which format mp4parser returns this) and pass the SPS and PPS with startcodes to the decoder (either via MediaFormat as "csd-0" or as the first buffer, with BUFFER_FLAG_CODEC_CONFIG set).

这篇关于德code MP4使用不MediaExtractor媒体codeC / H.264,预计访问单元格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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