Protocol not found
近日,在C++中使用FFmpeg把一些本地的视频文件,推送到远程RTSP服务器的时候,使用了如下这个过程:
- avformat_alloc_output_context2() 申请上下文
- avcodec_find_encoder 找到编码器
- avcodec_alloc_context3 通过找到的编码器,申请编码器上下文,设置编码器上下文
- avcodec_open2 打开编码器
- avformat_new_stream 新建媒体流,设置媒体流
- avio_open 打开推送媒体的网络IO
- avformat_write_header 写入媒体头
- av_interleaved_frame …… 依次写入视频帧
前面的过程都一切正常,但是到了上面倒数第二步,即avio_open的时候,怎是失败,错误信息是:Protocol not found。
FFmpeg源代码
网络上已有的信息,有的说是版本问题,有的说是因为相关协议没有注册,但是都不解决问题。
于是,从FFmpeg的地址上,克隆了一份源代码,读了一下,发现了问题根源。
我们以这个版本为准,这个版本提交信息为:
commit 9d15fe77e33b757c75a4186fa049857462737713
Author: James Almer <jamrial@gmail.com>
Date: Wed Aug 21 15:12:46 2024 -0300
avcodec/container_fifo: add missing stddef.h include
Fixes make checkheaders
Signed-off-by: James Almer <jamrial@gmail.com>
提交于2024年8月21日。
我们在源代码根目录下的libavformat目录中的avio.c中的第497行,找到avio_open,发现它的定义为:
int avio_open(AVIOContext **s, const char *filename, int flags)
{
return avio_open2(s, filename, flags, NULL, NULL);
}
而avio_open2的定义为:
int avio_open2(AVIOContext **s, const char *filename, int flags,
const AVIOInterruptCB *int_cb, AVDictionary **options)
{
return ffio_open_whitelist(s, filename, flags, int_cb, options, NULL, NULL);
}
即,avio_open的定义实际上为ffio_open_whitelist。
而avio.c的471行就是ffio_