音视频信息打印

1.av_register_all()

初始化所有的组件,只有调用了该函数,才能使用复用器和编解码器。

2.avformat_open_input()/avformat_close_input

打开一个多媒体文件。/ 释放一个文件资源

3.av_dump_format()

将文件中的信息打印出来

代码如下:

#include <libavutil/log.h>
#include <libavformat/avformat.h>

int main(int argc, char* argv[])
{
	AVFormatContext *fmt_ctx = NULL;

	int ret;

	av_log_set_level(AV_LOG_INFO);

	av_register_all();

	//打开test文件,第三个参数将文件格式设置为NULL,由FFmpeg自己进行检查,第四个参数为options
	ret = avformat_open_input(&fmt_ctx, "./test.mp4", NULL, NULL);

	//判断是否打印成功
	if(ret < 0){
		//打印具体的错误信息av_err2str(ret)试将错误码转换为字符串
		av_log(NULL, AV_LOG_ERROR, "can't open file: %s\n", av_err2str(ret));
		return -1;
	}

	//将多媒体文件的打印信息输出出来,第四个参数表明是输入流
	av_dump_format(fmt_ctx, 0, "./test.mp4", 0);

	//关闭多媒体文件
	avformat_close_input(&fmt_ctx);

	return 0;
}

下方是对应的指令,注意,那个不是引号,是1旁边那个波浪线的按钮(这玩意忙了我快两个小时)

然后随便找一个MP4后缀的文件(其实正规渠道很不好找),cp 成 test.mp4然后执行./mediainfo即可

扫描二维码关注公众号,回复: 11569910 查看本文章

结果如下图:

猜你喜欢

转载自blog.csdn.net/qq_37757236/article/details/107915641