-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild_x265.sh
307 lines (274 loc) · 11.5 KB
/
build_x265.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/bin/sh
#msys2用x265ビルドスクリプト
#pacman -S base-devel mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain p7zip git nasm p7zip
#そのほかにcmakeのインストールが必要
#NJOBS=$(($NUMBER_OF_PROCESSORS>16?16:$NUMBER_OF_PROCESSORS))
NJOBS=8
BUILD_DIR=$HOME/build_x265
BUILD_DIR_WIN=`cygpath -m ${HOME}`/build_x265
#cmake.exeのある場所
CMAKE_DIR="/C/Program Files/CMake/bin"
#プロファイル用のソース
Y4M_PATH=$HOME/sakura_op_cut.y4m
X265_REV=
X265_BRANCH="master"
UPDATE_X265="TRUE"
BUILD_12BIT="ON"
BUILD_10BIT="ON"
PROFILE_GEN_CC="-fprofile-generate -gline-tables-only"
PROFILE_GEN_LD="-fprofile-generate -gline-tables-only"
PROFILE_USE_CC="-fprofile-use"
PROFILE_USE_LD="-fprofile-use"
export PATH="${CMAKE_DIR}:$PATH"
mkdir -p ${BUILD_DIR}
mkdir -p ${BUILD_DIR}/src
cd ${BUILD_DIR}/src
# [ "x86", "x64" ]
if [ $MSYSTEM = "MINGW32" ]; then
TARGET_ARCH="x86"
else
TARGET_ARCH="x64"
fi
echo "TARGET_ARCH=${TARGET_ARCH}"
if [ $MSYSTEM == "CLANG64" ]; then
export CC=clang
export CXX=clang++
fi
if [ ${TARGET_ARCH} = "x64" ]; then
BUILD_CCFLAGS="-O3 -msse2 -fpermissive -flto -I${INSTALL_DIR}/include"
BUILD_LDFLAGS="-static -static-libgcc -static-libstdc++ -flto -L${INSTALL_DIR}/lib"
elif [ ${TARGET_ARCH} = "x86" ]; then
BUILD_CCFLAGS="-m32 -msse2 -I${INSTALL_DIR}/include"
BUILD_LDFLAGS="-static -static-libgcc -static-libstdc++ -L${INSTALL_DIR}/lib"
#x86向けには高ビット深度版はビルドしない
BUILD_12BIT="OFF"
BUILD_10BIT="OFF"
#x86向けには、プロファイル最適化はスキップする
PROFILE_GEN_CC=""
PROFILE_GEN_LD=""
PROFILE_USE_CC=""
PROFILE_USE_LD=""
else
echo "invalid TARGET_ARCH: ${TARGET_ARCH}"
exit
fi
#--- ソースのダウンロード ---------------------------------------
if [ -d "x265" ]; then
if [ $UPDATE_X265 != "FALSE" ]; then
cd x265
if [ "${X265_REV}" != "" ]; then
git fetch && git checkout --force ${X265_REV}
else
git fetch && git checkout --force ${X265_BRANCH} && git reset --hard origin/${X265_BRANCH}
fi
cd ..
fi
else
UPDATE_X265=TRUE
git clone https://bitbucket.org/multicoreware/x265_git.git x265
cd x265
git fetch
if [ "${X265_REV}" != "" ]; then
git checkout --force ${X265_REV}
else
git checkout --force ${X265_BRANCH}
git reset --hard origin/${X265_BRANCH}
fi
cd ..
fi
# --- 出力先を準備 --------------------------------------
if [ ! -d ${BUILD_DIR}/${TARGET_ARCH} ]; then
mkdir ${BUILD_DIR}/${TARGET_ARCH}
fi
cd ${BUILD_DIR}/${TARGET_ARCH}
if [ -d x265 ]; then
rm -rf x265
fi
cp -r ../src/x265 .
# --- ビルド ----------------------------------------------
cd ${BUILD_DIR}/${TARGET_ARCH}/x265
patch -p 1 < ~/patch/x265_version.diff
patch -p 1 < ~/patch/x265_zone_param.diff
cd ${BUILD_DIR}/${TARGET_ARCH}/x265/build/msys
X265_EXTRA_LIB=""
mkdir -p 8bit
if [ "${PROFILE_GEN_CC}" != "" ]; then
CMAKE_PROFILE_ARG="-DFPROFILE_GENERATE=ON"
if [ $BUILD_12BIT = "ON" ]; then
mkdir -p 12bit
cd 12bit
#fprofile-generateするためには、-fprofile-generateを
#CMAKE_C_FLAGS/CMAKE_CXX_FLAGSだけでなく、CMAKE_EXE_LINKER_FLAGSに渡す必要がある
cmake -G "MSYS Makefiles" ../../../source \
-DHIGH_BIT_DEPTH=ON \
-DEXPORT_C_API=OFF \
-DENABLE_SHARED=OFF \
-DENABLE_HDR10_PLUS=OFF \
-DENABLE_CLI=OFF \
-DMAIN12=ON \
${CMAKE_PROFILE_ARG} \
-DCMAKE_C_FLAGS="${BUILD_CCFLAGS} ${PROFILE_GEN_CC}" \
-DCMAKE_CXX_FLAGS="${BUILD_CCFLAGS} ${PROFILE_GEN_CC}" \
-DCMAKE_EXE_LINKER_FLAGS="${BUILD_LDFLAGS} ${PROFILE_GEN_LD}"
make -j${NJOBS} &
X265_EXTRA_LIB="x265_main12"
fi
cd ${BUILD_DIR}/${TARGET_ARCH}/x265/build/msys
if [ $BUILD_10BIT = "ON" ]; then
mkdir -p 10bit
cd 10bit
#fprofile-generateするためには、-fprofile-generateを
#CMAKE_C_FLAGS/CMAKE_CXX_FLAGSだけでなく、CMAKE_EXE_LINKER_FLAGSに渡す必要がある
cmake -G "MSYS Makefiles" ../../../source \
-DHIGH_BIT_DEPTH=ON \
-DEXPORT_C_API=OFF \
-DENABLE_SHARED=OFF \
-DENABLE_HDR10_PLUS=ON \
-DENABLE_CLI=OFF \
${CMAKE_PROFILE_ARG} \
-DCMAKE_C_FLAGS="${BUILD_CCFLAGS} ${PROFILE_GEN_CC}" \
-DCMAKE_CXX_FLAGS="${BUILD_CCFLAGS} ${PROFILE_GEN_CC}" \
-DCMAKE_EXE_LINKER_FLAGS="${BUILD_LDFLAGS} ${PROFILE_GEN_LD}"
make -j${NJOBS} &
X265_EXTRA_LIB="x265_main10;${X265_EXTRA_LIB}"
fi
cd ${BUILD_DIR}/${TARGET_ARCH}/x265/build/msys/8bit
if [ $BUILD_10BIT = "ON" ] || [ $BUILD_12BIT = "ON" ]; then
wait
if [ $BUILD_10BIT = "ON" ]; then
cp ../10bit/libx265.a libx265_main10.a
fi
if [ $BUILD_12BIT = "ON" ]; then
cp ../12bit/libx265.a libx265_main12.a
fi
fi
cmake -G "MSYS Makefiles" ../../../source \
-DEXTRA_LIB="${X265_EXTRA_LIB}" \
-DEXTRA_LINK_FLAGS=-L. \
-DLINKED_10BIT=${BUILD_10BIT} \
-DLINKED_12BIT=${BUILD_12BIT} \
-DENABLE_SHARED=OFF \
-DENABLE_HDR10_PLUS=OFF \
${CMAKE_PROFILE_ARG} \
-DCMAKE_C_FLAGS="${BUILD_CCFLAGS} ${PROFILE_GEN_CC}" \
-DCMAKE_CXX_FLAGS="${BUILD_CCFLAGS} ${PROFILE_GEN_CC}" \
-DCMAKE_EXE_LINKER_FLAGS="${BUILD_LDFLAGS} ${PROFILE_GEN_LD}"
#強制的に完全な静的リンクにする
sed -i -e 's/Bdynamic/Bstatic/g' CMakeFiles/cli.dir/linklibs.rsp
make -j${NJOBS}
prof_files=()
prof_idx=0
function run_prof() {
./x265 $@
prof_idx=$((prof_idx + 1))
for file in default_*_0.profraw; do
new_file="${file%.profraw}_${prof_idx}.${file##*.}"
mv "$file" "$new_file"
echo ${new_file}
prof_files+=( ${new_file} )
done
}
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --preset faster
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --preset fast
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --preset slow
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --preset slower
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --output-depth 10 --preset faster
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --output-depth 10 --preset fast
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --output-depth 10
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --output-depth 10 --preset slow
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --output-depth 10 --preset slower
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --output-depth 12 --preset faster
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --output-depth 12 --preset fast
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --output-depth 12
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --output-depth 12 --preset slow
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx2 --output-depth 12 --preset slower
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --preset faster
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --preset fast
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --preset slow
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --preset slower
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --output-depth 10 --preset faster
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --output-depth 10 --preset fast
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --output-depth 10
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --output-depth 10 --preset slow
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --output-depth 10 --preset slower
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --output-depth 12 --preset faster
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --output-depth 12 --preset fast
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --output-depth 12
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --output-depth 12 --preset slow
run_prof --y4m -o /dev/null --input "${Y4M_PATH}" --asm avx512 --output-depth 12 --preset slower
echo ${prof_files[@]}
llvm-profdata merge -output=default.profdata "${prof_files[@]}"
PROFILE_USE_CC=${PROFILE_USE_CC}=`pwd`/default.profdata
PROFILE_USE_LD=${PROFILE_USE_LD}=`pwd`/default.profdata
fi
if [ "${PROFILE_GEN_CC}" = "" ]; then
CMAKE_PROFILE_ARG=""
else
CMAKE_PROFILE_ARG="-DFPROFILE_GENERATE=OFF -DFPROFILE_USE=ON"
fi
X265_EXTRA_LIB=""
cd ${BUILD_DIR}/${TARGET_ARCH}/x265/build/msys
if [ $BUILD_12BIT = "ON" ]; then
mkdir -p 12bit
cd 12bit
cmake -G "MSYS Makefiles" ../../../source \
-DHIGH_BIT_DEPTH=ON \
-DEXPORT_C_API=OFF \
-DENABLE_SHARED=OFF \
-DENABLE_HDR10_PLUS=OFF \
-DENABLE_CLI=OFF \
-DMAIN12=ON \
${CMAKE_PROFILE_ARG} \
-DCMAKE_C_FLAGS="${BUILD_CCFLAGS} ${PROFILE_USE_CC}" \
-DCMAKE_CXX_FLAGS="${BUILD_CCFLAGS} ${PROFILE_USE_CC}" \
-DCMAKE_EXE_LINKER_FLAGS="${BUILD_LDFLAGS} ${PROFILE_USE_LD}"
make -j${NJOBS} &
cp libx265.a ../8bit/libx265_main12.a
X265_EXTRA_LIB="x265_main12"
fi
cd ${BUILD_DIR}/${TARGET_ARCH}/x265/build/msys
if [ $BUILD_10BIT = "ON" ]; then
mkdir -p 10bit
cd 10bit
cmake -G "MSYS Makefiles" ../../../source \
-DHIGH_BIT_DEPTH=ON \
-DEXPORT_C_API=OFF \
-DENABLE_SHARED=OFF \
-DENABLE_HDR10_PLUS=ON \
-DENABLE_CLI=OFF \
${CMAKE_PROFILE_ARG} \
-DCMAKE_C_FLAGS="${BUILD_CCFLAGS} ${PROFILE_USE_CC}" \
-DCMAKE_CXX_FLAGS="${BUILD_CCFLAGS} ${PROFILE_USE_CC}" \
-DCMAKE_EXE_LINKER_FLAGS="${BUILD_LDFLAGS} ${PROFILE_USE_LD}"
make -j${NJOBS} &
cp libx265.a ../8bit/libx265_main10.a
X265_EXTRA_LIB="x265_main10;${X265_EXTRA_LIB}"
fi
cd ${BUILD_DIR}/${TARGET_ARCH}/x265/build/msys/8bit
if [ $BUILD_10BIT = "ON" ] || [ $BUILD_12BIT = "ON" ]; then
wait
if [ $BUILD_10BIT = "ON" ]; then
cp ../10bit/libx265.a libx265_main10.a
fi
if [ $BUILD_12BIT = "ON" ]; then
cp ../12bit/libx265.a libx265_main12.a
fi
fi
cmake -G "MSYS Makefiles" ../../../source \
-DEXTRA_LIB="${X265_EXTRA_LIB}" \
-DEXTRA_LINK_FLAGS=-L. \
-DLINKED_10BIT=${BUILD_10BIT} \
-DLINKED_12BIT=${BUILD_12BIT} \
-DENABLE_SHARED=OFF \
-DENABLE_HDR10_PLUS=OFF \
${CMAKE_PROFILE_ARG} \
-DCMAKE_C_FLAGS="${BUILD_CCFLAGS} ${PROFILE_USE_CC}" \
-DCMAKE_CXX_FLAGS="${BUILD_CCFLAGS} ${PROFILE_USE_CC}" \
-DCMAKE_EXE_LINKER_FLAGS="${BUILD_LDFLAGS} ${PROFILE_USE_LD}"
#強制的に完全な静的リンクにする
sed -i -e 's/Bdynamic/Bstatic/g' CMakeFiles/cli.dir/linklibs.rsp
#echo ${SVT_HEVC_LINK_LIBS} >> CMakeFiles/cli.dir/linklibs.rsp
make -j${NJOBS}
strip -s ${BUILD_DIR}/${TARGET_ARCH}/x265/build/msys/8bit/x265.exe