install-ffmpeg-ousider 24 KB

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