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文件夾內
   
5、參考資料
    1      https://ffmpeg.zeranoe.com/builds/   
            https://www.cnblogs.com/bhlsheji/p/5359390.html
    4.1   https://blog.csdn.net/ljh0302/article/details/50011587

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM