H264: decode series of nal units with ffmpeg

﹥>﹥吖頭↗ 提交于 2019-12-03 00:49:21

Check out this tutorial. It should be able to decode any video type including H.264:

http://dranger.com/ffmpeg/

I don't know exactly what is causing the problem, but I suspect it has something to do with the fact that you are not using the av_read_frame from libavformat to parse out a frames worth of data at a time. H.264 has the ability to split a frame into multiple slices and therefore multiple NAL units.

I am pretty sure the x264 encoder does not do this by default and produces one NAL unit per frame. However, there are NAL units with other stream information that need to be fed to the decoder. I have experimented with this in the past and when av_read_frame parses out a frames worth of data, it sometimes contains multiple NAL units. I would suggest following the tutorial closely and seeing if that works.

Another thing is that I think you do need to pass the first 4 bytes of the NAL unit into avcodec_decode_video if that is the start code you are talking about (0x00000001). Having investigated the output from av_read_frame, the start codes are still in the data when passed to the decoder.

Vladvic

Try this after the codec context instantiation code:

  if(pCodec->capabilities & CODEC_CAP_TRUNCATED)
      pCodecContext->flags |= CODEC_FLAG_TRUNCATED; /* We may send incomplete frames */
  if(pCodec->capabilities & CODEC_FLAG2_CHUNKS)
      pCodecContext->flags2 |= CODEC_FLAG2_CHUNKS;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!