【FFmpeg 3.x API应用〇】基于VS2017的FFmpeg开发环境的搭建

本文介绍如何在Visual Studio 2017中配置FFmpeg开发环境,包括下载所需工具、设置工程属性及编译测试程序等步骤,并提供了一个简单的示例程序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

准备工作

在Windows平台上最强大的IDE非Visual Studio莫属了,虽然本人也非常喜欢并经常用Clion写一些小程序,鉴于VS的通用性还是选择使用VS来学习FFmpeg开发,可以使用免费的VS2017 Comminity社区版
然后要下载FFmpeg Windows平台的开发工具,可以点这里下载 Dev版本。
这里写图片描述
把下载下来的incldue和lib目录放到VS工程目录下。开发需要.h头文件和.lib静态库文件。

配置VS2017

打开工程属性页面(不是解决方案属性)
1. 【属性】 - 【C/C++】 - 【常规】 - 【附加包含目录】添加头文件目录../include;
2. 【属性】 - 【链接器】 - 【常规】 - 【附加库目录】添加静态库目录../lib;
3. 【属性】 - 【链接器】 - 【输入】 - 【附加依赖项】添加要使用的静态库文件,方便起见可以全部加上,avcodec.lib; avformat.lib; avutil.lib; swscale.lib; swresample.lib; postproc.lib; avfilter.lib; avdevice.lib;

英文版对应目录为:
- Properties - C/C++ - General - Additional Include Directories
../include;%(AdditionalIncludeDirectories)
- Properties - Linker - General - Additional Library Directories
../include;%(AdditionalIncludeDirectories)
- Properties - Linker - Input - Additional Dependencies
avcodec.lib;avformat.lib;avutil.lib;swscale.lib;swresample.lib;postproc.lib;avfilter.lib;avdevice.lib;%(AdditionalDependencies)

测试工程

新建main.cpp源文件,添加头文件应该使用extern "C" {}这种方式把#include包起来,注意main函数的参数int main(int argc, char *argv[])

main.cpp

extern "C" {
#include <libavformat/avformat.h>
};

int main(int argc, char *argv[])
{
    AVFormatContext *fmtCtx = NULL;

    char *inputFile = "../assets/Sample.mkv";

    // Register all components
    av_register_all();

    // Open an input stream and read the header.
    if (avformat_open_input(&fmtCtx, inputFile, NULL, NULL) < 0) {
        printf("Failed to open an input file");
        return -1;
    }

    // Read packets of a media file to get stream information.
    if (avformat_find_stream_info(fmtCtx, NULL) < 0) {
        printf("Failed to retrieve input stream information");
        return -1;
    }

    // Print detailed information about the input or output format 
    av_dump_format(fmtCtx, 0, 0, 0);

    avformat_close_input(&fmtCtx);

    return 0;
}

编译执行时会提示缺少相应的.dll动态库文件,直接去上面的网站下载Shared版本的dll文件放到程序执行目录就可以了。

具体工程可以参考: https://github.com/lmshao/FFmpeg-Basic

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值