如下代码:
#include <iostream>
extern "C"
{
#include "libavformat\avformat.h"
}
#pragma comment(lib,"avformat.lib")
#pragma comment(lib,"avutil.lib")
using namespace std;
int main()
{
cout << "test Demux ffmpeg.club" << endl;
//初始化封装库
av_register_all();
//初始化网络库,可以打开(rtsp,rtmp,http协议的流媒体视频:注意,rtmp得到所有主流的网络摄像机支持,rtsp一般在直播平台用的较多,http指网上站上存的一些视频,包括直播的数据也是http+flv协议支持的
avformat_network_init();
//解封转上下文:
AVFormatContext *ic = NULL;
char *path = "xuanya.mp4";
//参数设置
AVDictionary *opts = NULL;
//设置rtsp流以tcp协议打开
av_dict_set(&opts, "rtsp_transport", "tcp", 0);
//网络延时时间
av_dict_set(&opts, "max_delay", "500", 0); //在网络环境不是很好的时候设置网络延时时间比较好用
//打开文件
int re = avformat_open_input(&ic,path,0,&opts); //该函数的第一个参数,会将AVFormatContext的空间给他申请出来,并且在里面填入我们打开的信息内容;第二个参数p