编译了两天的MinGW下的ffmpeg,找了一下常见的老文章照着做,各种错误都需要解决。挺花时间的。
其实可以直接使用官方网站上下载已经编译好的文件。从http://ffmpeg.org/download.html进去,可以看到有static,shared,dev三个版本。static是直接可运行的exe,适合直接运行或命令行运行。我们主要用到shared和dev版本。dev版本就是windows下已经编译好的lib和头文件(不需要我们花精力去编译啦,特殊要求除外)。运行的时候需要shared版本,里面包含需要的dll。
下载shared版和dev版后,解压,添加dev版的inlude和lib目录到VC里面。可以用“View” -> “Property Manager”方式。
然后,下载vc2010里缺的头文件http://msinttypes.googlecode.com/files/msinttypes-r26.zip,对于VS2010来说通常是:C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include。VC里面已经有stdint的就不用替换,替换了反而编译错误。参考http://www.cnblogs.com/Jerry-Chou/archive/2011/03/31/2000761.html。
最后,源代码中包含相应头文件和lib
#ifdef __cplusplus
extern "C" {
#endif
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#ifdef __cplusplus
}
#endif
#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "swscale.lib")
#include <stdio.h>
然后开始使用吧。
使用是需要注意:
// pFormatCtx必须为空,否则 avformat_open_input失败。
AVFormatContext* pFormatCtx(NULL);
int result = avformat_open_input(&pFormatCtx, filename, NULL, NULL);
参考
http://wenku.baidu.com/link?url=2W6fQSQzpvTQAfcHJ12k9rbpBroTx0RHK-3m6SFZLdpeSCj9xzahF34n_0kzKPr8z7fd6QChb7ZgL9kznzmH33VUlIYnXLxH76HHeob_XMC
http://www.cnblogs.com/Jerry-Chou/archive/2011/03/31/2000761.html