-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_static_ffmpeg_centos-debian.sh
537 lines (439 loc) · 12.1 KB
/
build_static_ffmpeg_centos-debian.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
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
#!/bin/bash
set -e
# component revisions to check out:
vpx_rev="HEAD"
x264_rev="HEAD"
x265_rev="tip"
fdk_aac_rev="HEAD"
ffmpeg_rev="HEAD"
# each will be set to the actual commit sha (git describe --abbrev)
while (( $# > 0 )); do
case $1 in
--vpx-rev)
vpx_rev=$2
shift; shift;;
--x264-rev)
x264_rev=$2
shift; shift;;
--fdk_aac-rev)
fdk_aac_rev=$2
shift; shift;;
--x265-rev)
x265_rev=$2
shift; shift;;
--ffmpeg-rev)
ffmpeg_rev=$2
shift; shift;;
--help)
echo "
Build a static executable of ffmpeg, pulling the latest (or specific) revisions of
x264, x265, fdk_aac, vpx. Revisions (see revisions(7), hg()) can be specified with:
--vpx-rev REV
--x264-rev REV
--x265-rev REV
--fdk_aac-rev REV
--ffmpeg-rev REV
"
exit 0
;;
esac
done
echo "
Building ffmpeg with components at revisions:
libvpx: $vpx_rev
x264: $x264_rev
x265: $x265_rev
fdk_aac: $fdk_aac_rev
ffmpeg: $ffmpeg_rev
"
PREFIX="$(pwd)/ffmpeg_build"
PATH=$HOME/bin:$PATH
common_config_options="--enable-static --disable-shared"
# this needs to be exported for opus.pc to be found. No idea why.
export CFLAGS="$CFLAGS -fPIC" CXXFLAGS="$CFLAGS"
export LDFLAGS="$LDFLAGS -L$PREFIX/lib"
export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig"
mkdir -p ffmpeg_sources ffmpeg_build ~/bin
function do_yum {
sudo -nl yum 2&>1 >/dev/null || { echo "
This script needs to run \`sudo yum\`.
One way to enable the user running this script to do this is by adding a file in /etc/sudoers.d/ with the following contents:
Cmnd_Alias PKG_MANAGERS = /bin/yum
`whoami` ALL=(ALL) NOPASSWD: PKG_MANAGERS
"; exit 1; }
sudo -n yum -y update
sudo -n yum -y upgrade
sudo -n yum install -y \
epel-release
sudo -n yum remove -y \
nasm yasm # these are too old wrt ffmpeg requirements: we will have to build them from sources
sudo -n yum install -y \
autoconf automake bzip2 cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel \
libass-devel \
SDL SDL-devel \
libva-devel \
libvdpau-devel \
libxcb-devel \
libXfixes-devel
}
function do_apt {
sudo -nl apt-get 2&>1 >/dev/null || { echo "
This script needs to run \`sudo apt-get\`.
One way to enable the user running this script to do this is by adding a file in /etc/sudoers.d/ with the following contents:
Cmnd_Alias PKG_MANAGERS = /usr/bin/apt-get
$(whoami) ALL=(ALL) NOPASSWD: PKG_MANAGERS
(Do \`apt-get install sudo\` if necessay.)
"; exit 1; }
sudo -n apt-get update -y
sudo -n apt-get upgrade -y
sudo -n apt-get remove -y \
nasm yasm # these are too old wrt ffmpeg requirements: we will have to build them from sources
sudo -n apt-get install -y \
autoconf automake build-essential libtool pkg-config texinfo cmake git mercurial curl \
libass-dev \
libfreetype6-dev \
libsdl2-dev \
libtheora-dev \
libva-dev \
libvdpau-dev \
libvorbis-dev \
libxcb1-dev \
libxcb-shm0-dev \
libxcb-xfixes0-dev \
zlib1g-dev
}
function install_yasm {
local s=yasm-1.3.0
local t=$s.tar.gz
(cd ffmpeg_sources
curl -O -L http://www.tortall.net/projects/yasm/releases/$t
tar xzf $t
(cd $s
./configure --prefix="$PREFIX" --bindir="$HOME/bin"
make
make install)
rm -rf $s)
}
function install_nasm {
local s=nasm-2.13.02
local t=$s.tar.bz2
(cd ffmpeg_sources
curl -O -L http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/$t
tar xjf $t
(cd $s
./autogen.sh
./configure --prefix="$PREFIX" --bindir="$HOME/bin"
make
make install)
rm -rf $s)
}
function is_version_ok {
(IFS="."
local v=($1) req=($2)
if (( ${v[0]} < ${req[0]} )); then false; else
if (( ${v[0]} > ${req[0]} )); then true; else
if (( ${v[1]} < ${req[1]} )); then false; else
if (( ${v[1]} > ${req[1]} )); then true; else
if test -n "${v[2]}" && (( ${v[2]} < ${req[2]} )); then false; else
true
fi
fi
fi
fi
fi)
}
function check_yasm {
if which yasm >/dev/null 2>&1; then
local v=$(yasm --version | awk '/^yasm / { print $2 }')
if is_version_ok "$v" "1.3.0"; then
echo "found yasm version $v"
else
echo "found yasm version $v, which is too old"
false
fi
else
echo "yasm not found"
false
fi
}
function check_nasm {
if which nasm >/dev/null 2>&1; then
local v=$(nasm --version | awk '/^NASM / { print $3 }')
if is_version_ok "$v" "2.13.0"; then
echo "found nasm version $v"
else
echo "found nasm version $v, which is too old"
false
fi
else
echo "nasm not found"
false
fi
}
function check_lame {
if which lame >/dev/null 2>&1; then
local v=$(lame --version | awk '/^LAME / { print $4 }')
if is_version_ok "$v" "3.100"; then
echo "found lame version $v"
else
echo "found lame version $v, which is too old"
false
fi
else
echo "lame not found"
false
fi
}
function check_opus {
local v=$(pkg-config --modversion opus)
if test -n "$v"; then
if is_version_ok "$v" "1.2.1"; then
echo "found opus version $v"
else
echo "found opus version $v, which is too old"
false
fi
else
echo "opus not found"
false
fi
}
function check_libogg {
local v=$(pkg-config --modversion ogg)
if test -n "$v"; then
if is_version_ok "$v" "1.3.3"; then
echo "found ogg version $v"
else
echo "found ogg version $v, which is too old"
false
fi
else
echo "ogg not found"
false
fi
}
function check_libvorbis {
local v=$(pkg-config --modversion vorbis)
if test -n "$v"; then
if is_version_ok "$v" "1.3.5"; then
echo "found vorbis version $v"
else
echo "found vorbis version $v, which is too old"
false
fi
else
echo "vorbis not found"
false
fi
}
function build_lame {
echo "
- - - - lame"
if check_lame; then
true
else
local s="lame-3.100"
local t=$s.tar.gz
(cd ffmpeg_sources
test -r "$t" || curl -O -L http://downloads.sourceforge.net/project/lame/lame/3.100/$t
test -d $s || tar xzf $t
(cd $s
./configure --prefix="$PREFIX" --bindir="$HOME/bin" --enable-nasm $common_config_options
make $MAKEOPTS
make install)
rm -rf $s)
fi
}
function build_opus {
echo "
- - - - opus"
if check_opus; then
true
else
local s="opus-1.2.1"
local t=$s.tar.gz
(cd ffmpeg_sources
test -r "$t" || curl -O -L https://archive.mozilla.org/pub/opus/$t
test -d $s || tar xzf $t
(cd $s
./configure --prefix="$PREFIX" $common_config_options
make $MAKEOPTS
make install)
rm -rf $s)
fi
}
function build_libogg {
echo "
- - - - libogg"
if check_libogg; then
true
else
local s="libogg-1.3.3"
local t=$s.tar.gz
(cd ffmpeg_sources
test -r "$t" || curl -O -L http://downloads.xiph.org/releases/ogg/$t
test -d $s || tar xzf $t
(cd $s
./configure --prefix="$PREFIX" --bindir="$HOME/bin" $common_config_options
make $MAKEOPTS
make install)
rm -rf $s)
fi
}
function build_libvorbis {
echo "
- - - - libvorbis"
if check_libvorbis; then
true
else
local s="libvorbis-1.3.5"
local t=$s.tar.gz
(cd ffmpeg_sources
test -r "$t" || curl -O -L http://downloads.xiph.org/releases/vorbis/$t
test -d $s || tar xzf $t
(cd $s
./configure --prefix="$PREFIX" --bindir="$HOME/bin" $common_config_options
make $MAKEOPTS
make install)
rm -rf $s)
fi
}
## pull specific versions for the builds below
function build_x264 {
echo "
- - - - x264"
local d=x264
cd ffmpeg_sources
if test -d $d; then
cd $d
git pull
make distclean || :
else
git clone https://code.videolan.org/videolan/x264.git
cd $d
fi
git checkout "$x264_rev" || return 1
export x264_rev=$(git describe --always --abbrev HEAD)
./configure --prefix="$PREFIX" --bindir="$HOME/bin" --disable-cli --enable-pic $common_config_options
make $MAKEOPTS && make install && cd ../..
}
function build_x265 {
echo "
- - - - x265"
local d=x265
cd ffmpeg_sources
if test -d $d; then
cd $d
rm -rf build/linux/*
else
hg clone https://bitbucket.org/multicoreware/x265
cd $d
fi
hg update -r "$x265_rev"
export x265_rev=$(hg id --id)
cd build/linux
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$PREFIX" -DENABLE_SHARED:bool=off ../../source
make $MAKEOPTS && make install && mv $PREFIX/bin/x265 $HOME/bin && rmdir $PREFIX/bin && cd ../../..
}
function build_fdk {
echo "
- - - - fdk_aac"
local d=fdk-aac
cd ffmpeg_sources
if test -d $d; then
cd $d
git pull
make distclean || :
else
git clone https://github.com/mstorsjo/fdk-aac
cd $d
fi
git checkout "$fdk_aac_rev" || return 1
fdk_aac_rev=$(git describe --always --abbrev HEAD)
autoreconf -fiv
./configure --prefix="$PREFIX" $common_config_options
make $MAKEOPTS && make install && cd ../..
}
function build_vpx {
echo "
- - - - vpx"
local d=libvpx
cd ffmpeg_sources
if test -d $d; then
cd $d
git pull
make distclean || :
else
git clone https://chromium.googlesource.com/webm/libvpx.git
cd $d
fi
git checkout "$vpx_rev" || return 1
export vpx_rev=$(git describe --always --abbrev HEAD)
./configure --prefix="$PREFIX" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-pic $common_config_options
make $MAKEOPTS && make install && cd ../..
}
function build_ffmpeg {
echo "
- - - - ffmpeg
"
local d=ffmpeg
cd ffmpeg_sources
if test -d $d; then
cd $d
git pull
make distclean || :
else
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd $d
fi
git checkout "$ffmpeg_rev" || return 1
export ffmpeg_rev=$(git describe --always --abbrev HEAD)
./configure \
--prefix="$PREFIX" \
--pkg-config-flags="--static" \
--extra-libs="-lm -lpthread" \
--enable-pic \
--bindir="$HOME/bin" \
--extra-cflags="-I$PREFIX/include -static" \
--enable-gpl \
--enable-libass \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libvorbis \
--enable-libvpx \
--enable-libfdk_aac \
--enable-libfdk-aac \
--enable-libx264 \
--enable-nonfree \
--enable-static
make $MAKEOPTS && make install &&
echo "
Build successfully completed: ffmpeg installed in $PREFIX
" && cd ../..
}
test -r /etc/redhat-release && do_yum
test -r /etc/debian_version && do_apt
check_yasm || install_yasm || { echo "Failed to build yasm"; exit 3; }
check_nasm || install_nasm || { echo "Failed to build nasm"; exit 3; }
# these are at static versions
build_lame
build_opus
build_libogg
build_libvorbis
# some others are pulled newest
build_x264 || exit 2
build_x265 || exit 2
build_fdk || exit 2
build_vpx || exit 2
build_ffmpeg || exit 2
echo
ffmpeg -version || exit 4
echo "
ffmpeg binary successfully built with these components:
libvpx: $vpx_rev
x264: $x264_rev
x265: $x265_rev
fdk_aac: $fdk_aac_rev
ffmpeg: $ffmpeg_rev
"