使用ffmpeg和分隔的AVCodecContext解码h264 rtsp

mmm*_*aak 6 c++ ffmpeg rtsp h.264

我需要一些有关decodein rtsp视频流的帮助.我从AXIS IP-camera那里得到它.我使用ffmpeg库.有必要单独创建AVCodecContext,而不是AVFormatContext-> streams [...] - > codec;

所以我创建AVCodec,AVCOdecContext并尝试初始化它们.

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);
Run Code Online (Sandbox Code Playgroud)

然后在应用程序的主循环中,我获取帧数据并尝试解码:

_preallocatedFrame = avcodec_alloc_frame();
avcodec_decode_video2(_context, _preallocatedFrame, &got_picture, &_packet);
Run Code Online (Sandbox Code Playgroud)

在这里,我在控制台中收到了很多消息:

[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!
Run Code Online (Sandbox Code Playgroud)

你能告诉我一些事情,如何初始化AVCodecContext或其他什么来正确吗?

小智 4

您需要执行更多工作。如果您想解码 h.264 流,您需要向解码器传递“sps pps”数据。这个数据可以在rtp流本身上找到

或者在 SDP 中的 rtsp 协商中。成功向解码器提供此数据后,解码应该可以工作。