VS2013+ffmpeg開發環境搭建
一、准備ffmpeg相對應開發dll、include、lib
- 官網ffmpeg下載鏈接:https://ffmpeg.zeranoe.com/builds/
包含三個版本:Static、Shared以及Dev
- Static — 包含3個應用程序:ffmpeg.exe , ffplay.exe , ffprobe.exe,體積都很大,相關的DLL已經被編譯到exe里面去了。
- Shared — 除了ffmpeg.exe , ffplay.exe , ffprobe.exe之外還有一些DLL,exe體積很小,在運行時到相應的DLL中調用功能。
- Dev — 開發者(developer)版本,里面包含了庫文件xxx.lib以及頭文件xxx.h,這個版本不含exe文件
二、開發者版本配置相關環境
1.新建工程
2.把一中ffmpeg准備的dll、include、lib拷貝到工程目錄下
3.右擊工程“屬性”
4.“C/C++”——>“附加包含目錄”——>添加3中拷貝到工程“include”文件
注意:平台會默認選擇win32,我們下載的是Windows 64-bit的ffmpeg,因此要把平台改成活動(x64)!
5.“鏈接器”——>“常規”——>附加庫目錄”——>添加3中拷貝到工程“lib”文件
6.“鏈接器”——>“輸入”——>附加依賴項”——>添加“avcodec.lib;avformat.lib;avutil.lib;avdevice.lib;avfilter.lib;postproc.lib;swresample.lib;swscale.lib;”
7.將文件夾內的dll文件拷貝到ffavmuxer里
8.測試
#include "stdafx.h"
#include <stdio.h>
#include"stdlib.h"
//#include <rational.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;
//}
if ((ret = avformat_open_input(&fmt_ctx, "la.mp3", 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;
}
運行成功!環境配置完成!如果還有其他問題,請留言。