C FFmpeg:协议不在白名单上';文件';!

C FFmpeg:协议不在白名单上';文件';!,c,ffmpeg,rtp,C,Ffmpeg,Rtp,我想从RTP流中读取,但当我将“test.sdp”指定为avformat\u open\u input()时,我收到以下消息: [rtp @ 03928900] Protocol not on whitelist 'file'! Failed: cannot open input. avformat_open_input() fail: Invalid data found when processing input 通常,如果我在控制台上使用ffplay,我会添加选项-protocol\u

我想从RTP流中读取,但当我将“test.sdp”指定为
avformat\u open\u input()
时,我收到以下消息:

[rtp @ 03928900] Protocol not on whitelist 'file'!
Failed: cannot open input.
avformat_open_input() fail: Invalid data found when processing input
通常,如果我在控制台上使用ffplay,我会添加选项
-protocol\u whitelist file、udp、rtp
,它会正常工作

所以我试了一下:

AVDictionary *d = NULL;           
av_dict_set(&d, "protocol_whitelist", "file, udp, rtp", 0); 
ret = avformat_open_input(&inFormatCtx, filename, NULL, &d);

但同样的信息仍然会弹出。有什么想法吗?

编辑:这个答案适用于某些版本。您应该使用avformat_open_input的options参数,如BOT11131357的回答中所述


我不完全确定这一点,但我相信这一选择会进入AVFormatContext

AVFormatContext* formatContext = avformat_alloc_context();
formatContext->protocol_whitelist = "file,udp,rtp";
if (avformat_open_input(&formatContext, uri.c_str(), NULL, NULL) != 0) {
    return EXIT_FAILURE;
}
查看此更改的cvs日志: 这太尴尬了

avformat\u open\u输入失败,因为我有空格。删除空白现在可以工作了

av_dict_set(&d, "protocol_whitelist", "file,udp,rtp", 0); 

谢谢你的帮助!你的方法也奏效了。然而,源代码对protocol_白名单有这样的描述:由用户通过AVOptions(无直接访问)设置,所以我决定现在使用字典方法。这实际上对我不起作用。。。这是你唯一的改变吗?是的。如果查看调试,
inFormatCtx->protocol\u白名单
设置为“file,udp,rtp”。你能解释一下它是如何对你不起作用的吗?当我在字典中设置协议白名单时,我仍然得到了
协议不在白名单上的错误。可能是版本问题?无论如何-它现在对我们两个都有效,所以一切都很好:)我使用的是ffmpeg-20160219-git-98a0053-win32-dev(Zeranoe构建)。您是否正确设置了AVDictionary指针?也许您可以在设置后检查该值?我想FFmpeg的一个挑战是没有关于这些东西的官方指南……太好了。希望在后续版本中保持这种状态。:-)