0%

使用MSYS2+mingw编译x264-tmod

前言

最近在试着压片,想在mediainfo里夹带私货,所以需要自己编译一下x264。

本文仅做记录用,由于自己水平不足无法答疑请谅解。

第一步

安装 Git

安装MSYS2

由于网络原因你可能需要给MSYS换源或者设置代理,此处不赘述

安装完毕以后找到MSYS2 MinGW 64-bit

打开MSYS2

1
2
3
4
5
6
7
8
pacman -Syu
pacman -Su
pacman -S mingw-w64-i686-gcc
pacman -S mingw-w64-x86_64-gcc
pacman -S base-devel
pacman -S vim
pacman -S nasm
pacman -S git

以上安装完成后输入

gcc -v

查看是否正常

第二步

假设本次的文件都在 “ C:\x264_Prg\ “

在git bash中

1
2
3
cd "C:\x264_Prg\ "
git clone https://github.com/l-smash/l-smash.git
git clone https://github.com/jpsdr/x264.git -b t_mod_New

进入 “ C:\x264_Prg\l-smash “ 新建文件夹 Build_x264

修改makefile

找到

1
2
3
4
install -d $(DESTDIR)$(includedir)
install -m 644 $(SRCDIR)/lsmash.h $(DESTDIR)$(includedir)
install -d $(DESTDIR)$(libdir)/pkgconfig
install -m 644 liblsmash.pc $(DESTDIR)$(libdir)/pkgconfig

修改为

1
2
3
4
5
install -d $(DESTDIR)$(includedir)
install -m 644 $(SRCDIR)/lsmash.h $(DESTDIR)$(includedir)
install -m 644 $(SRCDIR)/importer.h $(DESTDIR)$(includedir)/lsmash_importer.h
install -d $(DESTDIR)$(libdir)/pkgconfig
install -m 644 liblsmash.pc $(DESTDIR)$(libdir)/pkgconfig

1
$(RM) $(DESTDIR)$(includedir)/lsmash.h

替换为

1
$(RM) $(addprefix $(DESTDIR)$(includedir)/, lsmash.h, lsmash_importer.h)

然后进入 “ C:\x264_Prg\l-smash\importer “将importer.h 复制到 “C:\x264_Prg\l-smash”

然后在 “ C:\x264_Prg\ “新建一个” Build_lsmash_x264.sh

文件内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cd ./l-smash/Build_x264
_dir="/local-x264"
[[ "$1" = "32" ]] && _dir="${_dir}_x86"
[[ "$1" = "64" ]] && _dir="${_dir}_x64"
[[ "$2" = "posix" ]] && _dir="${_dir}/posix"
[[ "$2" = "win32" ]] && _dir="${_dir}/Win32threads"
[[ "$3" = "original" ]] && _dir="${_dir}/Original"
[[ "$3" = "tmod" ]] && _dir="${_dir}/t_mod"
[[ "$3" = "jpsdr" ]] && _dir="${_dir}/jpsdr"
_ld="-static"
_cf=""
[[ "$3" = "jpsdr" ]] && _cf="-march=haswell -mavx -mavx2 -mtune=haswell"
[[ "$1" = "64" ]] && _ld="${_ld} -m64"
[[ "$1" = "64" ]] && _cf="${_cf} -m64"
PKG_CONFIG_PATH="${_dir}/lib/pkgconfig" \
../configure --prefix=${_dir} --extra-ldflags="${_ld}" --extra-cflags="${_cf}"
make -j1 lib
make install
make clean

在git bash里执行

1
./Build_lsmash_x264.sh 64 win32 tmod

或32位

1
./Build_lsmash_x264.sh 32 win32 tmod

l-smash完成

1
2
3
cd  "C:\x264_Prg\x264"
./configure
make

x264完成

具体configure的可选配置项可以自行前往x264文件查看

如果有需要修改version的需求,可以自行在编译前修改x264文件夹下的version.sh

参考链接

https://forum.doom9.org/showthread.php?t=172610