H264: decode series of nal units with ffmpeg -


I tried to decode a series of tap units with ffmpeg (libavcodec) but I do not have "any frame" error Found I produced NAL units with guidelines. I tried the following strategy for decoding:

  avcodec_init (); Avcodecregister_all (); AVCodec * pCodec; PCodec = lpavcodec_find_decoder (CODEC_ID_H264); AVCodecContext * pCodecContext; PCodecContext = lpavcodec_alloc_context (); Avcodecopen (pCodecContext, pCodec); AVFrame * pFrame; PFrame = avcodec_alloc_frame (); // For each tap unit: int frame = 0; // nalData2 is the nodeadata without the first 4 bytes avcodec_decode_video (pCodecContext, pFrame, & FrameFinished, (uint8_t *) nalData2, nalLength);  

I passed all the units near this code, but the frame remains 0. I think there should be something wrong with the pCodecContext setup. Can anyone send me a work example?

Thanks

Look at this tutorial. It should be able to decode any video type, in which H.264:

I do not know what the problem is, but I suspect something to do with it The fact is that you are not using av_read_frame from libavformat to cross the equivalent of the frame of the data at one time. 264 has the ability to divide one frame into several slices and therefore there are several NAL units.

I'm pretty sure that the x264 encoder does not do this by default and produces one NAL unit per frame. However, NAL units are with other stream information, which should be fed to the decoder. I have experimented with this in the past and when the av_read_frame parses the data worth a frame, there are several NAL units in it, I suggest to follow the tutorial and if it works So see me

One more thing is that I think you need to pass the first 4 bytes of the NAL unit to avcodec_decode_video the start code is about which you are talking about ( 0x00000001 ). After checking the output from av_read_frame , the start code is still in the data when decoder is passed.


Comments