install-ffmpeg 25 KB

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