C++配置ffmpeg
可以從這個地址下載ffmpeg開發庫https://www.gyan.dev/ffmpeg/builds/
下載完成后的配置情況與配置SDL是類似的。參考https://www.cnblogs.com/zzr-stdio/p/14514043.html
注意:從這里下載的ffmpeg是64位版本的
打開視頻文件示例:
#include <iostream>
extern "C" {
#include<libavcodec/avcodec.h>
#include<libavformat/avformat.h>
#include<libavutil/avutil.h>
#include<libavutil/opt.h>
}
#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "avutil.lib")
using namespace std;
int main()
{
AVFormatContext* pFormat = nullptr;
string path(R"(11.mp4)");
int ret = avformat_open_input(&pFormat, path.c_str(), nullptr, nullptr);//打開視頻文件
if (ret)
{
cout << "avformat_open_input failed" << endl;
return -1;
}
ret = avformat_find_stream_info(pFormat, nullptr);//查詢視頻流信息
if (ret)
{
cout << "avformat_open_input failed" << endl;
return -1;
}
av_dump_format(pFormat, 0, nullptr, 0);//在控制台中打印該視頻文件的信息。
getchar();
}
打開直播流示例:
#include <iostream>
extern "C" {
#include<libavcodec/avcodec.h>
#include<libavformat/avformat.h>
#include<libavutil/avutil.h>
#include<libavutil/opt.h>
}
#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "avutil.lib")
using namespace std;
int main()
{
AVFormatContext* pFormat = nullptr;
string path(R"(http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8)");
AVDictionary* opt = nullptr;
av_dict_set(&opt, "rtsp_transport", "tcp", 0);
av_dict_set(&opt, "rtsp_delay", "550", 0);
int ret = avformat_open_input(&pFormat, path.c_str(), nullptr, &opt);//打開網絡直播地址
if (ret)
{
cout << "avformat_open_input failed" << endl;
return -1;
}
ret = avformat_find_stream_info(pFormat, nullptr);//查詢視頻流信息
if (ret)
{
cout << "avformat_open_input failed" << endl;
return -1;
}
av_dump_format(pFormat, 0, nullptr, 0);//在控制台中打印該視頻文件的信息。
getchar();
}