按照网上的介绍的方法,下载MinGW,FFMPEG源代码。
首先在msys下编译FFMPEG。
./configure --disable-yasm --enable-memalign-hack --enable-shared --enable-static --disable-asm
make CFLAGS=-U__STRICT_ANSI__
make install.
在编译过程出现了一下错误。
1我引入了 Xhead.h 内容如下,主要解决restrict 带来的错误。
#ifndef XHEAD_H
#define XHEAD_H
#define restrict
#endif
2修改了 ../MinGW/include/sched.h文件 主要解决错误
In file included from e:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../include/
pthread.h:288:0,
from libavcodec/pthread.c:24:
e:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../include/sched.h:154:53: error:
expected ')' before 'pid'
e:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../include/sched.h:156:53: error:
expected ')' before 'pid'
make: *** [libavcodec/pthread.o] Error 1
---------------------------------------------修改方法如下-----------------------
#if defined(__MINGW32__) || defined(_UWIN)
#if PTW32_LEVEL >= PTW32_LEVEL_MAX
/* For pid_t */
# include <sys/types.h>
/* Required by Unix 98 */
# include <time.h>
#else //增加
typedef int pid_t; //增加
#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
#else
typedef int pid_t;
#endif
经过上述修改,基本可以在Msys下编译得到动态库,lib文件,以及相应的测试exe。
修改完毕后,从MSYS下通过搜索拷贝出.dll,.lib文件。
新建一个vc工程,添加一个ffmpeg.c以及cmdutils.c文件。最好就在ffmpeg目录下,保持目录一致。
将lib,加入到vc工程中。
针对vc进行修改。为了保持vc与Msys都可以编译通过,采用了编译宏。
#ifndef _MS_VC
原来的代码。
#else
针对vc适应性修改。
#endif
自己编写了stdint.h,放在了系统目录下。或者在vc里面设置路径,使得使用#Include <stdint.h>可以包含,而不需要使用引号。
#ifndef _STDINT_H
#define _STDINT_H
typedef unsigned char uint8_t;
typedef char int8_t;
typedef unsigned short uint16_t ;
typedef short int16_t;
typedef int int32_t;
typedef unsigned int uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#define UINT64_C
#define inline
#endif
其他技巧参照使用编译宏,来进行修改。
最后将成功编译的vc exe 以及MSYS产生的动态库拷贝在一起就可以执行了。
需要补充的动态库为 libpthread-2.dll。在MIngW下搜索可以得到。
ffmpegvc.exe 为vc 生成的可执行文件,
ffmpeg.exe 为MinGW在编译FFMPEG时候的生成的可执行文件。
在CMD窗口下输入命令,进行验证。
ffmpeg.exe -i E:/视频数据/Browse2.mpg mingw.avi
ffmpegvc.exe -i E:/视频数据/Browse2.mpg vc.avi