1. 程式人生 > 其它 >FFmpeg菜雞互啄#第2篇#配置VS開發環境

FFmpeg菜雞互啄#第2篇#配置VS開發環境

下載FFmpeg

首先是下載FFmpeg的win32庫,我用的版本是2.5.2(和其他2.x.x版本應該不會有太大差別)。FFmpeg的官網上好像已經找不到舊版本的下載了,可以在我的程式碼地址下載2.5.2版本。

建立工程

開啟Visual Studio 2013,建立一個空的控制檯專案。

配置FFmpeg目錄

在上面一步建立的工程目錄下,建立一個FFmpeg資料夾。FFmpeg資料夾下新建inc和lib目錄。把ffmpeg-2.5.2-win32-dev.7z壓縮包裡的include資料夾的所有內容複製到FFmpeginc目錄下,ffmpeg-2.5.2-win32-dev.7z壓縮包裡的lib資料夾的所有.lib檔案複製到FFmpeglib目錄下。

在專案屬性裡設定輸出路徑..bin。並在工程資料夾裡新建一個bin資料夾,把ffmpeg-2.5.2-win32-shared.7z壓縮包裡的bin資料夾的所有.dll檔案複製到bin目錄下。

附加包含目錄新增..FFmpeginc(從ffmpeg-2.5.2-win32-dev.7z裡複製include資料夾的路徑)。

附加庫目錄新增..FFmpeglib(從ffmpeg-2.5.2-win32-dev.7z裡複製lib資料夾的路徑)。

測試程式碼

向專案新增一個main.c原始檔,並輸入測試程式碼:

#include <stdio.h>

/*
#define __STDC_CONSTANT_MACROS
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif
*/

extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavdevice/avdevice.h"
}

#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avdevice.lib")
#pragma comment(lib, "avfilter.lib")
#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "avutil.lib")
#pragma comment(lib, "postproc.lib")
#pragma comment(lib, "swresample.lib")
#pragma comment(lib, "swscale.lib")

int main()
{
    //初始化FFMPEG  呼叫了這個才能正常適用編碼器和解碼器
    av_register_all();
    printf("FFmpeg's version is: %dn", avcodec_version());

    system("pause");
    return 0;
}

FFmpeg一共包含8個庫: ▫ avcodec:編解碼(最重要的庫)。 ▫ avformat:封裝格式處理。 ▫ avfilter:濾鏡特效處理。 ▫ avdevice:各種裝置的輸入輸出。 ▫ avutil:工具庫(大部分庫都需要這個庫的支援)。 ▫ postproc:後加工。 ▫ swresample:音訊取樣資料格式轉換。 ▫ swscale:視訊畫素資料格式轉換

#define __STDC_CONSTANT_MACROS
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif

之前遇到過在Qt或者VS2008裡要新增上面這個被註釋的巨集定義,但是在VS2013的話卻不需要。 測試結果:

github

https://github.com/gongluck/FFmpegTest.git