Decoding h264 rtsp with ffmpeg and splitting AVCodecContext

I need help with decodein rtsp video stream. I get it from an AXIS IP camera. For this, I use the ffmpeg library. It is necessary to create AVCodecContext separately, and not from AVFormatContext-> streams [...] → codec;

So, I am creating AVCodec, AVCOdecContext and trying to initialize them.

AVCodec *codec=avcodec_find_decoder(codec_id); if(!codec) { qDebug()<<"FFMPEG failed to create codec"<<codec_id; return false; //--> } AVCodecContext *context=avcodec_alloc_context3(codec); if(!context) { qDebug()<<"FFMPEG failed to allocate codec context"; return false; //--> } avcodec_open2(context, codec, NULL); 

Then in the main loop of the application, I get the frame data and try to decode:

 _preallocatedFrame = avcodec_alloc_frame(); avcodec_decode_video2(_context, _preallocatedFrame, &got_picture, &_packet); 

And here I get a lot of messages in the console:

 [h264 @ 1f177720] decode_slice_header error [h264 @ 1f177720] no frame! [h264 @ 1f177720] non-existing PPS 0 referenced [h264 @ 1f177720] decode_slice_header error [h264 @ 1f177720] no frame! [h264 @ 1f177720] non-existing PPS 0 referenced [h264 @ 1f177720] decode_slice_header error [h264 @ 1f177720] no frame! [h264 @ 1f177720] non-existing PPS 0 referenced [h264 @ 1f177720] decode_slice_header error [h264 @ 1f177720] no frame! [h264 @ 1f177720] non-existing PPS 0 referenced [h264 @ 1f177720] decode_slice_header error [h264 @ 1f177720] no frame! [h264 @ 1f177720] non-existing PPS 0 referenced [h264 @ 1f177720] decode_slice_header error [h264 @ 1f177720] no frame! 

Can you advise me something on how to run AVCodecContext or something else to do it right?

+6
source share
1 answer

You need to do one more job. if you want to decode the h.264 stream, you need to pass the "sps pps" data to the decoder. This data can be found in the rtp stream itself .

or in rtsp negotiations in SDP. after the decoder successfully feeds this data, decoding should work.

+4
source

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


All Articles