C++配置ffmpeg

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();
}
原文地址:https://www.cnblogs.com/zzr-stdio/p/14526982.html