ffmpeg:avformat_open_input

avformat_open_input() 是一个函数,通常用于打开输入媒体流并读取其头部信息。具体位于 libavformat 组件中。

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

参数说明:
AVFormatContext **ps:这是一个指向 AVFormatContext 结构体的指针的指针。成功调用此函数后,AVFormatContext 结构体将被分配并填充有关媒体流的信息。
const char *url:要打开的媒体文件的 URL 或路径。这可以是本地文件路径、HTTP URL 或其他支持的协议。
AVInputFormat *fmt:指定输入格式的 AVInputFormat 结构体的指针。如果此参数为 NULL,则函数将根据文件扩展名或内容自动检测输入格式。
AVDictionary **options:一个指向 AVDictionary 结构体的指针的指针,用于传递打开媒体文件时的选项。这些选项可以控制打开文件或网络流时的各种行为。

返回值:
如果成功打开流并读取了头部信息,函数将返回 0。
如果出现错误,将返回一个负的错误码。

使用 avformat_open_input() 之后,通常需要使用 avformat_close_input() 函数来释放 AVFormatContext 及其相关资源。

例子:

extern "C"
{
    //编码库
	#include <libavcodec/avcodec.h>
    //封装格式库
	#include <libavformat/avformat.h>
    //解码库
    #include <libswscale/swscale.h>
    //各种设备的输入输出
    #include <libavdevice/avdevice.h>
    //多媒体处理库 工具库
	#include <libavutil/opt.h>
}
int main()
{
	const char* path  = "xx.mp4";
	AVDictionary* opt=NULL;
    AVFormatContext* pFormat = NULL;
	int ret  = avformat_open_input(&pFormat,path,NULL,NULL);
    printf("ret: %d",ret);
	if (ret)
	{
		printf(" avformat_open_input failed\n");
		return -1;
	}
	printf(" avformat_open_input success\n");
	return 0;
}
  • 8
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值