H264: decode series of nal units with ffmpeg

前端 未结 2 549
渐次进展
渐次进展 2021-02-04 21:55

I tried to decode a series of nal units with ffmpeg (libavcodec) but I get a \"no frame\" error. I produced the nal units with the guideline at How does one encode a series of i

相关标签:
2条回答
  • 2021-02-04 22:27

    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;
    
    0 讨论(0)
  • 2021-02-04 22:29

    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.

    0 讨论(0)
提交回复
热议问题