ffmpeg 常用api 一

1 avformat_open_input

作用:打开媒体文件并获取媒体文件信息,可以是本地文件,也可以时网络流。

函数原型:

int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options);

ps:输入文件的AVFormatContext,会将获取的信息填充进去;

url:流地址,可以是本地文件、RTMP、RTP协议流地址;

fmt:一般为NULL,表示自动检测流格式,否则会使用提供的值作为流格式;

options:一般为NULL;

返回值:0表示成功,负值表示失败。

注意:需要调用avformat_close_input关闭AVFormatContext。

2 avformat_find_stream_info

作用:读取音视频包来获取流信息,常用于avformat_open_input函数之后。像flv这种头很简单的格式,从头中只知道是否存在音视频流,但不知道流的编解码信息,该函数会去读音视频包来获取流的编解码信息。

函数原型:

int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);

ic:输入文件的AVFormatContext;

options:用户自定义选项,一般为NULL;

返回值:>= 0表示成功。

3 av_dump_format

作用:用于将AVFormatContext中媒体格式的信息进行格式化输出。

函数原型:

void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output);

ic:输入文件的AVFormatContext;

index:输出音视频流的索引,-1表示输出所有音视频流信息;

url:媒体流地址;

is_output:0表示输入上下文,1表示输出上下文;

4 avformat_alloc_output_context2

作用:初始化一个用于输出的AVFormatContext结构体,需要调用avformat_free_context进行释放。

函数原型:

int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat, const char *format_name, const char *filename);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值