avio_open(),是FFmepeg早期版本。avio_open()比avio_open2()少了最后2个参数。而它前面几个参数的含义和avio_open2()是一样的。从源代码中可以看出,avio_open()内部调用了avio_open2(),并且把avio_open2()的后2个参数设置成了NULL,因此它的功能实际上和avio_open2()都是用于打开FFmpeg的输入输出文件的。其avio_open()源代码如下:
int avio_open(AVIOContext **s, const char *filename, int flags)
{
return avio_open2(s, filename, flags, NULL, NULL);
}
测试代码:
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libswscale/swscale.h"
#include "libswresample/swresample.h"
int main(int argc, char * argv[] )
{
int ret;
char filename[64] = "test.ts";
AVFormatContext *oc = NULL;//封装格式的上下文结构体,是统领全局的结构体,保存了视频文件封装格式的相关信息
av_register_all();
avformat_alloc_output_context2(&oc, NULL, "mpegts", filename);
if (!oc) {
printf("\nCould not deduce output format from file extension.\n");
return -1;
}
ret = avio_open(&(oc->pb), filename, AVIO_FLAG_WRITE);
if (ret < 0) {
fprintf(stderr, "Could not open '%s' %d: %s\n", filename, ret, av_err2str(ret));
return -1;
}
......
}
问题:调用avio_open()函数,返回 :-1330794744,具体的错误描述是: Protocol not found。如图:
解决方法 1:在FFmepeg移植时,加入了 ./configure --disable-everything --enble....选项,可以把 --disable-everything 该选项去掉,在重新编译移植FFmepeg,FFmepeg就会把所有的 指定分析器 注册完成。不过编译出来的执行文件会相应的变大。
解决方法 2:在FFmepeg移植时,加入所需要 启用指定的分析器 的类型:./configure --enable-protocol=NAME , 在重新编译FFmepeg即可。(优点:后面编译的执行文件不会增大,缺点:你所需要的分析器要一个个尝试去添加:如:./configure --enable-protocol=file等,这里的 .ts 就是需要它,才不会返回负值)。
--enable-protocol=NAME,其中NAME的类型如下:
async ftp mmsh srtp
cache gopher mmst subfile
concat hls pipe tcp
crypto http prompeg tee
data httpproxy rtmp udp
ffrtmphttp icecast rtmpt udplite
file md5 rtp unix