首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从UDP组播RTSP视频流读取

从UDP组播RTSP视频流读取
EN

Stack Overflow用户
提问于 2012-04-24 22:38:55
回答 1查看 7.6K关注 0票数 1

我目前正在开发一个需要解码UDP多播RTSP流的应用程序。目前,我可以使用ffplay via查看RTP流

代码语言:javascript
复制
ffplay -rtsp_transport udp_multicast rtsp://streamURLGoesHere

但是,我正在尝试使用FFMPEG通过打开UDP流(为了简洁,删除了错误检查和清理代码)。

代码语言:javascript
复制
AVFormatContext* ctxt = NULL;
av_open_input_file(
    &ctxt,
    urlString,
    NULL,
    0,
    NULL
);

av_find_stream_info(ctxt);

AVCodecContext* codecCtxt;

int videoStreamIdx = -1;
for (int i = 0; i < ctxt->nb_streams; i++)
{
    if (ctxt->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
    {
        videoStreamIdx = i;
        break;
    }
}

AVCodecContext* codecCtxt = ctxt->streams[videoStreamIdx]->codec;
AVCodec* codec = avcodec_fine_decoder(codecCtxt->codec_id);
avcodec_open(codecCtxt, codec);

AVPacket packet;
while(av_read_frame(ctxt, &packet) >= 0)
{
    if (packet.stream_index == videoStreamIdx)
    {
        /// Decoding performed here
        ...
    }
}

...

此方法适用于由原始编码视频流组成的文件输入,但对于UDP多播RTSP流,它无法通过在av_open_input_file()上执行的任何错误检查。敬请指教...

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-25 03:55:42

事实证明,打开组播UDP RTSP流可以通过以下方式执行:

代码语言:javascript
复制
AVFormatContext* ctxt = avformat_alloc_context();

AVDictionary* options = NULL;
av_dict_set(&options, "rtsp_transport", "udp_multicast", 0);
avformat_open_input(
    &ctxt,
    urlString,
    NULL,
    &options
);

...

avformat_free_context(ctxt);

以这种方式而不是av_open_input_file()使用avformat_open_input()会产生所需的行为。我猜测av_open_input_file()要么已被弃用,要么从未打算以这种方式使用--很可能是后者;)

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10300207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档