8

I'm trying to figure out how to use Android's MediaCodec class to decode H.264 video. To start, I'm trying to manually parse the NAL units out of an H.264 file and feed them to MediaCodec for decoding. I believe I'm parsing the NAL units out of the file correctly (searching for 0x00 0x00 0x01 sequence in file, indicates the start of a NAL unit), but MediaCodec always times out and returns -1 each time I make a call to dequeueOutputBuffer(). Does anyone know the specifics of how to feed H.264 NAL units to MediaCodec for decoding? Am I supposed to strip off the 0x00 0x00 0x01 sequence before I send it a NAL unit? Do I need to ignore/drop certain NAL unit types? Do I need to prepend the extracted SPS and PPS info (with or without the 0x00 0x00 0x01 sequence) before each NAL unit? I'm playing around with a lot of ideas here and none of them are panning out. Any guidance in this realm would be very much appreciated.

4

2 回答 2

4

就我所经历的而言,只要您不向解码器提供 sps/pps 信息,解码器就会在 dequeueOutputBuffer() 上返回 -1。当你这样做时,解码器应该在 dequeueOutputBuffer() 上返回 INFO_OUTPUT_FORMAT_CHANGED 标志 (-2),之后将正确返回解码的帧。

如果解码器仍然返回 -1,请尝试使用标志 BUFFER_FLAG_CODEC_CONFIG 将 sps/pps 信息添加到解码器。

于 2013-07-26T10:26:45.267 回答
0

AFAIK 您需要取出标头并将 SPS/PSS 作为第一个缓冲区提供给它,但是获得 -1 并不是什么大问题,这将是一种正常的行为。如果在其他 NAL 之前没有由 SPS/PPS 馈送某些设备,它们将会崩溃

于 2014-07-30T08:20:12.630 回答