-
Notifications
You must be signed in to change notification settings - Fork 5
/
ffmpeg-native-x86
564 lines (504 loc) · 17.9 KB
/
ffmpeg-native-x86
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
#!/bin/bash
SCRIPT_VERSION="1.4.0"
THIS="ffmpeg-native-x86"
#build paths
ROOT_PATH="${ROOT_PATH:-$HOME}"
SRC_PATH="${SRC_PATH:-ffmpeg_sources}"
OUT_PATH="${OUT_PATH:-ffmpeg_build}"
BIN_PATH="${BIN_PATH:-$ROOT_PATH/$OUT_PATH/bin}"
HINTS_FILE="${HINTS_FILE:-$ROOT_PATH/ffmpeg-native-build-hints}"
NCC_PATH_LIST=\
( \
"ROOT_PATH" "SRC_PATH" "OUT_PATH" "BIN_PATH" "HINTS_FILE" \
)
#compiler settings
NCC_OPTIM="-O2"
NCC_CFLAGS="-mtune=native -pipe"
#make settings
NCC_JOBS=$(getconf _NPROCESSORS_ONLN)
NCC_FETCH_ONLY="${NCC_FETCH_ONLY:-0}"
NCC_SHOW_ONLY="${NCC_SHOW_ONLY:-0}"
NCC_DISABLE_DEFAULT="${NCC_DISABLE_DEFAULT:-0}"
NCC_OPTION_LIST=\
( \
"HOST" "OPTIM" "CFLAGS" "JOBS" "FETCH_ONLY" "SHOW_ONLY" "DISABLE_DEFAULT" \
)
NCC_SOURCE_LIST=\
( \
"aom" "fdk-aac" "ffmpeg" "lame" \
"nv-codec-headers" "ogg" "opus" "sdl" \
"theora" "vorbis" "vpx" "x264" "x265" \
)
#fix pkg-config paths for cross
export PKG_CONFIG_DIR=
export PKG_CONFIG_PATH=
export PKG_CONFIG_SYSROOT_PATH="$ROOT_PATH"
export PKG_CONFIG_LIBDIR="$ROOT_PATH/$OUT_PATH/lib/pkgconfig"
build_message() {
local BM_WHITE=15
local BM_GREEN=10
local BM_CYAN=14
local BM_MAGENTA=200
local BM_YELLOW=11
local BM_RED=9
local color=$1
shift
printf "\e[38;5;${!color}m====> $@ <====\e[0m\n" 1>&2
}
build_die() {
build_message BM_RED "$@"
exit 1
}
build_make() {
local jobs="${1:-1}"
local hint=$(get_hint "$SRC_NAME" "make")
jobs="${hint:-$jobs}"
make -j $jobs
[ $? -eq 0 ] || build_die "$THIS: make stage failed (jobs = $jobs) -> $SRC_NAME"
make install
[ $? -eq 0 ] || build_die "$THIS: install stage failed -> $SRC_NAME"
build_message BM_GREEN "$SRC_NAME: built successfully (jobs = $jobs)"
}
fetch_source() {
local revision=$(get_hint "$SRC_NAME" "$SRC_METHOD")
local url=$(get_hint "$SRC_NAME" "url")
local status=1
local scheme;
local path;
if [ -z "$url" ]
then
url="$SRC_URL"
fi
[[ "$url" =~ ^(file://)(.+)$ ]]
scheme="${BASH_REMATCH[1]}"
path="${BASH_REMATCH[2]}"
if [ "$scheme" == "file://" ]
then
build_message BM_YELLOW "rsync $path/ ./$SRC_NAME/"
if [ "$NCC_SHOW_ONLY" -eq 0 ]
then
mkdir "$SRC_NAME"
eval "rsync -rit --stats $path/ ./$SRC_NAME/"
status=$?
fi
fi
if [ "$NCC_SHOW_ONLY" -ne 0 ]
then
build_message BM_MAGENTA "$SRC_NAME: fetch -> $SRC_METHOD $url $revision"
return 0
fi
case "$SRC_METHOD" in
git)
if [ "$scheme" != "file://" ]
then
git clone "$url" "$SRC_NAME"
status=$?
fi
if [ ! -z "$revision" ] && [ "$status" -eq 0 ]
then
cd_source
git reset --hard "$revision"
status=$?
cd ..
fi
;;
svn)
if [ "$scheme" != "file://" ]
then
svn checkout "$url" "$SRC_NAME"
status=$?
fi
if [ ! -z "$revision" ] && [ "$status" -eq 0 ]
then
cd_source
svn up -r"$revision"
status=$?
cd ..
fi
;;
hg)
if [ "$scheme" != "file://" ]
then
hg clone "$url" "$SRC_NAME"
status=$?
fi
if [ ! -z "$revision" ] && [ "$status" -eq 0 ]
then
cd_source
hg revert -r "$revision" --all
status=$?
cd ..
fi
;;
#wget)
#wget -O "$SRC_NAME.$1" "$url"
#;;
*)
build_die "$THIS: invalid fetch method -> $SRC_NAME: $SRC_METHOD"
;;
esac
if [ $status -eq 0 ]
then
build_message BM_MAGENTA "$SRC_NAME: fetch success -> $SRC_METHOD $url $revision"
else
build_die "$THIS: fetch stage failed -> $SRC_NAME: $SRC_METHOD $url"
fi
}
get_hint() {
local status=1
if [ -r "$HINTS_FILE" ]
then
#$1 name
#$2 hint
local name=$1
shift
local hint=$1
shift
awk -F'\t' -v name=$name -v hint=$hint \
'!($0 ~ /^[[:space:]]*#/) && !($0 ~ /^[[:space:]]*$/) && $1 == name && $2 == hint \
{printf "%s", $3; found=1; exit} \
END { if (found) {exit 0} else {exit 1}}' "$HINTS_FILE"
status=$?
fi
return $status
}
get_NCC_hints() {
local h
local val
local var
#initialize enabled builds based on enable/disable default
for h in "${NCC_SOURCE_LIST[@]}"
do
var="NCC_ENABLE_$h"
var="${var//[^A-Za-z0-9]/_}"
var="${var^^}"
#echo "$var"
if [ $NCC_DISABLE_DEFAULT -eq 0 ]
then
val=1
else
val=0
fi
eval "$var=\$val"
done
#check for values from the hints file
if [ -r "$HINTS_FILE" ]
then
for h in "${NCC_OPTION_LIST[@]}"
do
val="$(get_hint "NCC" "$h")"
if [ $? -eq 0 ]
then
var="NCC_$h"
eval "$var=\$val"
fi
done
for h in "${NCC_SOURCE_LIST[@]}"
do
var="NCC_ENABLE_$h"
var="${var//[^A-Za-z0-9]/_}"
var="${var^^}"
#echo "$var"
if [ $NCC_DISABLE_DEFAULT -eq 0 ]
then
val="$(get_hint "$h" "disable")"
if [ $? -eq 0 ]
then
val=0
else
val=1
fi
else
val="$(get_hint "$h" "enable")"
if [ $? -eq 0 ]
then
val=1
else
val=0
fi
fi
eval "$var=\$val"
done
fi
}
set_source() {
if [ "$NCC_SHOW_ONLY" -eq 0 ]
then
cd "$ROOT_PATH/$SRC_PATH"
fi
SRC_NAME="$1"
shift
SRC_ENABLE="NCC_ENABLE_$SRC_NAME"
SRC_ENABLE="${SRC_ENABLE//[^A-Za-z0-9]/_}"
SRC_ENABLE="${SRC_ENABLE^^}"
SRC_URL=$(get_hint "$SRC_NAME" "url")
SRC_METHOD="$1"
shift
SRC_URL="${SRC_URL:-$1}"
shift
if [ "${!SRC_ENABLE}" -ne 0 ]
then
for arg in "$@"
do
NCC_FFMPEG_LIB_OPTIONS="$NCC_FFMPEG_LIB_OPTIONS --enable-$arg"
done
build_message BM_CYAN "$SRC_NAME"
fi
}
cd_source() {
cd $SRC_NAME
}
#startup banner
build_message BM_WHITE "$THIS: Version $SCRIPT_VERSION"
#load NCC hints
get_NCC_hints
if [ "$NCC_SHOW_ONLY" -ne 0 ]
then
for i in "${NCC_PATH_LIST[@]}"
do
echo "$i: ${!i}"
done
for i in "${NCC_OPTION_LIST[@]}"
do
var="NCC_$i"
echo "$var: ${!var}"
done
for i in "${NCC_SOURCE_LIST[@]}"
do
var="NCC_ENABLE_$i"
var="${var//[^A-Za-z0-9]/_}"
var="${var^^}"
echo "$var: ${!var} ($i)"
done
fi
if [ "$NCC_FETCH_ONLY" -eq 0 ] && [ "$NCC_SHOW_ONLY" -eq 0 ]
then
BUILD=1
else
BUILD=0
fi
#ensure clean build
if [ "$BUILD" -ne 0 ]
then
rm -rf "$ROOT_PATH/$OUT_PATH"
[ -d "$ROOT_PATH/$OUT_PATH" ] && build_die "$THIS: unable to remove build directory -> $ROOT_PATH/$OUT_PATH"
fi
if [ "$BUILD" -ne 0 ] || [ "$NCC_FETCH_ONLY" -ne 0 ]
then
rm -rf "$ROOT_PATH/$SRC_PATH"
[ -d "$ROOT_PATH/$SRC_PATH" ] && build_die "$THIS: unable to remove source directory -> $ROOT_PATH/$SRC_PATH"
fi
if [ "$BUILD" -ne 0 ]
then
mkdir "$ROOT_PATH/$OUT_PATH"
[ ! -d "$ROOT_PATH/$OUT_PATH" ] && build_die "$THIS: unable to create build directory -> $ROOT_PATH/$OUT_PATH"
fi
if [ "$BUILD" -ne 0 ] || [ "$NCC_FETCH_ONLY" -ne 0 ]
then
mkdir "$ROOT_PATH/$SRC_PATH"
[ ! -d "$ROOT_PATH/$SRC_PATH" ] && build_die "$THIS: unable to create source directory -> $ROOT_PATH/$SRC_PATH"
fi
if [ "$BUILD" -ne 0 ]
then
#cmake toolchain settings
touch $ROOT_PATH/$SRC_PATH/native.make
echo "SET(CMAKE_SYSTEM_NAME Linux)" >> $ROOT_PATH/$SRC_PATH/native.make
echo "SET(CMAKE_SYSTEM_PROCESSOR i686)" >> $ROOT_PATH/$SRC_PATH/native.make
echo "SET(CMAKE_C_COMPILER gcc)" >> $ROOT_PATH/$SRC_PATH/native.make
echo "SET(CMAKE_CXX_COMPILER g++)" >> $ROOT_PATH/$SRC_PATH/native.make
echo "SET(CMAKE_ASM_YASM_COMPILER yasm)" >> $ROOT_PATH/$SRC_PATH/native.make
echo "SET(CMAKE_ASM_NASM_COMPILER nasm)" >> $ROOT_PATH/$SRC_PATH/native.make
echo "SET(CMAKE_CXX_FLAGS \"$NCC_OPTIM $NCC_CFLAGS\")" >> $ROOT_PATH/$SRC_PATH/native.make
echo "SET(CMAKE_C_FLAGS \"$NCC_OPTIM $NCC_CFLAGS\")" >> $ROOT_PATH/$SRC_PATH/native.make
fi
#build the sources
#fdk-aac
set_source "fdk-aac" "git" "https://github.com/mstorsjo/fdk-aac.git" "libfdk-aac"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
cd_source
autoreconf -fiv
./configure --prefix="$ROOT_PATH/$OUT_PATH" CFLAGS="$NCC_OPTIM $NCC_CFLAGS" CXXFLAGS="$NCC_OPTIM $NCC_CFLAGS" --enable-static --disable-shared
[ $? -eq 0 ] || build_die "$THIS: configure stage failed -> $SRC_NAME"
build_make $NCC_JOBS
fi
fi
#lame
set_source "lame" "svn" "https://svn.code.sf.net/p/lame/svn/trunk/lame" "libmp3lame"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
cd_source
#--enable-nasm x86 broken?
./configure --prefix="$ROOT_PATH/$OUT_PATH" CFLAGS="$NCC_OPTIM $NCC_CFLAGS" CXXFLAGS="$NCC_OPTIM $NCC_CFLAGS" --disable-shared --disable-frontend
[ $? -eq 0 ] || build_die "$THIS: configure stage failed -> $SRC_NAME"
build_make $NCC_JOBS
fi
fi
#ogg
set_source "ogg" "git" "https://github.com/xiph/ogg.git"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
cd_source
./autogen.sh
./configure --prefix="$ROOT_PATH/$OUT_PATH" CFLAGS="$NCC_OPTIM $NCC_CFLAGS" CXXFLAGS="$NCC_OPTIM $NCC_CFLAGS" --enable-static --disable-shared
[ $? -eq 0 ] || build_die "$THIS: configure stage failed -> $SRC_NAME"
build_make $NCC_JOBS
fi
fi
#opus
set_source "opus" "git" "https://github.com/xiph/opus.git" "libopus"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
cd_source
./autogen.sh
./configure --prefix="$ROOT_PATH/$OUT_PATH" CFLAGS="$NCC_OPTIM $NCC_CFLAGS" CXXFLAGS="$NCC_OPTIM $NCC_CFLAGS" --enable-static --disable-shared --disable-doc --disable-examples
[ $? -eq 0 ] || build_die "$THIS: configure stage failed -> $SRC_NAME"
build_make $NCC_JOBS
fi
fi
#theora
set_source "theora" "git" "https://github.com/xiph/theora.git" "libtheora"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
cd_source
./autogen.sh
./configure --prefix="$ROOT_PATH/$OUT_PATH" CFLAGS="$NCC_OPTIM $NCC_CFLAGS" CXXFLAGS="$NCC_OPTIM $NCC_CFLAGS" --enable-static --disable-shared --disable-doc --disable-oggtest --disable-vorbistest --disable-examples
[ $? -eq 0 ] || build_die "$THIS: configure stage failed -> $SRC_NAME"
build_make $NCC_JOBS
fi
fi
#vorbis
set_source "vorbis" "git" "https://github.com/xiph/vorbis.git" "libvorbis"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
cd_source
./autogen.sh
./configure --prefix="$ROOT_PATH/$OUT_PATH" --enable-static --disable-shared -disable-docs --disable-examples
[ $? -eq 0 ] || build_die "$THIS: configure stage failed -> $SRC_NAME"
build_make $NCC_JOBS
fi
fi
#aom AV1
set_source "aom" "git" "https://aomedia.googlesource.com/aom" "libaom"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
mkdir "$SRC_NAME"_build
cd "$SRC_NAME"_build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$ROOT_PATH/$OUT_PATH" -DCMAKE_TOOLCHAIN_FILE="$ROOT_PATH/$SRC_PATH/native.make" -DAOM_TARGET_CPU="x86" -DENABLE_SHARED=0 -DENABLE_NASM=1 -DENABLE_DOCS=0 -DENABLE_EXAMPLES=0 ../aom
[ $? -eq 0 ] || build_die "$THIS: configure stage failed -> $SRC_NAME"
build_make $NCC_JOBS
fi
fi
#vpx
set_source "vpx" "git" "https://chromium.googlesource.com/webm/libvpx.git" "libvpx"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
cd_source
./configure --prefix="$ROOT_PATH/$OUT_PATH" --extra-cflags="$NCC_CFLAGS" --target=x86-linux-gcc --as=yasm --enable-static --disable-shared --disable-examples --disable-tools --disable-docs --disable-unit-tests --enable-vp9 --enable-vp8 --enable-postproc --enable-vp9-postproc --enable-vp9-highbitdepth
[ $? -eq 0 ] || build_die "$THIS: configure stage failed -> $SRC_NAME"
build_make $NCC_JOBS
fi
fi
#x264
set_source "x264" "git" "https://git.videolan.org/git/x264" "libx264"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
cd_source
./configure --prefix="$ROOT_PATH/$OUT_PATH" --extra-cflags="$NCC_CFLAGS" --bindir="$BIN_PATH" --enable-static --disable-cli
[ $? -eq 0 ] || build_die "$THIS: configure stage failed -> $SRC_NAME"
build_make $NCC_JOBS
fi
fi
#x265
set_source "x265" "hg" "https://bitbucket.org/multicoreware/x265" "libx265"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
cd_source
cd build/linux
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$ROOT_PATH/$OUT_PATH" -DCMAKE_TOOLCHAIN_FILE="$ROOT_PATH/$SRC_PATH/native.make" -DENABLE_SHARED=0 -DENABLE_CLI=0 ../../source
[ $? -eq 0 ] || build_die "$THIS: configure stage failed -> $SRC_NAME"
build_make $NCC_JOBS
fi
fi
#sdl
set_source "sdl" "hg" "http://hg.libsdl.org/SDL"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
cd_source
mv .hg .temp_hg
CFLAGS=-DDECLSPEC= ./configure --prefix="$ROOT_PATH/$OUT_PATH" CFLAGS="$NCC_OPTIM $NCC_CFLAGS" CXXFLAGS="$NCC_OPTIM$NCC_CFLAGS" --bindir="$BIN_PATH" --enable-static --disable-shared
[ $? -eq 0 ] || build_die "$THIS: configure stage failed -> $SRC_NAME"
build_make $NCC_JOBS
rm -f "$BIN_PATH"/sdl*
mv .temp_hg .hg
fi
fi
#nvenc
set_source "nv-codec-headers" "git" "https://github.com/FFmpeg/nv-codec-headers.git" "nvenc" "nvdec"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
cd_source
make PREFIX="$ROOT_PATH/$OUT_PATH" install
[ $? -eq 0 ] || build_die "install stage failed for $SRC_NAME"
build_message BM_GREEN "$SRC_NAME: built"
fi
fi
#ffmpeg
set_source "ffmpeg" "git" "https://git.ffmpeg.org/ffmpeg.git" "gpl" "version3" "nonfree" "avresample"
if [ "${!SRC_ENABLE}" -ne 0 ]
then
fetch_source
if [ "$BUILD" -ne 0 ]
then
cd_source
./configure \
--enable-static \
--prefix="$ROOT_PATH/$OUT_PATH" \
--pkg-config="pkg-config" \
--pkg-config-flags="--static" \
--extra-cflags="$NCC_OPTIM $NCC_CFLAGS -no-pie" \
--extra-cflags="-I$ROOT_PATH/$OUT_PATH/include" \
--extra-ldflags="-L$ROOT_PATH/$OUT_PATH/lib -no-pie" \
--extra-libs="-lpthread -lm" \
--bindir="$BIN_PATH"\
$NCC_FFMPEG_LIB_OPTIONS
[ $? -eq 0 ] || build_die "$THIS: configure stage failed -> $SRC_NAME"
build_make $NCC_JOBS
fi
fi