install-ffmpeg 23 KB

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