解码h264 rtsp与ffmpeg和分离的AVCodecContext [英] Decode h264 rtsp with ffmpeg and separated AVCodecContext

查看:1524
本文介绍了解码h264 rtsp与ffmpeg和分离的AVCodecContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助decodein rtsp视频流。
我从AXIS IP摄像头。我使用ffmpeg库。
必须单独创建AVCodecContext,而不是从AVFormatContext-> streams [...] - >编解码器;

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;

所以我创建AVCodec,AVCOdecContext,以启动它们。

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!

你能建议我一些,如何初始化AVCodecContext或其他东西做正确吗?

Can you advice me something, how to init AVCodecContext or something else to do it correct?

推荐答案

您需要执行一些更多的工作。
如果你想解码h.264流,你需要通过解码器的sps pps数据。
此数据可以在rtp流本身上找到请参阅

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

或在SDP中的rtsp协商。
在您成功地给解码器提供此数据后,解码应该工作。

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

这篇关于解码h264 rtsp与ffmpeg和分离的AVCodecContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆