VS2017 FFmpeg配置

首先需要去FFmpeg官网下载相应的内容:

下载地址为:https://ffmpeg.zeranoe.com/builds/,这里有三种类型的:static、shared、dev。

包含三个版本:Static、Shared以及Dev
Static   --- 包含3个应用程序:ffmpeg.exe , ffplay.exe , ffprobe.exe,体积都很大,相关的DLL已经被编译到exe里面去了。
Shared --- 除了ffmpeg.exe , ffplay.exe , ffprobe.exe之外还有一些DLL,exe体积很小,在运行时到相应的DLL中调用功能。
Dev      --- 开发者(developer)版本,里面包含了库文件xxx.lib以及头文件xxx.h,这个版本不含exe文件

从上面的类型说明中,可以知道,我们需要下载的是shared和dev两个文件

然后将这些文件拷贝到项目中,具体如下:

  1. 将shared的DLL文件拷贝到项目中。
  2. 将dev的include和lib文件夹一起拷贝到目录中。

添加附加包含目录指向拷贝的include文件,如下:

添加附加库目录,如下:

 添加附加依赖项,内容为

avcodec.lib; avformat.lib; avutil.lib; avdevice.lib; avfilter.lib;postproc.lib;swresample.lib; swscale.lib

至此,FFmpeg的开发环境配置完毕了。

验证

extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
}

int main()
{
    std::cout << "Hello World!\n"; 
	printf("%s\n", avcodec_configuration());
}

 

如果编译运行不报错,且输出如下的界面,则说明FFmpeg设置成功了:

补充

如果在运行代码的时候,IDE提示,***声明已被否决,这时可以通过以下几种方式来解决:

1. 修改项目的配置

Project Properties > Configuration Properties > C/C++ > General > SDL checks关掉

2. 代码中添加编译参数信息

#pragma warning(disable: 4996)    

但是这并不是一个好方法。出现这个的原因在于deprecated问题

'av_register_all': 被声明为已否决

其实就是av_register_all()这个方法在FFMPEG 4.0以后将不再推荐使用,而且是非必需的,因此直接注释掉即可。

avcodec_decode_video2() 

原本的解码函数被拆解为两个函数avcodec_send_packet()和avcodec_receive_frame() 具体用法如下:

   old:
   avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, pPacket);
   new:
   avcodec_send_packet(pCodecCtx, pPacket);
   avcodec_receive_frame(pCodecCtx, pFrame);

avcodec_encode_video2() 
对应的编码函数也被拆分为两个函数avcodec_send_frame()和avcodec_receive_packet() 具体用法如下:

   old:
   avcodec_encode_video2(pCodecCtx, pPacket, pFrame, &got_picture);
   new:
   avcodec_send_frame(pCodecCtx, pFrame);
   avcodec_receive_packet(pCodecCtx, pPacket);

avpicture_get_size() 
现在改为使用av_image_get_size() 具体用法如下:

   old:
   avpicture_get_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
   new:
   //最后一个参数align这里是置1的,具体看情况是否需要置1
   av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 1);

avpicture_fill() 
现在改为使用av_image_fill_arrays 具体用法如下:

   old:
   avpicture_fill((AVPicture *)pFrame, buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
   new:
   //最后一个参数align这里是置1的,具体看情况是否需要置1
   av_image_fill_arrays(pFrame->data, pFrame->linesize, buffer, AV_PIX_FMT_YUV420P,  pCodecCtx->width, pCodecCtx->height,1);
'AVStream::codec': 被声明为已否决:
pCodecCtx = pFormatCtx->streams[videoindex]->codec;
=>
pCodecCtx = avcodec_alloc_context3(NULL);
avcodec_parameters_to_context(pCodecCtx, pFormatCtx->streams[videoindex]->codecpar);

'av_free_packet': 被声明为已否决

av_free_packet()可被av_free_packet()替换

为使用VS2017FFmpeg,你可以按照以下步骤进行配置: 1. 首先,你需要从FFmpeg的官方网站下载FFmpeg的Windows版本。你可以在找到FFmpeg的官方网站,并点击Windows图标进行下载。 2. 下载完成后,解压缩文件并将解压后的文件夹重命名为"FFmpeg"。 3. 打开VS2017,创建一个新的C++项目。 4. 在项目中,右键单击"属性",然后选择"VC++目录"。 5. 在"包含目录"中添加FFmpeg文件夹的路径。 6. 在"库目录"中添加FFmpeg文件夹下的"lib"文件夹的路径。 7. 在"链接器"选项卡中的"输入"中,添加以下库文件引用:avcodec.lib、avformat.lib、avutil.lib、avdevice.lib、avfilter.lib、postproc.lib、swresample.lib、swscale.lib。你可以在找到这些库文件的引用。 8. 在代码中,你需要引用libavcodec库。你可以像下面这样在代码中添加引用: ``` #include <stdio.h> #include <iostream> extern "C" { #include <libavcodec/avcodec.h> } int main() { printf("%s", avcodec_configuration()); system("pause"); return 0; } ``` 9. 编译并运行代码,如果成功打印出FFmpeg配置信息,那么说明配置成功。 通过按照以上步骤进行配置,你就可以在VS2017中使用FFmpeg了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [vs2017+ffmpeg 环境搭建](https://blog.csdn.net/king_ink/article/details/115017961)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [VS2017+ FFmpeg+SDL 实现ts流解码播放](https://blog.csdn.net/qq_30727593/article/details/119786080)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值