音视频开发(二)FFmpeg调用avio_open返回Protocol not found的追踪

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_

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值