1、在src目录下新建TestDemux目录
2、 在TestDemux下编写测试程序
main.cpp
#include <iostream>
extern "C"{
#include "libavformat/avformat.h"
}
using namespace std;
#pragma comment(lib,"avformat.lib")
#pragma comment(lib,"avutil.lib")
int main(int argc, char *argv[])
{
cout << "Test Demux FFmpeg.club" << endl;
const char *path = "001111.mp4";
//初始化封装库
av_register_all();
//初始化网络库 (可以打开rtsp rtmp http 协议的流媒体视频)
avformat_network_init();
//参数设置
AVDictionary *opts = NULL;
//设置rtsp流已tcp协议打开
av_dict_set(&opts, "rtsp_transport", "tcp", 0);
//网络延时时间
av_dict_set(&opts, "max_delay", "500", 0);
//解封装上下文
AVFormatContext *ic = NULL;
int re = avformat_open_input(
&ic,
path,
0, // 0表示自动选择解封器
&opts //参数设置,比如rtsp的延时时间
);
cout <<re << endl;
if (re != 0)
{
char buf[1024] = { 0 };
av_strerror(re, buf, sizeof(buf) - 1);
cout << "open " << path << " failed! :" << buf << endl;
getchar();
return -1;
}
cout << "open " << path << " success! " << endl;
getchar();
return 0;
}
TestDemux.pro
TEMPLATE = app
CONFIG += console c++11
SOURCES += main.cpp
INCLUDEPATH += $$PWD/../../include
#区分32位和64位windows程序
opt = $$find(QMAKESPEC,"msvc2017_64")
isEmpty(opt){
message("win32 lib")
LIBS += -L$$PWD/../../lib/win32
}
!isEmpty(opt){
message("win64 lib")
LIBS += -L$$PWD/../../lib/win64
}
#message($$QMAKESPEC)