流程示意图
程序代码
#include <iostream>
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avformat.lib")
using namespace std;
int main()
{
//注册
av_register_all();
//上下文
AVFormatContext* pFormat = NULL;
const char* path = "aa.mp4";
//打开本地文件
int ret = avformat_open_input(&pFormat, path, NULL, NULL);
if (ret < 0)
{
cout << "avformat_open_input error:" << ret;
return -1;
}
//查找流信息
ret = avformat_find_stream_info(pFormat, NULL);
if (ret < 0)
{
cout << "avformat_find_stream_info error:" << ret;
return -1;
}
int time = pFormat->duration;
int second = time / 1000000;
cout << "second=" << second << endl;
//获取详细信息
av_dump_format(pFormat, NULL, path, 0);
system("pause");
return 0;
}
运行结果: