需要的文件:
(inttypes.h,stdin.h爲C99標準定義了stdint.h、inttypes.h,用於統一的跨平臺數據定義。VC2010有stdint.h,沒有inttypes.h,inttypes.h可以到這裏下載
http://code.google.com/p/msinttypes/)
1.新建工程,打開屬性管理器,這裏只配置Debug(Release配置方法相同),雙擊打開Microsoft.cpp.win32.user
選擇"VC++目錄","包含目錄"填入ffmpeg頭文件目錄,"庫目錄"填入ffmpeg的lib所在目錄
2.點擊"鏈接器"->"輸入"在附加依賴項中加入要鏈接的庫
(也可以在代碼中鏈接庫
#pragma comment(lib,"avcodec.lib")
#pragma comment(lib,"avformat.lib")
#pragma comment(lib,"avutil.lib")
#pragma comment(lib,"swscale.lib")
}
3.編寫代碼
可能出現的錯誤
error LNK2019: 無法解析的外部符號 "void __cdecl av_register_all(void)" (?av_register_all@@YAXXZ),該符號在函數 _main 中被引用
.....
.....
.....
原因:老版本的ffmpeg頭文件中有
#ifdef __cplusplus
extern "C"{
....
}
....
#endif
#ifdef __cplusplus
}
#endif
所以在編譯時能夠正確的以C語言的方式進行編譯和鏈接
新版本的頭文件中沒有上面宏編譯,所以需要自己在代碼中以C的方式包含頭文件
#ifdef __cplusplus
extern "C" {
#endif
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libutil/avutil.h>
#ifdef __cplusplus
}
#endif