Decode h264 rtsp with ffmpeg and separated AVCodecContext

我是研究僧i 提交于 2019-12-07 02:10:47

问题


I need some help with decodein rtsp stream of video. I get it from AXIS IP-camera. I use ffmpeg library for it. It is neccessary to create AVCodecContext separately, not from AVFormatContext->streams[...]->codec;

So i create AVCodec, AVCOdecContext and try to init 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 main loop of application, i get frames data and try to decode:

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

And here I get lots of messages in 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 advice me something, how to init AVCodecContext or something else to do it correct?


回答1:


You need to perform some more work. if you want to decode h.264 stream you need to pass the decoder the "sps pps" data. This data can be found on the rtp stream itself see

or in th rtsp negotiation in the SDP. after you successfully feed the decoder with this data, the decoding should work.



来源:https://stackoverflow.com/questions/11261551/decode-h264-rtsp-with-ffmpeg-and-separated-avcodeccontext

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!