1. 程式人生 > >FFmpeg+vs2013開發環境配置(windows)

FFmpeg+vs2013開發環境配置(windows)

1、下載ffmpeg包(dll、include、lib)   https://ffmpeg.zeranoe.com/builds/

        有3個版本:Static、Shared和Dev

  • Static  --- 包含3個應用程式:ffmpeg.exe , ffplay.exe , ffprobe.exe,相關的DLL已經被編譯到exe裡了。
  • Shared---包含3個應用程式之外還包含一些DLL,exe體積很小,在執行時到相應的DLL中呼叫功能。
  • Dev     ---開發者(developer)版本,包含了庫檔案XXX.lib和標頭檔案XXX.h,不包含exe.

        開發者下載Shared(include、lib)和Dev(dll),依據自己電腦選擇相應的平臺下載,本文下載的是:

              

2、環境配置

2.1 新建工程

        

 2.2  將1中準備的dll、include、lib拷貝到2.1建立的tutorial02工程目錄下

           

2.3 右擊工程“屬性”

      

2.4 “c/c++”---->"附加包含目錄"---->新增2.2中拷貝到tutorial02工程目錄下的“include”路徑

          

2.5 “聯結器”---->"常規"---->“附加庫目錄”---->新增2.2中拷貝到tutorial02工程目錄下的“lib”路徑

         

2.6  “聯結器”---->"輸入"---->“附加依賴項“---->新增“avcodec.lib;avformat.lib;avutil.lib;avdevice.lib;avfilter.lib;postproc.lib;swresample.lib;swscale.lib;”

            

3、測試

       在ffmpeg-3.4.2-win64-dev\examples目錄下複製metagata.c原始碼到新建的tutorial02.cpp檔案中,這是一個獨立的demo,作用是列印音視訊媒體檔案基本資訊。

       注意!!!有些人下載的metadata.c裡面的標頭檔案如下左圖所示,需要修改為右圖所示

      (why? C++工程直接呼叫ffmpeg的c函式庫會導致c函式無法解析,用extern "C"進行宣告即可)

 

        ------------>        

 

      測試程式碼(metadata.c):

#ifndef INT64_C

#define INT64_C (c)  (c ## LL)

#define UINT64_C (c) (c ## ULL)

#endif

 

#include <stdio.h>

#include "stdafx.h"

#include <stdlib.h>

//#include <libavformat/avformat.h>

//#include <libavutil/dict.h>

 

extern "C"

{

#include <libavformat/avformat.h>

#include <libavutil/dict.h>

}

 

#pragma comment (lib, "avformat.lib")

#pragma comment (lib, "avutil.lib")

 

int main(int argc, char ** argv)

{

                 AVFormatContext *fmt_ctx = NULL ;

                 AVDictionaryEntry *tag = NULL ;

                 int ret;

 

                 if (argc != 2) {

                                printf( "usage: %s <input_file>\n"

                                                 "example program to demonstrate the use of the libavformat metadata API.\n"

                                                 "\n", argv [0]);

                                 return 1;

                }

 

                av_register_all();

                 if ((ret = avformat_open_input(&fmt_ctx, argv[1], NULL, NULL )))

                                 return ret;

 

                 while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX)))

                                printf( "%s=%s\n", tag->key, tag->value);

 

                avformat_close_input(&fmt_ctx);

                 return 0;

}

       執行結果:

        

 

4、出現的錯誤

4.1  編譯出現---error LNK2019: 無法解析的外部符號                                                                                                                                                                                            

    解決方法:

         1) ffmpeg的環境已經配置好(第2部分)

         2)配置管理器--平臺由Win32修改為x64(原因未知)參考 https://blog.csdn.net/ljh0302/article/details/50011587

        

4.2  執行程式,彈如下錯誤

         

     解決方法:將資料夾內的dll檔案拷貝到Debug資料夾內