forked from markus-perl/ffmpeg-build-script
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build-ffmpeg
executable file
·446 lines (377 loc) · 13.5 KB
/
build-ffmpeg
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
#!/bin/bash
# Enhanced version of https://github.com/rtgoodwin/ffmpeg-build-script-plus-frei0r-freetype and its source https://github.com/markus-perl/ffmpeg-build-script
# Version 0.8zb2
CWD=$(pwd)
PACKAGES="$CWD/packages"
WORKSPACE="$CWD/workspace"
CC=clang
LDFLAGS="-L${WORKSPACE}/lib -lm"
CFLAGS="-I${WORKSPACE}/include"
PKG_CONFIG_PATH="${WORKSPACE}/lib/pkgconfig"
# Speed up the process
# Env Var NUMJOBS overrides automatic detection
if [[ -n $NUMJOBS ]]; then
MJOBS=$NUMJOBS
elif [[ -f /proc/cpuinfo ]]; then
MJOBS=$(grep -c processor /proc/cpuinfo)
elif [[ "$OSTYPE" == "darwin"* ]]; then
MJOBS=$(sysctl -n machdep.cpu.thread_count)
else
MJOBS=4
fi
make_dir () {
if [ ! -d $1 ]; then
if ! mkdir $1; then
printf "\n Failed to create dir %s" "$1";
exit 1
fi
fi
}
remove_dir () {
if [ -d $1 ]; then
rm -r "$1"
fi
}
download () {
if [ ! -f "$PACKAGES/$2" ]; then
printf "Downloading $1"
curl -L --silent -o "$PACKAGES/$2" "$1"
EXITCODE=$?
if [ $EXITCODE -ne 0 ]; then
echo ""
echo "Failed to download $1. Exitcode $EXITCODE. Retrying in 10 seconds";
sleep 10
curl -L --silent -o "$PACKAGES/$2" "$1"
fi
EXITCODE=$?
if [ $EXITCODE -ne 0 ]; then
echo ""
echo "Failed to download $1. Exitcode $EXITCODE";
exit 1
fi
echo "... Done"
if ! tar -xvf "$PACKAGES/$2" -C "$PACKAGES" 2>/dev/null >/dev/null; then
echo "Failed to extract $2";
exit 1
fi
fi
}
execute () {
echo "$ $*"
if [[ ! $VERBOSE == "yes" ]]; then
OUTPUT="$($@ 2>&1)"
else
$@
fi
if [ $? -ne 0 ]; then
echo "$OUTPUT"
echo ""
echo "Failed to Execute $*" >&2
exit 1
fi
}
build () {
echo ""
echo "building $1"
echo "======================="
if [ -f "$PACKAGES/$1.done" ]; then
echo "$1 already built. Remove $PACKAGES/$1.done lockfile to rebuild it."
return 1
fi
return 0
}
command_exists() {
if ! [[ -x $(command -v "$1") ]]; then
return 1
fi
return 0
}
build_done () {
touch "$PACKAGES/$1.done"
}
echo "ffmpeg-build-script v$VERSION"
echo "========================="
echo ""
case "$1" in
"--cleanup")
remove_dir $PACKAGES
remove_dir $WORKSPACE
echo "Cleanup done."
echo ""
exit 0
;;
"--build")
;;
*)
echo "Usage: $0"
echo " --build: start building process"
echo " --cleanup: remove all working dirs"
echo " --help: show this help"
exit 0
;;
esac
echo "Using $MJOBS make jobs simultaneously."
make_dir $PACKAGES
make_dir $WORKSPACE
make_dir $CMPL
export PATH=${WORKSPACE}/bin:$PATH
if ! command_exists "make"; then
echo "make not installed.";
exit 1
fi
if ! command_exists "g++"; then
echo "g++ not installed.";
exit 1
fi
if ! command_exists "curl"; then
echo "curl not installed.";
exit 1
fi
if build "nasm"; then
download "http://www.nasm.us/pub/nasm/releasebuilds/2.13.01/nasm-2.13.01.tar.gz" "nasm-2.13.01.tar.gz"
cd $PACKAGES/nasm-2.13.01 || exit
execute ./configure --prefix=${WORKSPACE}
execute make -j $MJOBS
execute make install
build_done "nasm"
fi
if build "yasm"; then
download "http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz" "yasm-1.3.0.tar.gz"
cd $PACKAGES/yasm-1.3.0 || exit
execute ./configure --prefix=${WORKSPACE}
execute make -j $MJOBS
execute make install
build_done "yasm"
fi
if build "opencore"; then
download "http://downloads.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.5.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fopencore-amr%2Ffiles%2Fopencore-amr%2F&ts=1442256558&use_mirror=netassist" "opencore-amr-0.1.5.tar.gz"
cd $PACKAGES/opencore-amr-0.1.5 || exit
execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "opencore"
fi
if build "libvpx"; then
download "https://github.com/webmproject/libvpx/archive/v1.5.0.tar.gz" "libvpx-1.5.0.tar.gz"
cd $PACKAGES/libvpx* || exit
sed -e 's/cp -p/cp/' -i build/make/Makefile
execute ./configure --prefix=${WORKSPACE} --disable-unit-tests --disable-shared
execute make -j $MJOBS
execute make install
build_done "libvpx"
fi
if build "lame"; then
download "http://kent.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz" "lame-3.99.5.tar.gz"
cd $PACKAGES/lame-3.99.5 || exit
execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "lame"
fi
if build "xvidcore"; then
download "http://downloads.xvid.org/downloads/xvidcore-1.3.4.tar.gz" "xvidcore-1.3.4.tar.gz"
cd $PACKAGES/xvidcore || exit
cd build/generic || exit
execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static
execute make -j $MJOBS
execute make install
if [[ -f ${WORKSPACE}/lib/libxvidcore.4.dylib ]]; then
execute rm "${WORKSPACE}/lib/libxvidcore.4.dylib"
fi
build_done "xvidcore"
fi
if build "x264"; then
download "ftp://ftp.videolan.org/pub/x264/snapshots/x264-snapshot-20170328-2245.tar.bz2" "last_x264.tar.bz2"
cd $PACKAGES/x264-snapshot-* || exit
execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static
execute make -j $MJOBS
execute make install
execute make install-lib-static
build_done "x264"
fi
if build "libogg"; then
download "http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz" "libogg-1.3.2.tar.gz"
cd $PACKAGES/libogg-1.3.2 || exit
execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "libogg"
fi
if build "libvorbis"; then
download "http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz" "libvorbis-1.3.5.tar.gz"
cd $PACKAGES/libvorbis-1.3.5 || exit
execute ./configure --prefix=${WORKSPACE} --with-ogg-libraries=${WORKSPACE}/lib --with-ogg-includes=${WORKSPACE}/include/ --enable-static --disable-shared --disable-oggtest
execute make -j $MJOBS
execute make install
build_done "libvorbis"
fi
if build "libtheora"; then
download "http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz" "libtheora-1.1.1.tar.bz"
cd $PACKAGES/libtheora-1.1.1 || exit
sed "s/-fforce-addr//g" configure > configure.patched
chmod +x configure.patched
mv configure.patched configure
execute ./configure --prefix=${WORKSPACE} --with-ogg-libraries=${WORKSPACE}/lib --with-ogg-includes=${WORKSPACE}/include/ --with-vorbis-libraries=${WORKSPACE}/lib --with-vorbis-includes=${WORKSPACE}/include/ --enable-static --disable-shared --disable-oggtest --disable-vorbistest --disable-examples --disable-asm
execute make -j $MJOBS
execute make install
build_done "libtheora"
fi
if build "pkg-config"; then
download "http://pkgconfig.freedesktop.org/releases/pkg-config-0.29.1.tar.gz" "pkg-config-0.29.1.tar.gz"
cd $PACKAGES/pkg-config-0.29.1 || exit
execute ./configure --silent --prefix=${WORKSPACE} --with-pc-path=${WORKSPACE}/lib/pkgconfig --with-internal-glib
execute make -j $MJOBS
execute make install
build_done "pkg-config"
fi
if build "freetype"; then
download "http://download.savannah.gnu.org/releases/freetype/freetype-2.8.tar.gz" "freetype-2.8.tar.gz"
cd $PACKAGES/freet* || exit
execute ./configure --silent --prefix=${WORKSPACE} --with-pc-path=${WORKSPACE}/lib/pkgconfig --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "freetype"
fi
if build "fontconfig"; then
download "http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.11.94.tar.gz" "fontconfig-2.11.94.tar.gz"
cd $PACKAGES/fontc* || exit
execute ./configure --silent --prefix=${WORKSPACE} --with-pc-path=${WORKSPACE}/lib/pkgconfig --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "fontconfig"
fi
if build "cmake"; then
download "https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz" "cmake-3.5.2.tar.gz"
cd $PACKAGES/cmake* || exit
rm Modules/FindJava.cmake
perl -p -i -e "s/get_filename_component.JNIPATH/#get_filename_component(JNIPATH/g" Tests/CMakeLists.txt
perl -p -i -e "s/get_filename_component.JNIPATH/#get_filename_component(JNIPATH/g" Tests/CMakeLists.txt
execute ./configure --prefix=${WORKSPACE}
execute make -j $MJOBS
execute make install
build_done "cmake"
fi
if build "vid_stab"; then
download "https://codeload.github.com/georgmartius/vid.stab/legacy.tar.gz/release-0.98b" "vid.stab-0.98b-transcode-1.1-binary-x86_64.tgz"
cd $PACKAGES/georgmartius-vid* || exit
perl -p -i -e "s/vidstab SHARED/vidstab STATIC/" CMakeLists.txt
execute cmake -DCMAKE_INSTALL_PREFIX:PATH=${WORKSPACE} .
execute make install
build_done "vid_stab"
fi
if build "x265"; then
download "https://bitbucket.org/multicoreware/x265/downloads/x265_2.3.tar.gz" "x265-2.3tar.gz"
cd $PACKAGES/x265_* || exit
cd source || exit
execute cmake -DCMAKE_INSTALL_PREFIX:PATH=${WORKSPACE} -DENABLE_SHARED:bool=off .
execute make -j $MJOBS
execute make install
sed "s/-lx265/-lx265 -lstdc++/g" "$WORKSPACE/lib/pkgconfig/x265.pc" > "$WORKSPACE/lib/pkgconfig/x265.pc.tmp"
mv "$WORKSPACE/lib/pkgconfig/x265.pc.tmp" "$WORKSPACE/lib/pkgconfig/x265.pc"
build_done "x265"
fi
if build "fdk_aac"; then
download "http://downloads.sourceforge.net/project/opencore-amr/fdk-aac/fdk-aac-0.1.5.tar.gz?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fopencore-amr%2Ffiles%2Ffdk-aac%2F&ts=1457561564&use_mirror=kent" "fdk-aac-0.1.5.tar.gz"
cd $PACKAGES/fdk-aac* || exit
execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static
execute make -j $MJOBS
execute make install
build_done "fdk_aac"
fi
if build "frei0r"; then
download "https://files.dyne.org/frei0r/releases/frei0r-plugins-1.6.1.tar.gz" "frei0r-plugins-1.6.1.tar.gz"
cd $PACKAGES/frei0r* || exit
perl -p -i -e "s/OpenCV\" OFF/OpenCV\" ON/" CMakeLists.txt
execute cmake -DCMAKE_INSTALL_PREFIX:PATH=${WORKSPACE} .
execute make -s install
for file in ${WORKSPACE}/lib/frei0r-1/*.so ; do
cp $file "${file%.*}.dylib"
done
build_done "frei0r"
fi
build "ffmpeg"
download "http://ffmpeg.org/releases/ffmpeg-3.3.4.tar.bz2" "ffmpeg-3.3.4.tar.bz2"
cd $PACKAGES/ffmpeg* || exit
CFLAGS="-I$WORKSPACE/include `$WORKSPACE/bin/freetype-config --cflags` -I$WORKSPACE/include/vorbis" LDFLAGS="-L$WORKSPACE/lib `$WORKSPACE/bin/freetype-config --libs`"
# CFLAGS="-I$WORKSPACE/include" LDFLAGS="-L$WORKSPACE/lib"
execute ./configure --arch=64 --prefix=${WORKSPACE} \
--extra-cflags="-I$WORKSPACE/include" --extra-cflags="-I$WORKSPACE/include/vorbis" --extra-cflags="`$WORKSPACE/bin/freetype-config --cflags`" \
--extra-ldflags="-L$WORKSPACE/lib" --extra-version=static \
--disable-debug \
--disable-shared \
--enable-static \
--enable-libopencore_amrwb \
--enable-libopencore_amrnb \
--extra-cflags=--static \
--disable-ffplay \
--disable-ffserver \
--disable-doc \
--enable-gpl \
--enable-version3 \
--enable-nonfree \
--enable-pthreads \
--enable-libvpx \
--enable-libmp3lame \
--enable-libtheora \
--enable-libvorbis \
--enable-libx264 \
--enable-libx265 \
--enable-runtime-cpudetect \
--enable-libfdk-aac \
--enable-avfilter \
--enable-libopencore_amrwb \
--enable-libopencore_amrnb \
--enable-filters \
--enable-libvidstab \
--enable-frei0r \
--enable-indev=avfoundation
# enable all filters
# enable AAC de/encoding via libfdk-aac [no]
# enable detecting cpu capabilities at runtime (smaller binary)
# enable HEVC encoding via x265 [no]
# enable H.264 encoding via x264 [no]
# enable Vorbis en/decoding via libvorbis, native implementation exists [no]
# enable Theora encoding via libtheora [no]
# enable MP3 encoding via libmp3lame [no]
# enable VP8 and VP9 de/encoding via libvpx [no]
# enable pthreads [autodetect]
# allow use of nonfree code, the resulting libs and binaries will be unredistributable [no]
# upgrade (L)GPL to version 3 [no]
# allow use of GPL code, the resulting libs and binaries will be under GPL [no]
# do not build documentation
# disable ffserver build
# disable ffplay build
# build static libraries [no]
# disable debugging symbols
# disable build shared libraries [no]
execute make -j $MJOBS
execute make install
INSTALL_FOLDER="/usr/bin"
if [[ "$OSTYPE" == "darwin"* ]]; then
INSTALL_FOLDER="/usr/local/bin"
fi
echo ""
echo "Building done. The binary can be found here: $WORKSPACE/bin/ffmpeg"
echo ""
if [[ ! $SKIPINSTALL == "yes" ]]; then
if command_exists "sudo"; then
read -r -p "Install the binary to your $INSTALL_FOLDER folder? [Y/n] " response
case $response in
[yY][eE][sS]|[yY])
sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
echo "Done. ffmpeg is now installed to your system"
;;
esac
fi
fi
echo ""
echo "The frei0r plugins can be found here: $WORKSPACE/lib/ in a folder named \"frei0r-1\""
echo ""
read -r -p "Copy frei0r plugins to your /usr/local/lib/frei0r-1 folder [Y/n] " response
case $response in
[yY][eE][sS]|[yY])
sudo cp -Rv "$WORKSPACE/lib/frei0r-1" "/usr/local/lib/"
echo "Done. frei0r plugins are now installed to your system"
;;
esac