1. 程式人生 > 其它 >Visual Studio2019整合ffmpeg之hello world

Visual Studio2019整合ffmpeg之hello world

title: 音視訊系列二:Visual Studio2019整合ffmpeg之hello world
categories:[ffmpeg]
tags:[音視訊程式設計]
date: 2021/11/25

作者:hackett 微信公眾號:加班猿

一、下載安裝Visual Studio

下載地址為:https://visualstudio.microsoft.com/zh-hans/downloads/

然後進行安裝,安裝時選擇C/C++開發的選項進行安裝,安裝時選擇如下:

選好就,點選下一步,等待安裝就OK了。

二、下載ffmpeg開發包

GitHub下載地址:https://github.com/BtbN/FFmpeg-Builds/releases

下載最新的帶share版本的,就是已經編譯好了的,不用自己再編譯 ffmpeg-n4.4.1-2-gcc33e73618-win64-gpl-shared-4.4.zip

├─bin #可執行程式
├─doc #參考文件
├─include #標頭檔案目錄
│  ├─libavcodec
│  ├─libavdevice
│  ├─libavfilter
│  ├─libavformat
│  ├─libavutil
│  ├─libpostproc
│  ├─libswresample
│  └─libswscale
├─lib #連結庫檔案
└─presets

三、建立專案目錄

├─bin     #程式執行和除錯目錄
├─include #標頭檔案目錄
├─lib     #動態連結庫目錄
└─src     #原始碼目錄

四、開啟Visual Studio 2019建立專案

將專案建立到src目錄下面

檔案->新建->專案 選擇C++空專案

專案位置選擇到src,然後建立專案。注意:將專案解決方案和專案放在同一目錄中前面的勾要選上,不然預設會多建立一層目錄

五、開發環境配置

選中專案右鍵選擇屬性:

  1. C/C++->常規->附件包含目錄 【$(ProjectDir)....\include】

  2. 連結器->常規->附加庫目錄 【$(ProjectDir)....\lib】

  3. 連結器->輸入->附加依賴項

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

  4. 專案->配置管理器選擇x64

六、建立hello world程式

#include<iostream>
using namespace std;

extern "C" {//包含C標頭檔案
#include "libavutil/log.h" 
#include "libavcodec/avcodec.h"
#include "libavfilter/avfilter.h"
#include "libavformat/avformat.h" 
#include "libavutil/avutil.h"
#include "libavutil/ffversion.h"
#include "libswresample/swresample.h"
#include "libswscale/swscale.h"
#include "libpostproc/postprocess.h"
};

int main(int argc, char* argv[]) {

	av_log_set_level(AV_LOG_DEBUG); //設定日誌級別
	av_log(NULL, AV_LOG_DEBUG, "hello world log\n"); //列印日誌

	unsigned int codecVer = avcodec_version();
	int ver_major, ver_minor, ver_micro;
	ver_major = (codecVer >> 16) & 0xff;
	ver_minor = (codecVer >> 8) & 0xff;
	ver_micro = (codecVer) & 0xff;
	printf("Current ffmpeg version is: %s ,avcodec version is: %d=%d.%d.%d\n", FFMPEG_VERSION, codecVer, ver_major, ver_minor, ver_micro);

	system("pause"); //視窗等待
	return 0;
}

執行結果:

補充:

如果在執行程式碼的時候,IDE提示,***宣告已被否決,這時可以通過修改專案的配置方式來解決:

  1. C/C++ ->常規-> SDL檢查關掉

  2. C/C++ ->程式碼生成-> 多執行緒除錯(/MTD)

如果你覺得文章還不錯,可以給個"三連"

我是加班猿,我們下期見