MP4 muxer に L-SMASH を使った x264 のビルド手順。
基本は以下の過去トピの通り MSYS2 上で進め、 「GPAC のビルド」の部分を L-SMASH に置き換えるだけ。
L-SMASH を公式GitHubリポジトリ GitHub L-SMASH's official repo から clone します。
$ git clone https://github.com/l-smash/l-smash.git
Cloning into 'l-smash'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 7412 (delta 0), reused 1 (delta 0), pack-reused 7407
Receiving objects: 100% (7412/7412), 7.71 MiB | 4.84 MiB/s, done.
Resolving deltas: 100% (5445/5445), done.
$
続いて configure。
64bit 版をビルドする場合は prefix 指定を mingw32 → mingw64 に変更。
$ cd l-smash/
$ ./configure --prefix=/mingw32 (32bit版)
$ ./configure --prefix=/mingw64 (64bit版はこっち)
generating config.mak ...
SRCDIR = .
DESTDIR =
prefix = /mingw32
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
libdir = ${exec_prefix}/lib
includedir = ${prefix}/include
CC = gcc
AR = ar
LD = gcc
RANLIB = ranlib
STRIP = strip
STATICLIBNAME = liblsmash.a
STATICLIB = liblsmash.a
SHAREDLIBNAME = liblsmash-2.dll
SHAREDLIB =
IMPLIB = liblsmash.dll.a
CFLAGS = -Os -ffast-math -Wshadow -Wall -std=c99 -pedantic -I. -I. -D__USE_MINGW_ANSI_STDIO=1 -fexcess-precision=fast
LDFLAGS = -L. -Wl,--large-address-aware
SO_LDFLAGS =
LIBS = -lm
LIBARCH = i386
DEFNAME = liblsmash-2.def
SLIB_CMD = sed -i "s/ @[^ ]*//" $(DEFNAME); dlltool -m $(LIBARCH) -d $(DEFNAME) -l lsmash.lib -D $(SHAREDLIBNAME)
configure finished
type 'make' : compile library and tools
type 'make install' : install all into system
type 'make lib' : compile library only
type 'make install-lib' : install library and header into system
$
ビルド。ライブラリだけでいいので、ターゲットは lib を指定します。
$ make lib -j15 j15 は環境に合わせて適当に
gcc -c -Os -ffast-math -Wshadow -Wall -std=c99 -pedantic -I. -I. -D__USE_MINGW_ANSI_STDIO=1 -fexcess-precision=fast -o common/alloc.o common/alloc.c
gcc -c -Os -ffast-math -Wshadow -Wall -std=c99 -pedantic -I. -I. -D__USE_MINGW_ANSI_STDIO=1 -fexcess-precision=fast -o common/bits.o common/bits.c
gcc -c -Os -ffast-math -Wshadow -Wall -std=c99 -pedantic -I. -I. -D__USE_MINGW_ANSI_STDIO=1 -fexcess-precision=fast -o common/bytes.o common/bytes.c
(省略)
gcc -c -Os -ffast-math -Wshadow -Wall -std=c99 -pedantic -I. -I. -D__USE_MINGW_ANSI_STDIO=1 -fexcess-precision=fast -o core/timeline.o core/timeline.c
gcc -c -Os -ffast-math -Wshadow -Wall -std=c99 -pedantic -I. -I. -D__USE_MINGW_ANSI_STDIO=1 -fexcess-precision=fast -o core/write.o core/write.c
ar rc liblsmash.a common/alloc.o common/bits.o common/bytes.o common/list.o common/multibuf.o common/osdep.o common/utils.o codecs/a52.o codecs/alac.o codecs/description.o codecs/dts.o codecs/h264.o codecs/hevc.o codecs/id.o codecs/mp4sys.o codecs/mp4a.o codecs/mp4v.o codecs/nalu.o codecs/qt_wfex.o codecs/vc1.o codecs/wma.o importer/a52_imp.o importer/adts_imp.o importer/als_imp.o importer/amr_imp.o importer/dts_imp.o importer/importer.o importer/isobm_imp.o importer/mp3_imp.o importer/nalu_imp.o importer/vc1_imp.o importer/wave_imp.o core/box.o core/box_default.o core/box_type.o core/chapter.o core/file.o core/fragment.o core/isom.o core/meta.o core/print.o core/read.o core/summary.o core/timeline.o core/write.o
ranlib liblsmash.a
$
ビルドされたライブラリのインストール。
$ make install-lib
install -d /mingw32/include
install -m 644 ./lsmash.h /mingw32/include
install -d /mingw32/lib/pkgconfig
install -m 644 liblsmash.pc /mingw32/lib/pkgconfig
install -m 644 liblsmash.a /mingw32/lib
$ cd ~
$
これで L-SMASH 入り x264 のビルド環境ができあがり。
x264 のビルド
あとは 公式の git リポジトリ から x264 のソースを clone してきてビルドするだけ。
公式 git リポジトリからソースを clone する。
$ git clone http://code.videolan.org/videolan/x264.git
Cloning into 'x264'...
warning: redirecting to https://code.videolan.org/videolan/x264.git/
remote: Enumerating objects: 22359, done.
remote: Counting objects: 100% (22359/22359), done.
remote: Compressing objects: 100% (3848/3848), done.
remote: Total 22359 (delta 18548), reused 22258 (delta 18468), pack-reused 0
Receiving objects: 100% (22359/22359), 5.20 MiB | 1.23 MiB/s, done.
Resolving deltas: 100% (18548/18548), done.
$
configure。 host オプション付けないと妙な exe ができるので注意。
Commit 71ed44c7 でビット深度 10bit, 8bit 両対応のバイナリがデフォルトになったので、ビット深度設定オプション --bit-depth は不要に。
64bit 版をビルドする場合は host 指定を i686-w64-mingw32 → x86_64-w64-mingw32 に変更する。
$ cd x264/
$ ./configure --extra-cflags="-pipe -march=native" --extra-ldflags="-static -static-libgcc" --enable-strip --host=i686-w64-mingw32 (32bit版)
$ ./configure --extra-cflags="-pipe -march=native" --extra-ldflags="-static -static-libgcc" --enable-strip --host=x86_64-w64-mingw32 (64bit版)
platform: X86 64bit版では X86_64
byte order: little-endian
system: WINDOWS
cli: yes
libx264: internal
shared: no
static: no
asm: yes
interlaced: yes
avs: avisynth
lavf: no
ffms: no
mp4: lsmash ここが lsmash になっているか確認
gpl: yes
thread: win32
opencl: yes
filters: crop select_every
lto: no
debug: no
gprof: no
strip: yes
PIC: no
bit depth: all
chroma format: all
You can run 'make' or 'make fprofiled' now.
$
make する。何かしらの動画を使って最適化する場合は make fprofiled を使う。
ここでは、そこまでこだわってないので普通に make します。
$ make -j15 j15 オプションは環境に応じて(ry
cat common/opencl/x264-cl.h common/opencl/bidir.cl common/opencl/downscale.cl common/opencl/intra.cl common/opencl/motionsearch.cl common/opencl/subpel.cl common/opencl/weightp.cl | ./tools/cltostr.sh common/oclobj.h
dependency file generation...
windres --target=pe-i386 -I. -o x264res.o x264res.rc
(省略)
gcc-ranlib libx264.a
gcc -o x264.exe x264res.o x264.o autocomplete.o input/input.o input/timecode.o input/raw.o input/y4m.o output/raw.o output/matroska.o output/matroska_ebml.o output/flv.o output/flv_bytestream.o filters/filters.o filters/video/video.o filters/video/source.o filters/video/internal.o filters/video/resize.o filters/video/fix_vfr_pts.o filters/video/select_every.o filters/video/crop.o input/avs.o output/mp4_lsmash.o filters/video/cache-8.o filters/video/depth-8.o input/thread-8.o filters/video/cache-10.o filters/video/depth-10.o input/thread-10.o libx264.a -L/mingw32/lib -llsmash -lm -lshell32 -m32 -static -static-libgcc -Wl,--large-address-aware -Wl,--dynamicbase,--nxcompat,--tsaware -s
$
動作確認する。
$ ./x264 --version
x264 0.160.3009 4c9b076
built on Jun 20 2020, gcc: 10.1.0
x264 configuration: --chroma-format=all
libx264 configuration: --chroma-format=all
x264 license: GPL version 2 or later
$
exit して msys をインストールしたフォルダの home\(ユーザ名)\x264\x264.exe を適当な場所に移動なりコピーするなりすればできあがり。
それにしても 2017年だと -j3 だったのが -j15 になって隔世感ある。