1. 安装msys
msys(Minimal GNU system on Windows),是一个小型的GNU环境,包括基本的bash,make等等。与Cygwin差不多吧, 我也没用过cygwin
下载地址: https://msys2.github.io/
双击mingw64_shell.bat, 进入shell界面。(新的版本也可能没有这个文件了, 自己找找类似的吧). 使用uname -a查看系统信息:
$ uname -a
MINGW64_NT-6.1 Galaxy 2.3.0(0.290/5/3) 2015-09-15 09:39 x86_64 Msys
使用pacman更新系统
pacman –Suy
这个命令会同步数据源, 安装最新的msys, 并且安装mingw32和mingw64工具。pacman的使用说明,可以在下面这个网址上查到
https://www.archlinux.org/pacman/pacman.8.html
再次执行uname-a,可以看到系统已经升级到2.5.1了
$ uname -a
MSYS_NT-6.1 Galaxy 2.5.1(0.297/5/3) 2016-05-16 10:51 x86_64 Msys
2. 编译x264
将x264拷贝到msys64的home目录下, 执行配置脚本
./configure --host=mingw64 --enable-static --prefix=/home/x264-bin
可能会提示下面这样的错误,意思是config.guess和config.sub这两个脚本太旧了,需要重新下载它们
./config.guess: unable to guess system type
This script, last modified 2012-09-25, has failed to recognize
the operating system you are using. It is advised that you
download the most up to date version of the config scripts from
http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
and
http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
按照提示,打开这两个网页,网页的内容分别复制到config.gess和config.sub, 然后再次执行configure命令。这次应该可以成功了,显示如下信息
platform: X86_64
byte order: little-endian
system: WINDOWS
cli: yes
libx264: internal
shared: no
static: yes
asm: yes
interlaced: yes
avs: avisynth
lavf: no
ffms: no
mp4: no
gpl: yes
thread: posix
opencl: yes
filters: crop select_every
debug: no
gprof: no
strip: no
PIC: no
bit depth: 8
chroma format: all
You can run 'make' or 'make fprofiled' now.
执行make
$ make
最终可能编译不过,出现如下的错误:
libx264.a(cpu.o):cpu.c:(.text+0x631):对‘pthread_num_processors_np’未定义的引用
libx264.a(cpu.o):cpu.c:(.text+0x631): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `pthread_num_processors_np'
msys2自带的libpthread.a中没有pthread_num_processors_np这个接口, 所以链接时会提示未定义的符号,解决的方法有两个:
方法1: 禁用thread
./configure --host=mingw64 --enable-static --disable-thread --prefix=/home/x264-bin
方法2: 使用pthread-win32代替系统的libpthread.a。pthreads-win32的官网为
https://sourceware.org/pthreads-win32/
下载最近发布的版本
ftp://sourceware.org/pub/pthreads-win32/dll-latest
下载dll-latest/lib/x64/libpthreadGC2.a, 这是gcc使用的版本
删除msys64/usr/lib/libpthread.a, 使用libpthreadGC2.a来代替,之后应该就可以编译通过
3.编译ffmpeg
下载最新版本的ffmpeg, (我的版本是2.6.3), 在msys上安装yasm
pacman -S yasm
执行configure
./configure --target-os=win64 \
--arch=x86_64 \
--enable-static \
--enable-memalign-hack \
--enable-small \
--enable-version3 \
--enable-gpl \
--enable-nonfree \
--disable-stripping \
--disable-encoders \
--disable-decoders \
--enable-decoder=h264 \
--enable-encoder=libx264 \
--enable-encoder=mjpeg \
--enable-encoder=mpeg4 \
--prefix=./lib \
--enable-libx264 \
--extra-cflags="-I/home/x264-bin/include" \
--extra-ldflags="-L/home/x264-bin/lib"
这个过程应该很简单,麻烦的是,在链接最终的应用程序时,有很多函数找不到。需要自己去实现一版