install-ffmpeg 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. #!/bin/bash
  2. # export http_proxy=http://192.168.0.144:7890 https_proxy=http://192.168.0.144:7890
  3. PROGNAME=$(basename "$0")
  4. VERSION=1.22
  5. CWD=$(pwd)
  6. PACKAGES="$CWD/packages"
  7. WORKSPACE="$CWD/workspace"
  8. CFLAGS="-I$WORKSPACE/include"
  9. LDFLAGS="-L$WORKSPACE/lib"
  10. LDEXEFLAGS=""
  11. EXTRALIBS="-ldl -lpthread -lm -lz"
  12. MACOS_M1=false
  13. CONFIGURE_OPTIONS=()
  14. # Check for Apple Silicon
  15. if [[ ("$(uname -m)" == "arm64") && ("$OSTYPE" == "darwin"*) ]]; then
  16. # If arm64 AND darwin (macOS)
  17. export ARCH=arm64
  18. export MACOSX_DEPLOYMENT_TARGET=11.0
  19. MACOS_M1=true
  20. fi
  21. # Speed up the process
  22. # Env Var NUMJOBS overrides automatic detection
  23. if [[ -n "$NUMJOBS" ]]; then
  24. MJOBS="$NUMJOBS"
  25. elif [[ -f /proc/cpuinfo ]]; then
  26. MJOBS=$(grep -c processor /proc/cpuinfo)
  27. elif [[ "$OSTYPE" == "darwin"* ]]; then
  28. MJOBS=$(sysctl -n machdep.cpu.thread_count)
  29. CONFIGURE_OPTIONS=("--enable-videotoolbox")
  30. else
  31. MJOBS=4
  32. fi
  33. make_dir() {
  34. remove_dir "$1"
  35. if ! mkdir "$1"; then
  36. printf "\n Failed to create dir %s" "$1"
  37. exit 1
  38. fi
  39. }
  40. remove_dir() {
  41. if [ -d "$1" ]; then
  42. rm -r "$1"
  43. fi
  44. }
  45. download() {
  46. # download url [filename[dirname]]
  47. DOWNLOAD_PATH="$PACKAGES"
  48. DOWNLOAD_FILE="${2:-"${1##*/}"}"
  49. if [[ "$DOWNLOAD_FILE" =~ tar. ]]; then
  50. TARGETDIR="${DOWNLOAD_FILE%.*}"
  51. TARGETDIR="${3:-"${TARGETDIR%.*}"}"
  52. else
  53. TARGETDIR="${3:-"${DOWNLOAD_FILE%.*}"}"
  54. fi
  55. if [ ! -f "$DOWNLOAD_PATH/$DOWNLOAD_FILE" ]; then
  56. echo "Downloading $1 as $DOWNLOAD_FILE"
  57. curl -L --silent -o "$DOWNLOAD_PATH/$DOWNLOAD_FILE" "$1"
  58. EXITCODE=$?
  59. if [ $EXITCODE -ne 0 ]; then
  60. echo ""
  61. echo "Failed to download $1. Exitcode $EXITCODE. Retrying in 10 seconds"
  62. sleep 10
  63. curl -L --silent -o "$DOWNLOAD_PATH/$DOWNLOAD_FILE" "$1"
  64. fi
  65. EXITCODE=$?
  66. if [ $EXITCODE -ne 0 ]; then
  67. echo ""
  68. echo "Failed to download $1. Exitcode $EXITCODE"
  69. exit 1
  70. fi
  71. echo "... Done"
  72. else
  73. echo "$DOWNLOAD_FILE has already downloaded."
  74. fi
  75. make_dir "$DOWNLOAD_PATH/$TARGETDIR"
  76. if [ -n "$3" ]; then
  77. if ! tar -xvf "$DOWNLOAD_PATH/$DOWNLOAD_FILE" -C "$DOWNLOAD_PATH/$TARGETDIR" 2>/dev/null >/dev/null; then
  78. echo "Failed to extract $DOWNLOAD_FILE"
  79. exit 1
  80. fi
  81. else
  82. if ! tar -xvf "$DOWNLOAD_PATH/$DOWNLOAD_FILE" -C "$DOWNLOAD_PATH/$TARGETDIR" --strip-components 1 2>/dev/null >/dev/null; then
  83. echo "Failed to extract $DOWNLOAD_FILE"
  84. exit 1
  85. fi
  86. fi
  87. echo "Extracted $DOWNLOAD_FILE"
  88. cd "$DOWNLOAD_PATH/$TARGETDIR" || (
  89. echo "Error has occurred."
  90. exit 1
  91. )
  92. }
  93. execute() {
  94. echo "$ $*"
  95. OUTPUT=$("$@" 2>&1)
  96. # shellcheck disable=SC2181
  97. if [ $? -ne 0 ]; then
  98. echo "$OUTPUT"
  99. echo ""
  100. echo "Failed to Execute $*" >&2
  101. exit 1
  102. fi
  103. }
  104. build() {
  105. echo ""
  106. echo "building $1"
  107. echo "======================="
  108. if [ -f "$PACKAGES/$1.done" ]; then
  109. echo "$1 already built. Remove $PACKAGES/$1.done lockfile to rebuild it."
  110. return 1
  111. fi
  112. return 0
  113. }
  114. command_exists() {
  115. if ! [[ -x $(command -v "$1") ]]; then
  116. return 1
  117. fi
  118. return 0
  119. }
  120. library_exists() {
  121. if ! [[ -x $(pkg-config --exists --print-errors "$1" 2>&1 >/dev/null) ]]; then
  122. return 1
  123. fi
  124. return 0
  125. }
  126. build_done() {
  127. touch "$PACKAGES/$1.done"
  128. }
  129. verify_binary_type() {
  130. BINARY_TYPE=$(file "$WORKSPACE/bin/ffmpeg" | sed -n 's/^.*\:\ \(.*$\)/\1/p')
  131. echo ""
  132. case $BINARY_TYPE in
  133. "Mach-O 64-bit executable arm64")
  134. echo "Successfully built Apple Silicon (M1) for ${OSTYPE}: ${BINARY_TYPE}"
  135. ;;
  136. *)
  137. echo "Successfully built binary for ${OSTYPE}: ${BINARY_TYPE}"
  138. ;;
  139. esac
  140. }
  141. cleanup() {
  142. remove_dir "$PACKAGES"
  143. remove_dir "$WORKSPACE"
  144. echo "Cleanup done."
  145. echo ""
  146. }
  147. usage() {
  148. echo "Usage: $PROGNAME [OPTIONS]"
  149. echo "Options:"
  150. echo " -h, --help Display usage information"
  151. echo " --version Display version information"
  152. echo " -b, --build Starts the build process"
  153. echo " -c, --cleanup Remove all working dirs"
  154. echo " -f, --full-static Build a full static FFmpeg binary (eg. glibc, pthreads etc...) **only Linux**"
  155. echo " Note: Because of the NSS (Name Service Switch), glibc does not recommend static links."
  156. echo ""
  157. }
  158. while (($# > 0)); do
  159. case $1 in
  160. -h | --help)
  161. usage
  162. exit 0
  163. ;;
  164. --version)
  165. echo "$VERSION"
  166. exit 0
  167. ;;
  168. -*)
  169. if [[ "$1" == "--build" || "$1" =~ 'b' ]]; then
  170. bflag='-b'
  171. fi
  172. if [[ "$1" == "--cleanup" || "$1" =~ 'c' && ! "$1" =~ '--' ]]; then
  173. cflag='-c'
  174. cleanup
  175. fi
  176. if [[ "$1" == "--full-static" || "$1" =~ 'f' ]]; then
  177. if [[ "$OSTYPE" == "darwin"* ]]; then
  178. echo "Error: A full static binary can only be build on Linux."
  179. exit 1
  180. fi
  181. LDEXEFLAGS="-static"
  182. fi
  183. shift
  184. ;;
  185. *)
  186. usage
  187. exit 1
  188. ;;
  189. esac
  190. done
  191. echo "ffmpeg-build-script v$VERSION"
  192. echo "========================="
  193. echo ""
  194. if [ -z "$bflag" ]; then
  195. if [ -z "$cflag" ]; then
  196. usage
  197. exit 1
  198. fi
  199. exit 0
  200. fi
  201. echo "Using $MJOBS make jobs simultaneously."
  202. if [ -n "$LDEXEFLAGS" ]; then
  203. echo "Start the build in full static mode."
  204. fi
  205. mkdir -p "$PACKAGES"
  206. mkdir -p "$WORKSPACE"
  207. export PATH="${WORKSPACE}/bin:$PATH"
  208. PKG_CONFIG_PATH="/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig"
  209. PKG_CONFIG_PATH+=":/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib64/pkgconfig"
  210. export PKG_CONFIG_PATH
  211. buildEssentialLib() {
  212. sudo apt-get install -y build-essential pkg-config autoconf m4 libtool curl -y
  213. }
  214. buildEssentialLib
  215. if ! command_exists "make"; then
  216. echo "make not installed."
  217. exit 1
  218. fi
  219. if ! command_exists "g++"; then
  220. echo "g++ not installed."
  221. exit 1
  222. fi
  223. if ! command_exists "curl"; then
  224. echo "curl not installed."
  225. exit 1
  226. fi
  227. if ! command_exists "python"; then
  228. echo "Python command not found. Lv2 filter will not be available."
  229. fi
  230. ##
  231. ## build tools
  232. ##
  233. if build "pkg-config"; then
  234. download "https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz"
  235. execute ./configure --silent --prefix="${WORKSPACE}" --with-pc-path="${WORKSPACE}"/lib/pkgconfig --with-internal-glib
  236. execute make -j $MJOBS
  237. execute make install
  238. build_done "pkg-config"
  239. fi
  240. if command_exists "python"; then
  241. if build "lv2"; then
  242. download "https://lv2plug.in/spec/lv2-1.18.0.tar.bz2" "lv2-1.18.0.tar.bz2"
  243. execute ./waf configure --prefix="${WORKSPACE}" --lv2-user
  244. execute ./waf
  245. execute ./waf install
  246. build_done "lv2"
  247. fi
  248. if build "waflib"; then
  249. download "https://gitlab.com/drobilla/autowaf/-/archive/cc37724b9bfa889baebd8cb10f38b8c7cab83e37/autowaf-cc37724b9bfa889baebd8cb10f38b8c7cab83e37.tar.gz" "autowaf.tar.gz"
  250. build_done "waflib"
  251. fi
  252. if build "serd"; then
  253. download "https://gitlab.com/drobilla/serd/-/archive/v0.30.6/serd-v0.30.6.tar.gz" "serd-v0.30.6.tar.gz"
  254. execute cp -r "${PACKAGES}"/autowaf/* "${PACKAGES}/serd-v0.30.6/waflib/"
  255. execute ./waf configure --prefix="${WORKSPACE}" --static --no-shared --no-posix
  256. execute ./waf
  257. execute ./waf install
  258. build_done "serd"
  259. fi
  260. if build "pcre"; then
  261. download "https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz" "pcre-8.44.tar.gz"
  262. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  263. execute make -j $MJOBS
  264. execute make install
  265. build_done "pcre"
  266. fi
  267. if build "sord"; then
  268. download "https://gitlab.com/drobilla/sord/-/archive/v0.16.6/sord-v0.16.6.tar.gz" "sord-v0.16.6.tar.gz"
  269. execute cp -r "${PACKAGES}"/autowaf/* "${PACKAGES}/sord-v0.16.6/waflib/"
  270. execute ./waf configure --prefix="${WORKSPACE}" CFLAGS="${CFLAGS}" --static --no-shared --no-utils
  271. execute ./waf CFLAGS="${CFLAGS}"
  272. execute ./waf install
  273. build_done "sord"
  274. fi
  275. if build "sratom"; then
  276. download "https://gitlab.com/lv2/sratom/-/archive/v0.6.6/sratom-v0.6.6.tar.gz" "sratom-v0.6.6.tar.gz"
  277. execute cp -r "${PACKAGES}"/autowaf/* "${PACKAGES}/sratom-v0.6.6/waflib/"
  278. execute ./waf configure --prefix="${WORKSPACE}" --static --no-shared
  279. execute ./waf
  280. execute ./waf install
  281. build_done "sratom"
  282. fi
  283. if build "lilv"; then
  284. download "https://gitlab.com/lv2/lilv/-/archive/v0.24.10/lilv-v0.24.10.tar.gz" "lilv-v0.24.10.tar.gz"
  285. execute cp -r "${PACKAGES}"/autowaf/* "${PACKAGES}/lilv-v0.24.10/waflib/"
  286. execute ./waf configure --prefix="${WORKSPACE}" --static --no-shared --no-utils
  287. execute ./waf
  288. execute ./waf install
  289. CFLAGS+=" -I$WORKSPACE/include/lilv-0"
  290. build_done "lilv"
  291. fi
  292. CONFIGURE_OPTIONS+=("--enable-lv2")
  293. fi
  294. if build "yasm"; then
  295. download "https://github.com/yasm/yasm/releases/download/v1.3.0/yasm-1.3.0.tar.gz"
  296. execute ./configure --prefix="${WORKSPACE}"
  297. execute make -j $MJOBS
  298. execute make install
  299. build_done "yasm"
  300. fi
  301. if build "nasm"; then
  302. download "https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.xz"
  303. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  304. execute make -j $MJOBS
  305. execute make install
  306. build_done "nasm"
  307. fi
  308. if build "zlib"; then
  309. download "https://www.zlib.net/zlib-1.2.11.tar.gz"
  310. execute ./configure --static --prefix="${WORKSPACE}"
  311. execute make -j $MJOBS
  312. execute make install
  313. build_done "zlib"
  314. fi
  315. if build "openssl"; then
  316. download "https://www.openssl.org/source/openssl-1.1.1i.tar.gz"
  317. if $MACOS_M1; then
  318. sed -n 's/\(##### GNU Hurd\)/"darwin64-arm64-cc" => { \n inherit_from => [ "darwin-common", asm("aarch64_asm") ],\n CFLAGS => add("-Wall"),\n cflags => add("-arch arm64 "),\n lib_cppflags => add("-DL_ENDIAN"),\n bn_ops => "SIXTY_FOUR_BIT_LONG", \n perlasm_scheme => "macosx", \n}, \n\1/g' Configurations/10-main.conf
  319. execute ./configure --prefix="${WORKSPACE}" no-shared no-asm darwin64-arm64-cc
  320. else
  321. execute ./config --prefix="${WORKSPACE}" --openssldir="${WORKSPACE}" --with-zlib-include="${WORKSPACE}"/include/ --with-zlib-lib="${WORKSPACE}"/lib no-shared zlib
  322. fi
  323. execute make -j $MJOBS
  324. execute make install_sw
  325. build_done "openssl"
  326. fi
  327. CONFIGURE_OPTIONS+=("--enable-openssl")
  328. if build "cmake"; then
  329. download "https://cmake.org/files/v3.18/cmake-3.18.4.tar.gz"
  330. execute ./configure --prefix="${WORKSPACE}" --system-zlib
  331. execute make -j $MJOBS
  332. execute make install
  333. build_done "cmake"
  334. fi
  335. if build "svtav1"; then
  336. download "https://github.com/AOMediaCodec/SVT-AV1/archive/v0.8.6.tar.gz"
  337. cd Build/linux || exit
  338. execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DENABLE_SHARED=off -DBUILD_SHARED_LIBS=OFF ../.. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
  339. execute make -j $MJOBS
  340. execute make install
  341. execute cp SvtAv1Enc.pc "${WORKSPACE}/lib/pkgconfig/"
  342. execute cp SvtAv1Dec.pc "${WORKSPACE}/lib/pkgconfig/"
  343. build_done "svtav1"
  344. fi
  345. CONFIGURE_OPTIONS+=("--enable-libsvtav1")
  346. ##
  347. ## video library
  348. ##
  349. if build "x264"; then
  350. download "https://code.videolan.org/videolan/x264/-/archive/0d754ec36013fee82978496cd56fbd48824910b3/x264-0d754ec36013fee82978496cd56fbd48824910b3.tar.gz" "x264-0d754ec.tar.gz"
  351. cd "${PACKAGES}"/x264-0d754ec || exit
  352. if [[ "$OSTYPE" == "linux-gnu" ]]; then
  353. execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic CXXFLAGS="-fPIC"
  354. else
  355. execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic
  356. fi
  357. execute make -j $MJOBS
  358. execute make install
  359. execute make install-lib-static
  360. build_done "x264"
  361. fi
  362. CONFIGURE_OPTIONS+=("--enable-libx264")
  363. if build "x265"; then
  364. download "https://github.com/videolan/x265/archive/Release_3.5.tar.gz" "x265-3.5.tar.gz"
  365. cd build/linux || exit
  366. execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DENABLE_SHARED=off -DBUILD_SHARED_LIBS=OFF ../../source
  367. execute make -j $MJOBS
  368. execute make install
  369. if [ -n "$LDEXEFLAGS" ]; then
  370. sed -i.backup 's/-lgcc_s/-lgcc_eh/g' "${WORKSPACE}/lib/pkgconfig/x265.pc" # The -i.backup is intended and required on MacOS: https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux
  371. fi
  372. build_done "x265"
  373. fi
  374. CONFIGURE_OPTIONS+=("--enable-libx265")
  375. if build "libvpx"; then
  376. download "https://github.com/webmproject/libvpx/archive/v1.9.0.tar.gz" "libvpx-1.9.0.tar.gz"
  377. if [[ "$OSTYPE" == "darwin"* ]]; then
  378. echo "Applying Darwin patch"
  379. sed "s/,--version-script//g" build/make/Makefile >build/make/Makefile.patched
  380. sed "s/-Wl,--no-undefined -Wl,-soname/-Wl,-undefined,error -Wl,-install_name/g" build/make/Makefile.patched >build/make/Makefile
  381. fi
  382. execute ./configure --prefix="${WORKSPACE}" --disable-unit-tests --disable-shared --as=yasm
  383. execute make -j $MJOBS
  384. execute make install
  385. build_done "libvpx"
  386. fi
  387. CONFIGURE_OPTIONS+=("--enable-libvpx")
  388. if build "xvidcore"; then
  389. download "http://fossies.org/linux/misc/xvidcore-1.3.7.tar.gz"
  390. cd build/generic || exit
  391. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  392. execute make -j $MJOBS
  393. execute make install
  394. if [[ -f ${WORKSPACE}/lib/libxvidcore.4.dylib ]]; then
  395. execute rm "${WORKSPACE}/lib/libxvidcore.4.dylib"
  396. fi
  397. if [[ -f ${WORKSPACE}/lib/libxvidcore.so ]]; then
  398. execute rm "${WORKSPACE}"/lib/libxvidcore.so*
  399. fi
  400. build_done "xvidcore"
  401. fi
  402. CONFIGURE_OPTIONS+=("--enable-libxvid")
  403. if build "vid_stab"; then
  404. download "https://github.com/georgmartius/vid.stab/archive/v1.1.0.tar.gz" "vid.stab-1.1.0.tar.gz"
  405. if $MACOS_M1; then
  406. curl -s -o "$PACKAGES/vid.stab-1.1.0/fix_cmake_quoting.patch" https://raw.githubusercontent.com/Homebrew/formula-patches/5bf1a0e0cfe666ee410305cece9c9c755641bfdf/libvidstab/fix_cmake_quoting.patch
  407. patch -p1 <fix_cmake_quoting.patch
  408. fi
  409. execute cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DUSE_OMP=OFF -DENABLE_SHARED=off .
  410. execute make
  411. execute make install
  412. build_done "vid_stab"
  413. fi
  414. CONFIGURE_OPTIONS+=("--enable-libvidstab")
  415. if build "av1"; then
  416. # download "https://aomedia.googlesource.com/aom/+archive/b52ee6d44adaef8a08f6984390de050d64df9faa.tar.gz" "av1.tar.gz" "av1"
  417. download "https://www.andrews-corner.org/downloads/aom-b52ee6d44adaef8a08f6984390de050d64df9faa.tar.gz" "av1.tar.gz" "av1"
  418. make_dir "$PACKAGES"/aom_build
  419. cd "$PACKAGES"/aom_build || exit
  420. if $MACOS_M1; then
  421. execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib -DCONFIG_RUNTIME_CPU_DETECT=0 "$PACKAGES"/av1
  422. else
  423. execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib "$PACKAGES"/av1
  424. fi
  425. execute make -j $MJOBS
  426. execute make install
  427. build_done "av1"
  428. fi
  429. CONFIGURE_OPTIONS+=("--enable-libaom")
  430. ##
  431. ## audio library
  432. ##
  433. if build "opencore"; then
  434. download "https://deac-riga.dl.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.5.tar.gz"
  435. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  436. execute make -j $MJOBS
  437. execute make install
  438. build_done "opencore"
  439. fi
  440. CONFIGURE_OPTIONS+=("--enable-libopencore_amrnb" "--enable-libopencore_amrwb")
  441. if build "lame"; then
  442. download "https://fossies.org/linux/misc/lame-3.100.tar.gz"
  443. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  444. execute make -j $MJOBS
  445. execute make install
  446. build_done "lame"
  447. fi
  448. CONFIGURE_OPTIONS+=("--enable-libmp3lame")
  449. if build "opus"; then
  450. download "https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz"
  451. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  452. execute make -j $MJOBS
  453. execute make install
  454. build_done "opus"
  455. fi
  456. CONFIGURE_OPTIONS+=("--enable-libopus")
  457. if build "libogg"; then
  458. download "https://ftp.osuosl.org/pub/xiph/releases/ogg/libogg-1.3.3.tar.gz"
  459. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  460. execute make -j $MJOBS
  461. execute make install
  462. build_done "libogg"
  463. fi
  464. if build "libvorbis"; then
  465. download "https://ftp.osuosl.org/pub/xiph/releases/vorbis/libvorbis-1.3.6.tar.gz"
  466. execute ./configure --prefix="${WORKSPACE}" --with-ogg-libraries="${WORKSPACE}"/lib --with-ogg-includes="${WORKSPACE}"/include/ --enable-static --disable-shared --disable-oggtest
  467. execute make -j $MJOBS
  468. execute make install
  469. build_done "libvorbis"
  470. fi
  471. CONFIGURE_OPTIONS+=("--enable-libvorbis")
  472. if build "libtheora"; then
  473. download "https://ftp.osuosl.org/pub/xiph/releases/theora/libtheora-1.1.1.tar.gz"
  474. sed "s/-fforce-addr//g" configure >configure.patched
  475. chmod +x configure.patched
  476. mv configure.patched configure
  477. 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 --disable-spec
  478. execute make -j $MJOBS
  479. execute make install
  480. build_done "libtheora"
  481. fi
  482. CONFIGURE_OPTIONS+=("--enable-libtheora")
  483. if build "fdk_aac"; then
  484. download "https://sourceforge.net/projects/opencore-amr/files/fdk-aac/fdk-aac-2.0.1.tar.gz/download?use_mirror=gigenet" "fdk-aac-2.0.1.tar.gz"
  485. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  486. execute make -j $MJOBS
  487. execute make install
  488. build_done "fdk_aac"
  489. fi
  490. CONFIGURE_OPTIONS+=("--enable-libfdk-aac")
  491. ##
  492. ## image library
  493. ##
  494. if build "libwebp"; then
  495. download "https://github.com/webmproject/libwebp/archive/v1.1.0.tar.gz" "libwebp-1.1.0.tar.gz"
  496. make_dir build
  497. cd build || exit
  498. execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_BINDIR=bin -DCMAKE_INSTALL_INCLUDEDIR=include -DENABLE_SHARED=OFF -DENABLE_STATIC=ON ../
  499. execute make -j $MJOBS
  500. execute make install
  501. build_done "libwebp"
  502. fi
  503. CONFIGURE_OPTIONS+=("--enable-libwebp")
  504. ##
  505. ## other library
  506. ##
  507. if build "libsdl"; then
  508. download "https://www.libsdl.org/release/SDL2-2.0.14.tar.gz"
  509. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  510. execute make -j $MJOBS
  511. execute make install
  512. build_done "libsdl"
  513. fi
  514. if build "srt"; then
  515. download "https://github.com/Haivision/srt/archive/v1.4.1.tar.gz" "srt-1.4.1.tar.gz"
  516. export OPENSSL_ROOT_DIR="${WORKSPACE}"
  517. export OPENSSL_LIB_DIR="${WORKSPACE}"/lib
  518. export OPENSSL_INCLUDE_DIR="${WORKSPACE}"/include/
  519. execute cmake . -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_BINDIR=bin -DCMAKE_INSTALL_INCLUDEDIR=include -DENABLE_SHARED=OFF -DENABLE_STATIC=ON -DENABLE_APPS=OFF -DUSE_STATIC_LIBSTDCXX=ON
  520. execute make install
  521. if [ -n "$LDEXEFLAGS" ]; then
  522. sed -i.backup 's/-lgcc_s/-lgcc_eh/g' "${WORKSPACE}"/lib/pkgconfig/srt.pc # The -i.backup is intended and required on MacOS: https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux
  523. fi
  524. build_done "srt"
  525. fi
  526. # ERROR: srt >= 1.3.0 not found using pkg-config temp hide
  527. CONFIGURE_OPTIONS+=("--enable-libsrt")
  528. ##
  529. ## HWaccel library
  530. ##
  531. # if [[ "$OSTYPE" == "linux-gnu" ]]; then
  532. # if command_exists "nvcc"; then
  533. # if build "nv-codec"; then
  534. # download "https://github.com/FFmpeg/nv-codec-headers/releases/download/n11.0.10.0/nv-codec-headers-11.0.10.0.tar.gz"
  535. # execute make PREFIX="${WORKSPACE}"
  536. # execute make install PREFIX="${WORKSPACE}"
  537. # build_done "nv-codec"
  538. # fi
  539. # CFLAGS+=" -I/usr/local/cuda/include"
  540. # LDFLAGS+=" -L/usr/local/cuda/lib64"
  541. # CONFIGURE_OPTIONS+=("--enable-cuda-nvcc" "--enable-cuvid" "--enable-nvenc" "--enable-cuda-llvm")
  542. # if [ -z "$LDEXEFLAGS" ]; then
  543. # CONFIGURE_OPTIONS+=("--enable-libnpp") # Only libnpp cannot be statically linked.
  544. # fi
  545. # # https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/
  546. # CONFIGURE_OPTIONS+=("--nvccflags=-gencode arch=compute_52,code=sm_52")
  547. # fi
  548. # # Vaapi doesn't work well with static links FFmpeg.
  549. # if [ -z "$LDEXEFLAGS" ]; then
  550. # # If the libva development SDK is installed, enable vaapi.
  551. # if library_exists "libva"; then
  552. # if build "vaapi"; then
  553. # build_done "vaapi"
  554. # fi
  555. # CONFIGURE_OPTIONS+=("--enable-vaapi")
  556. # fi
  557. # fi
  558. # fi
  559. ##
  560. ## FFmpeg
  561. ##
  562. build "ffmpeg"
  563. download "https://git.ffmpeg.org/gitweb/ffmpeg.git/snapshot/553eb0773763798a6b9656b621cb125e1f6edbcc.tar.gz"
  564. # shellcheck disable=SC2086
  565. ./configure "${CONFIGURE_OPTIONS[@]}" \
  566. --disable-debug \
  567. --disable-doc \
  568. --disable-shared \
  569. --enable-gpl \
  570. --enable-nonfree \
  571. --enable-pthreads \
  572. --enable-static \
  573. --enable-small \
  574. --enable-version3 \
  575. --extra-cflags="${CFLAGS}" \
  576. --extra-ldexeflags="${LDEXEFLAGS}" \
  577. --extra-ldflags="${LDFLAGS}" \
  578. --extra-libs="${EXTRALIBS}" \
  579. --pkgconfigdir="$WORKSPACE/lib/pkgconfig" \
  580. --pkg-config-flags="--static" \
  581. --prefix="${WORKSPACE}"
  582. execute make -j $MJOBS
  583. execute make install
  584. INSTALL_FOLDER="/usr/bin"
  585. if [[ "$OSTYPE" == "darwin"* ]]; then
  586. INSTALL_FOLDER="/usr/local/bin"
  587. fi
  588. verify_binary_type
  589. echo ""
  590. echo "Building done. The following binaries can be found here:"
  591. echo "- ffmpeg: $WORKSPACE/bin/ffmpeg"
  592. echo "- ffprobe: $WORKSPACE/bin/ffprobe"
  593. echo "- ffplay: $WORKSPACE/bin/ffplay"
  594. echo ""
  595. if [[ "$AUTOINSTALL" == "yes" ]]; then
  596. if command_exists "sudo"; then
  597. sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
  598. sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
  599. sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
  600. echo "Done. FFmpeg is now installed to your system."
  601. else
  602. cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
  603. cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
  604. sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
  605. echo "Done. FFmpeg is now installed to your system."
  606. fi
  607. elif [[ ! "$SKIPINSTALL" == "yes" ]]; then
  608. read -r -p "Install these binaries to your $INSTALL_FOLDER folder? Existing binaries will be replaced. [Y/n] " response
  609. case $response in
  610. [yY][eE][sS] | [yY])
  611. if command_exists "sudo"; then
  612. sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
  613. sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
  614. sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
  615. else
  616. cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
  617. cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
  618. cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
  619. fi
  620. echo "Done. FFmpeg is now installed to your system."
  621. ;;
  622. esac
  623. fi
  624. ##
  625. ## build lv2 speech-denoiser
  626. ##
  627. build "speech-denoiser"
  628. if ! command_exists "git"; then
  629. sudo apt-get install -y git
  630. fi
  631. if [ ! -d "$WORKSPACE/speech-denoiser" ]; then
  632. git clone https://github.com/lucianodato/speech-denoiser.git "$WORKSPACE/speech-denoiser"
  633. fi
  634. cd "$WORKSPACE/speech-denoiser"
  635. if command_exists "python3"; then
  636. pyv="$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:3])))' 2>&1)"
  637. laverison="3.5.2"
  638. echo "$pyv"
  639. comparse=$(awk 'BEGIN{ print "'$pyv'"<="'$laverison'" }')
  640. if [ "$comparse" -eq 1 ]; then
  641. echo "install system python3.7"
  642. sudo apt-get remove python3.4 -y
  643. sudo apt-get install software-properties-common python-software-properties -y
  644. sudo add-apt-repository ppa:deadsnakes/ppa -y
  645. sudo apt-get update -y
  646. sudo apt-get install python3-pip python3.7 -y
  647. sudo apt-get install python3.7-gdbm -y
  648. else
  649. echo "python3:$pyv,only need install meson ninja "
  650. sudo apt-get install python3-pip -y
  651. sudo pip3 install meson ninja
  652. fi
  653. fi
  654. chmod +x install.sh && ./install.sh
  655. build_done "speech-denoiser"
  656. exit 0