H264: nal unit decoding series with ffmpeg

I tried to decode a series of nal units with ffmpeg (libavcodec), but I get a "no frame" error. I developed nal units with the directive How to encode a series of images in H264 using the x264 C API? . I tried the following strategy for decoding:

avcodec_init();  
avcodec_register_all();  
AVCodec* pCodec;  
pCodec=lpavcodec_find_decoder(CODEC_ID_H264);  
AVCodecContext* pCodecContext;  
pCodecContext=lpavcodec_alloc_context();  
avcodec_open(pCodecContext,pCodec);  
AVFrame *pFrame;  
pFrame=avcodec_alloc_frame();
//for every nal unit:    
    int frameFinished=0;  
    //nalData2 is nalData without the first 4 bytes
    avcodec_decode_video(pCodecContext,pFrame,&frameFinished,(uint8_t*) nalData2,nalLength);

I passed all the units that I got into this code, but frameFinished remains 0. I am assuming there should be something wrong with the pCodecContext setting. Can someone send me a working example?

thank

+3
source share
2 answers

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

http://dranger.com/ffmpeg/

, , , , av_read_frame libavformat . H.264 , , NAL.

, x264 NAL . NAL , . , av_read_frame , NAL. , .

, , 4 NAL avcodec_decode_video, , (0x00000001). av_read_frame, .

+3

:

  if(pCodec->capabilities & CODEC_CAP_TRUNCATED)
      pCodecContext->flags |= CODEC_FLAG_TRUNCATED; /* We may send incomplete frames */
  if(pCodec->capabilities & CODEC_FLAG2_CHUNKS)
      pCodecContext->flags |= CODEC_FLAG2_CHUNKS;
0

Source: https://habr.com/ru/post/1755419/


All Articles