
1、复制一个新文件,删除新建目录下两层DEBUG文件夹 ,删除新建目录下一层xxx.sln文件
2 、test.vcxproj改为新工程名字open.vcxproj
test.vcxproj.filters改为新工程名字open.vcxproj.filters
test.vcxproj.user删除
3、双击open.vcxproj
打开本地文件
#include<stdio.h>
extern "C" {
#include<libavcodec\avcodec.h>
#include <libavformat\avformat.h>
}
#pragma comment(lib,"avcodec.lib")
#pragma comment(lib,"avformat.lib")
int main()
{
printf("%s\n", avcodec_configuration());//验证工程有没有创建成功
av_register_all();//解码器注册
AVFormatContext* pFormat = NULL;//设备上下文
const char* path = "11.mp4";
int ret = avformat_open_input(&pFormat,path,NULL,NULL);//打开文件
if (ret)
{
printf("avformat_open_input failed\n");
return -1;
}
printf("avformat_open_input success\n");
ret = avformat_find_stream_info(pFormat,NULL);//寻找流信息
if (ret<0)
{
printf("avformat_find_stream_info failed\n");
return -1;
}
printf("avformat_find_stream_info success\n");
int time = pFormat->duration;//获取时长,单位us;
int mbittime = (time / 1000000) / 60;//得到多少分钟
int mmintime = (time / 1000000) % 60;//得到多少秒
printf("mbittime=%d分,mmintime=%d秒\n", mbittime, mmintime);
av_dump_format(pFormat,NULL,path,0);//显示文件信息
return 0;
}
打开网络文件
#include<stdio.h>
extern "C" {
#include<libavcodec\avcodec.h>
#include <libavformat\avformat.h>
#include<libavutil\opt.h>
}
#pragma comment(lib,"avcodec.lib")
#pragma comment(lib,"avformat.lib")
#pragma comment(lib,"avutil.lib")
int main()
{
printf("%s\n", avcodec_configuration());//验证工程有没有创建成功
av_register_all();//解码器注册
avformat_network_init();
AVFormatContext* pFormat = NULL;//设备上下文
//const char* path = "http://ivi.bupt.edu.cn/hls/cctvlhd.m3u8";
const char* path = "http://121.18.168.149/cache.ott.ystenlive.itv.cmvideo.cn:80/000000001000/5000000010000030951/index.m3u8?channel-";
AVDictionary* OPT=NULL;
av_dict_set(&OPT,"rtsp_transport","tcp",0);
av_dict_set(&OPT, "max_delay", "550", 0);
int ret = avformat_open_input(&pFormat,path,NULL, &OPT);//打开网络视频文件
if (ret)
{
printf("avformat_open_input failed\n");
return -1;
}
printf("avformat_open_input success\n");
// ret = avformat_find_stream_info(pFormat,NULL);//寻找流信息
//if (ret<0)
//{
// printf("avformat_find_stream_info failed\n");
// return -1;
//}
//printf("avformat_find_stream_info success\n");
int time = pFormat->duration;//获取时长,单位us;
int mbittime = (time / 1000000) / 60;//得到多少分钟
int mmintime = (time / 1000000) % 60;//得到多少秒
printf("mbittime=%d分,mmintime=%d秒\n", mbittime, mmintime);
av_dump_format(pFormat,NULL,path,0);//显示文件信息
return 0;
} 
版权声明:本文为qq_41962968原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。