install-ffmpeg-ousider 24 KB

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