(转)How to build x264/libx264.dll in Windows (2012-06-06 15:22:36)转载▼ 标签: 杂谈 分类: 音视频
From http://blog.sina.com.cn/s/blog_4ae178ba01013xmm.html
For someone coming from a windows background, where you do virtually everything, using GUI probably with Visual studio or an equivalent IDE, compiling a program from the command line can be a daunting task.
This blog post will guide you through compiling and building the popular open source video encoding library on windows using the MinGW(Minimalist GNU on Windows).
First you need to download the x264 source code from http://x264.nl/ Or if you know how to use git, you can git clone the x264 from git://git.videolan.org/x264.git.
Then you should download MinGW from http://sourceforge.net/projects/mingw/files Download the mingw-get-inst-20111118.exe (591.9 kB) install it and during the installation steps, select all the check boxes.
After the installation is completed, then from Start button , click All program, then click MinGW and then Click on MinGW shell, this brings up the following window
From the msys shell change your directory to the location where your x264 source code is, in my own case the x264 code is in the c: drive so I will simply Type cd c:\x264
Then type ./configure and press enter, this screen waits for some seconds and the bring
Then you can now type make and press enter, this will bring up the window below, showing the progress of the compilation process.
After the compilation is finished, if you look into your x264 directory you will find x264.exe file there.
Now compiling the x264 into a dynamic link library that can be used in Visual studio takes another process entirely. Open the MinGW bash once again and change the directory to the location of your x264 source code, just like you did previously.
Then type
./configure --disable-cli --enable-shared --extra-ldflags=-Wl,--output-def=libx264-120.def
or just
./configure --disable-cli --enable-shared --extra-ldflags=-Wl,--output-def=libx264.def
Now in libx264-120.def “120” is the version of the x264 you are using, you can find the version of the x264 you are using by opening the x264.h file in your x264 source folder you will see something like this #define X264_BUILD 120 depending on your version.
You can now type the make command and press enter and you will find the libx264-120.dll in your x264 source folder. Then rename libx264-120.dll to libx264.dll and you have you dynamic link library to work with.
If you wish to generate the Visual Studio .lib file to work with then open a Visual Studio command prompt, and change the directory to the location of the x264 source .
Then run this command
LIB /DEF:libx264.def
Then press enter
And your libx264.lib would be generated.
-------------------------------------
完整版win32 vs2008 2010编译X264的过程
1.首先下载该处的X264:
http://truth-tracer.appspot.com/x264-snapshot-20090216-2245.rar
作者已经对该版本的X264进行了一定的修改。具体修改内容可见:http://bbs.chinavideo.org/viewthread.php?tid=6945&highlight=VS2008
2。下载yasm
http://www.tortall.net/projects/yasm/wiki/Download
选择win32.exe.如果是VS2010则下载Win32 VS2010 .zip
解压后将.exe改名成yasm.exe,主要是方便工程里面yasm的设置
将.exe放在D:\Program Files\Microsoft Visual Studio 9.0\VC\bin,查找自己的相应目录
3。接下来需要下载自定义生成的模板(自己理解的)
VS2008,VS2005下载 yasm.rules //
VS2010可直接使用除了EXE外三个文件
有同学反映说下载不了,我发现这个网站可能换了
现在最新的应该是地址:
http://github.com/yasm/yasm/blob/master/Mkfiles/vc9/yasm.rules
相应的使用说明介绍在
https://github.com/yasm/yasm/wiki/VisualStudio2005
4。模板放到你的工程目录下,如C。。。。。。\x264-snapshot-20090216-2245\x264-snapshot-20090216-2245\build\win32
VS2010有个一劳永逸的办法,将那三个文件放到
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations下
5。打开工程,编译X264具体的思路是先编译生成libx264d.lib,然后将该lib添加到工程lib库,最后对x264进行编译后生成x264.exe
首先编译生成libx264d.lib.右击解决方案,选择自定义生成规则,选择查找现有的,然后在弹出对话框里选择放在该目录下的yasm.rules,如果你放在别的地方就同样的方式添加。
然后右击解决方案,在属性里可以看到刚才新加的yasm assemble,vs2010貌似没有显示,但不妨碍。具体的东西不用动,接着下一步。
接下来打开解决方案的x86目录,可以发现ASM都集中在这里.刚才已经修改了yasm名字的,这里可以不用多改,不过也可以按照接下来的步骤进行检修改:
将命令行里的yasm改成你放在bin目录下的exe的名字。
如果使用yasm的话,请注意你的工程所在目录中不能有中文,否则编译的时候yasm会显示???而导致不能进行汇编。
接下来对所有的asm文件进行属性修改,完了后编译就没有什么问题了。
6。编译完了libx264后,会在工程\bin目录下生成个libx264d.lib(因人而异),可以将它提取出来放到VC的lib库里,具体路径:D:\Program Files\Microsoft Visual Studio 9.0\VC\lib中
打开x264的工程。右击解决方案,选择属性,选择C++-->链接器
将刚才添加的lib名添加到附加依赖选项。
接下来解决方案,生成,是不是没有问题了。嘿嘿!
VS2010也同样可以解决。
KA@EHNL}2KK@EM9[)O32@73.jpg (19.51 KB)
http://www.cnblogs.com/cplusplus/archive/2012/04/16/2451873.html
vs2008 x264-snapshot-20091006-2245编译成功
2012-01-13 18:01
x264-snapshot-20091006-2245 是包含vc的最后一个版本了,所以我对这个版本进行了编译,开始一大把错误;然后逐步排查,一一解决;
(1)下载该版本 http://download.videolan.org/pub/videolan/x264/snapshots/
(2)首先编译libx264,错误如下
2.1)主要是编译时,提示某个“;”分号之类的错误。
这种错误就是因为变量未声明成功。由于是C代码,VC中,一般要求C代码的变量在函数开头声明。所以,如果变量是在函数中间声明,必然报错。解决方法就是,把这些报错的变量声明放到函数开头或者作用域(大括号)开头。
解决这个问题后,出现一个错误:analyse.c(2950) : error C2059: syntax error : ‘[' ,错误的地方直接指向static const uint8_t check_mv_lists[X264_MBTYPE_MAX] =
{[P_L0]=1, [B_L0_L0]=1, [B_L1_L1]=2}; 将它改为static const uint8_t check_mv_lists[X264_MBTYPE_MAX] ={0,0,0,0,1,0,0,0,1,0,0,0,2,0,0,0,0,0,0};
编译libx264成功;接着编译x264.exe
2.2)又出现2.1)中的错误,这个好解决,最好的办法就是将变量在函数开始时声明,然后出现一个bug 如下:
muxers.c(299) : error C2146: syntax error :
missing ‘)’ before identifier ‘PRIx32′
fprintf( stderr, “Bad header magic (%”PRIx32″ <=> %s)\n”, *((uint32_t*)header), header );
改为:
fprintf( stderr, “Bad header magic (%ld <=>%s)\n”, *((uint32_t*)header), header );
2.3)解决这个问题后,又出现一个bug:
muxers.c(299) : error C2146: syntax error :missing ‘)’ before identifier ‘PRIx32′
fprintf( stderr, “Bad header magic (%”PRIx32″ <=> %s)\n”, *((uint32_t*)header), header );
改为
fprintf( stderr, “Bad header magic (%ld <=>%s)\n”, *((uint32_t*)header), header );
继续编译:x264 出现如下bug:
1>libx264.lib(encoder.obj) : error LNK2019: unresolved
external symbol _x264_lookahead_is_empty referenced in function
_x264_encoder_encode
1>libx264.lib(encoder.obj) : error LNK2019: unresolved
external symbol _x264_lookahead_get_frames referenced in function
_x264_encoder_encode
1>libx264.lib(encoder.obj) : error LNK2019: unresolved
external symbol _x264_lookahead_put_frame referenced in function
_x264_encoder_encode
1>libx264.lib(encoder.obj) : error LNK2019: unresolved
external symbol _x264_lookahead_delete referenced in function
_x264_encoder_close
1>libx264.lib(analyse.obj) : error LNK2019: unresolved
external symbol _log2f referenced in function _x264_analyse_init_costs
1>bin/x264.exe : fatal error LNK1120: 6 unresolved
externals
这是因为:libx264工程没有添加lookahead.c文件,从而缺少几个函数的定义造成的,添加lookahead.c进工程;
再次Build libx264工程,修改以下几个错误
1>..\..\encoder\lookahead.c(135) : error C2143: syntax
error : missing ‘;’ before ‘type’
1>..\..\encoder\lookahead.c(154) : error C2275: ‘x264_t’ :
illegal use of this type as an expression
1>..\..\encoder\lookahead.c(259) : error C2143: syntax error
: missing ‘;’ before ‘type’
然后接续编译:
1>libx264.lib(analyse.obj) : error LNK2019: unresolved
external symbol _log2f referenced in function _x264_analyse_init_costs
这是因为没有定义log2f函数,添加#define
log2f(x) (logf(x)*1.4426950408889634f)到osdep.h中
再次编译x264 成功;