install-ffmpeg 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. #!/bin/bash
  2. # HOMEPAGE: https://github.com/markus-perl/ffmpeg-build-script
  3. # LICENSE: https://github.com/markus-perl/ffmpeg-build-script/blob/master/LICENSE
  4. PROGNAME=$(basename "$0")
  5. VERSION=1.22
  6. CWD=$(pwd)
  7. PACKAGES="$CWD/packages"
  8. WORKSPACE="$CWD/workspace"
  9. CFLAGS="-I$WORKSPACE/include"
  10. LDFLAGS="-L$WORKSPACE/lib"
  11. LDEXEFLAGS=""
  12. EXTRALIBS="-ldl -lpthread -lm -lz"
  13. MACOS_M1=false
  14. CONFIGURE_OPTIONS=()
  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 " -f, --full-static Build a full static FFmpeg binary (eg. glibc, pthreads etc...) **only Linux**"
  156. echo " Note: Because of the NSS (Name Service Switch), glibc does not recommend static links."
  157. echo ""
  158. }
  159. while (($# > 0)); do
  160. case $1 in
  161. -h | --help)
  162. usage
  163. exit 0
  164. ;;
  165. --version)
  166. echo "$VERSION"
  167. exit 0
  168. ;;
  169. -*)
  170. if [[ "$1" == "--build" || "$1" =~ 'b' ]]; then
  171. bflag='-b'
  172. fi
  173. if [[ "$1" == "--cleanup" || "$1" =~ 'c' && ! "$1" =~ '--' ]]; then
  174. cflag='-c'
  175. cleanup
  176. fi
  177. if [[ "$1" == "--full-static" || "$1" =~ 'f' ]]; then
  178. if [[ "$OSTYPE" == "darwin"* ]]; then
  179. echo "Error: A full static binary can only be build on Linux."
  180. exit 1
  181. fi
  182. LDEXEFLAGS="-static"
  183. fi
  184. shift
  185. ;;
  186. *)
  187. usage
  188. exit 1
  189. ;;
  190. esac
  191. done
  192. echo "ffmpeg-build-script v$VERSION"
  193. echo "========================="
  194. echo ""
  195. if [ -z "$bflag" ]; then
  196. if [ -z "$cflag" ]; then
  197. usage
  198. exit 1
  199. fi
  200. exit 0
  201. fi
  202. echo "Using $MJOBS make jobs simultaneously."
  203. if [ -n "$LDEXEFLAGS" ]; then
  204. echo "Start the build in full static mode."
  205. fi
  206. mkdir -p "$PACKAGES"
  207. mkdir -p "$WORKSPACE"
  208. export PATH="${WORKSPACE}/bin:$PATH"
  209. PKG_CONFIG_PATH="/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig"
  210. PKG_CONFIG_PATH+=":/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib64/pkgconfig"
  211. export PKG_CONFIG_PATH
  212. if ! command_exists "make"; then
  213. echo "make not installed."
  214. exit 1
  215. fi
  216. if ! command_exists "g++"; then
  217. echo "g++ not installed."
  218. exit 1
  219. fi
  220. if ! command_exists "curl"; then
  221. echo "curl not installed."
  222. exit 1
  223. fi
  224. if ! command_exists "python"; then
  225. echo "Python command not found. Lv2 filter will not be available."
  226. fi
  227. ##
  228. ## build tools
  229. ##
  230. if build "pkg-config"; then
  231. download "https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz"
  232. execute ./configure --silent --prefix="${WORKSPACE}" --with-pc-path="${WORKSPACE}"/lib/pkgconfig --with-internal-glib
  233. execute make -j $MJOBS
  234. execute make install
  235. build_done "pkg-config"
  236. fi
  237. if command_exists "python"; then
  238. if build "lv2"; then
  239. download "https://lv2plug.in/spec/lv2-1.18.0.tar.bz2" "lv2-1.18.0.tar.bz2"
  240. execute ./waf configure --prefix="${WORKSPACE}" --lv2-user
  241. execute ./waf
  242. execute ./waf install
  243. build_done "lv2"
  244. fi
  245. if build "waflib"; then
  246. download "https://gitlab.com/drobilla/autowaf/-/archive/cc37724b9bfa889baebd8cb10f38b8c7cab83e37/autowaf-cc37724b9bfa889baebd8cb10f38b8c7cab83e37.tar.gz" "autowaf.tar.gz"
  247. build_done "waflib"
  248. fi
  249. if build "serd"; then
  250. download "https://gitlab.com/drobilla/serd/-/archive/v0.30.6/serd-v0.30.6.tar.gz" "serd-v0.30.6.tar.gz"
  251. execute cp -r "${PACKAGES}"/autowaf/* "${PACKAGES}/serd-v0.30.6/waflib/"
  252. execute ./waf configure --prefix="${WORKSPACE}" --static --no-shared --no-posix
  253. execute ./waf
  254. execute ./waf install
  255. build_done "serd"
  256. fi
  257. if build "pcre"; then
  258. download "https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz" "pcre-8.44.tar.gz"
  259. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  260. execute make -j $MJOBS
  261. execute make install
  262. build_done "pcre"
  263. fi
  264. if build "sord"; then
  265. download "https://gitlab.com/drobilla/sord/-/archive/v0.16.6/sord-v0.16.6.tar.gz" "sord-v0.16.6.tar.gz"
  266. execute cp -r "${PACKAGES}"/autowaf/* "${PACKAGES}/sord-v0.16.6/waflib/"
  267. execute ./waf configure --prefix="${WORKSPACE}" CFLAGS="${CFLAGS}" --static --no-shared --no-utils
  268. execute ./waf CFLAGS="${CFLAGS}"
  269. execute ./waf install
  270. build_done "sord"
  271. fi
  272. if build "sratom"; then
  273. download "https://gitlab.com/lv2/sratom/-/archive/v0.6.6/sratom-v0.6.6.tar.gz" "sratom-v0.6.6.tar.gz"
  274. execute cp -r "${PACKAGES}"/autowaf/* "${PACKAGES}/sratom-v0.6.6/waflib/"
  275. execute ./waf configure --prefix="${WORKSPACE}" --static --no-shared
  276. execute ./waf
  277. execute ./waf install
  278. build_done "sratom"
  279. fi
  280. if build "lilv"; then
  281. download "https://gitlab.com/lv2/lilv/-/archive/v0.24.10/lilv-v0.24.10.tar.gz" "lilv-v0.24.10.tar.gz"
  282. execute cp -r "${PACKAGES}"/autowaf/* "${PACKAGES}/lilv-v0.24.10/waflib/"
  283. execute ./waf configure --prefix="${WORKSPACE}" --static --no-shared --no-utils
  284. execute ./waf
  285. execute ./waf install
  286. CFLAGS+=" -I$WORKSPACE/include/lilv-0"
  287. build_done "lilv"
  288. fi
  289. CONFIGURE_OPTIONS+=("--enable-lv2")
  290. fi
  291. if build "yasm"; then
  292. download "https://github.com/yasm/yasm/releases/download/v1.3.0/yasm-1.3.0.tar.gz"
  293. execute ./configure --prefix="${WORKSPACE}"
  294. execute make -j $MJOBS
  295. execute make install
  296. build_done "yasm"
  297. fi
  298. if build "nasm"; then
  299. download "https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.xz"
  300. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  301. execute make -j $MJOBS
  302. execute make install
  303. build_done "nasm"
  304. fi
  305. if build "zlib"; then
  306. download "https://www.zlib.net/zlib-1.2.11.tar.gz"
  307. execute ./configure --static --prefix="${WORKSPACE}"
  308. execute make -j $MJOBS
  309. execute make install
  310. build_done "zlib"
  311. fi
  312. if build "openssl"; then
  313. download "https://www.openssl.org/source/openssl-1.1.1i.tar.gz"
  314. if $MACOS_M1; then
  315. 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
  316. execute ./configure --prefix="${WORKSPACE}" no-shared no-asm darwin64-arm64-cc
  317. else
  318. execute ./config --prefix="${WORKSPACE}" --openssldir="${WORKSPACE}" --with-zlib-include="${WORKSPACE}"/include/ --with-zlib-lib="${WORKSPACE}"/lib no-shared zlib
  319. fi
  320. execute make -j $MJOBS
  321. execute make install_sw
  322. build_done "openssl"
  323. fi
  324. CONFIGURE_OPTIONS+=("--enable-openssl")
  325. if build "cmake"; then
  326. download "https://cmake.org/files/v3.18/cmake-3.18.4.tar.gz"
  327. execute ./configure --prefix="${WORKSPACE}" --system-zlib
  328. execute make -j $MJOBS
  329. execute make install
  330. build_done "cmake"
  331. fi
  332. if build "svtav1"; then
  333. download "https://github.com/AOMediaCodec/SVT-AV1/archive/v0.8.6.tar.gz"
  334. cd Build/linux || exit
  335. execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DENABLE_SHARED=off -DBUILD_SHARED_LIBS=OFF ../.. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
  336. execute make -j $MJOBS
  337. execute make install
  338. execute cp SvtAv1Enc.pc "${WORKSPACE}/lib/pkgconfig/"
  339. execute cp SvtAv1Dec.pc "${WORKSPACE}/lib/pkgconfig/"
  340. build_done "svtav1"
  341. fi
  342. CONFIGURE_OPTIONS+=("--enable-libsvtav1")
  343. ##
  344. ## video library
  345. ##
  346. if build "x264"; then
  347. download "https://code.videolan.org/videolan/x264/-/archive/0d754ec36013fee82978496cd56fbd48824910b3/x264-0d754ec36013fee82978496cd56fbd48824910b3.tar.gz" "x264-0d754ec.tar.gz"
  348. cd "${PACKAGES}"/x264-0d754ec || exit
  349. if [[ "$OSTYPE" == "linux-gnu" ]]; then
  350. execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic CXXFLAGS="-fPIC"
  351. else
  352. execute ./configure --prefix="${WORKSPACE}" --enable-static --enable-pic
  353. fi
  354. execute make -j $MJOBS
  355. execute make install
  356. execute make install-lib-static
  357. build_done "x264"
  358. fi
  359. CONFIGURE_OPTIONS+=("--enable-libx264")
  360. if build "x265"; then
  361. download "https://github.com/videolan/x265/archive/Release_3.5.tar.gz" "x265-3.5.tar.gz"
  362. cd build/linux || exit
  363. execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DENABLE_SHARED=off -DBUILD_SHARED_LIBS=OFF ../../source
  364. execute make -j $MJOBS
  365. execute make install
  366. if [ -n "$LDEXEFLAGS" ]; then
  367. 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
  368. fi
  369. build_done "x265"
  370. fi
  371. CONFIGURE_OPTIONS+=("--enable-libx265")
  372. if build "libvpx"; then
  373. download "https://github.com/webmproject/libvpx/archive/v1.9.0.tar.gz" "libvpx-1.9.0.tar.gz"
  374. if [[ "$OSTYPE" == "darwin"* ]]; then
  375. echo "Applying Darwin patch"
  376. sed "s/,--version-script//g" build/make/Makefile >build/make/Makefile.patched
  377. sed "s/-Wl,--no-undefined -Wl,-soname/-Wl,-undefined,error -Wl,-install_name/g" build/make/Makefile.patched >build/make/Makefile
  378. fi
  379. execute ./configure --prefix="${WORKSPACE}" --disable-unit-tests --disable-shared --as=yasm
  380. execute make -j $MJOBS
  381. execute make install
  382. build_done "libvpx"
  383. fi
  384. CONFIGURE_OPTIONS+=("--enable-libvpx")
  385. if build "xvidcore"; then
  386. download "https://downloads.xvid.com/downloads/xvidcore-1.3.7.tar.gz"
  387. cd build/generic || exit
  388. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  389. execute make -j $MJOBS
  390. execute make install
  391. if [[ -f ${WORKSPACE}/lib/libxvidcore.4.dylib ]]; then
  392. execute rm "${WORKSPACE}/lib/libxvidcore.4.dylib"
  393. fi
  394. if [[ -f ${WORKSPACE}/lib/libxvidcore.so ]]; then
  395. execute rm "${WORKSPACE}"/lib/libxvidcore.so*
  396. fi
  397. build_done "xvidcore"
  398. fi
  399. CONFIGURE_OPTIONS+=("--enable-libxvid")
  400. if build "vid_stab"; then
  401. download "https://github.com/georgmartius/vid.stab/archive/v1.1.0.tar.gz" "vid.stab-1.1.0.tar.gz"
  402. if $MACOS_M1; then
  403. 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
  404. patch -p1 <fix_cmake_quoting.patch
  405. fi
  406. execute cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DUSE_OMP=OFF -DENABLE_SHARED=off .
  407. execute make
  408. execute make install
  409. build_done "vid_stab"
  410. fi
  411. CONFIGURE_OPTIONS+=("--enable-libvidstab")
  412. if build "av1"; then
  413. download "https://aomedia.googlesource.com/aom/+archive/b52ee6d44adaef8a08f6984390de050d64df9faa.tar.gz" "av1.tar.gz" "av1"
  414. make_dir "$PACKAGES"/aom_build
  415. cd "$PACKAGES"/aom_build || exit
  416. if $MACOS_M1; then
  417. execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib -DCONFIG_RUNTIME_CPU_DETECT=0 "$PACKAGES"/av1
  418. else
  419. execute cmake -DENABLE_TESTS=0 -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib "$PACKAGES"/av1
  420. fi
  421. execute make -j $MJOBS
  422. execute make install
  423. build_done "av1"
  424. fi
  425. CONFIGURE_OPTIONS+=("--enable-libaom")
  426. ##
  427. ## audio library
  428. ##
  429. if build "opencore"; then
  430. download "https://deac-riga.dl.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.5.tar.gz"
  431. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  432. execute make -j $MJOBS
  433. execute make install
  434. build_done "opencore"
  435. fi
  436. CONFIGURE_OPTIONS+=("--enable-libopencore_amrnb" "--enable-libopencore_amrwb")
  437. if build "lame"; then
  438. download "https://netcologne.dl.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz"
  439. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  440. execute make -j $MJOBS
  441. execute make install
  442. build_done "lame"
  443. fi
  444. CONFIGURE_OPTIONS+=("--enable-libmp3lame")
  445. if build "opus"; then
  446. download "https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz"
  447. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  448. execute make -j $MJOBS
  449. execute make install
  450. build_done "opus"
  451. fi
  452. CONFIGURE_OPTIONS+=("--enable-libopus")
  453. if build "libogg"; then
  454. download "https://ftp.osuosl.org/pub/xiph/releases/ogg/libogg-1.3.3.tar.gz"
  455. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  456. execute make -j $MJOBS
  457. execute make install
  458. build_done "libogg"
  459. fi
  460. if build "libvorbis"; then
  461. download "https://ftp.osuosl.org/pub/xiph/releases/vorbis/libvorbis-1.3.6.tar.gz"
  462. execute ./configure --prefix="${WORKSPACE}" --with-ogg-libraries="${WORKSPACE}"/lib --with-ogg-includes="${WORKSPACE}"/include/ --enable-static --disable-shared --disable-oggtest
  463. execute make -j $MJOBS
  464. execute make install
  465. build_done "libvorbis"
  466. fi
  467. CONFIGURE_OPTIONS+=("--enable-libvorbis")
  468. if build "libtheora"; then
  469. download "https://ftp.osuosl.org/pub/xiph/releases/theora/libtheora-1.1.1.tar.gz"
  470. sed "s/-fforce-addr//g" configure >configure.patched
  471. chmod +x configure.patched
  472. mv configure.patched configure
  473. 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
  474. execute make -j $MJOBS
  475. execute make install
  476. build_done "libtheora"
  477. fi
  478. CONFIGURE_OPTIONS+=("--enable-libtheora")
  479. if build "fdk_aac"; then
  480. 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"
  481. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  482. execute make -j $MJOBS
  483. execute make install
  484. build_done "fdk_aac"
  485. fi
  486. CONFIGURE_OPTIONS+=("--enable-libfdk-aac")
  487. ##
  488. ## image library
  489. ##
  490. if build "libwebp"; then
  491. download "https://github.com/webmproject/libwebp/archive/v1.1.0.tar.gz" "libwebp-1.1.0.tar.gz"
  492. make_dir build
  493. cd build || exit
  494. execute cmake -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_BINDIR=bin -DCMAKE_INSTALL_INCLUDEDIR=include -DENABLE_SHARED=OFF -DENABLE_STATIC=ON ../
  495. execute make -j $MJOBS
  496. execute make install
  497. build_done "libwebp"
  498. fi
  499. CONFIGURE_OPTIONS+=("--enable-libwebp")
  500. ##
  501. ## other library
  502. ##
  503. if build "libsdl"; then
  504. download "https://www.libsdl.org/release/SDL2-2.0.14.tar.gz"
  505. execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
  506. execute make -j $MJOBS
  507. execute make install
  508. build_done "libsdl"
  509. fi
  510. if build "srt"; then
  511. download "https://github.com/Haivision/srt/archive/v1.4.1.tar.gz" "srt-1.4.1.tar.gz"
  512. export OPENSSL_ROOT_DIR="${WORKSPACE}"
  513. export OPENSSL_LIB_DIR="${WORKSPACE}"/lib
  514. export OPENSSL_INCLUDE_DIR="${WORKSPACE}"/include/
  515. 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
  516. execute make install
  517. if [ -n "$LDEXEFLAGS" ]; then
  518. 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
  519. fi
  520. build_done "srt"
  521. fi
  522. CONFIGURE_OPTIONS+=("--enable-libsrt")
  523. ##
  524. ## HWaccel library
  525. ##
  526. if [[ "$OSTYPE" == "linux-gnu" ]]; then
  527. if command_exists "nvcc"; then
  528. if build "nv-codec"; then
  529. download "https://github.com/FFmpeg/nv-codec-headers/releases/download/n11.0.10.0/nv-codec-headers-11.0.10.0.tar.gz"
  530. execute make PREFIX="${WORKSPACE}"
  531. execute make install PREFIX="${WORKSPACE}"
  532. build_done "nv-codec"
  533. fi
  534. CFLAGS+=" -I/usr/local/cuda/include"
  535. LDFLAGS+=" -L/usr/local/cuda/lib64"
  536. CONFIGURE_OPTIONS+=("--enable-cuda-nvcc" "--enable-cuvid" "--enable-nvenc" "--enable-cuda-llvm")
  537. if [ -z "$LDEXEFLAGS" ]; then
  538. CONFIGURE_OPTIONS+=("--enable-libnpp") # Only libnpp cannot be statically linked.
  539. fi
  540. # https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/
  541. CONFIGURE_OPTIONS+=("--nvccflags=-gencode arch=compute_52,code=sm_52")
  542. fi
  543. # Vaapi doesn't work well with static links FFmpeg.
  544. if [ -z "$LDEXEFLAGS" ]; then
  545. # If the libva development SDK is installed, enable vaapi.
  546. if library_exists "libva"; then
  547. if build "vaapi"; then
  548. build_done "vaapi"
  549. fi
  550. CONFIGURE_OPTIONS+=("--enable-vaapi")
  551. fi
  552. fi
  553. fi
  554. ##
  555. ## FFmpeg
  556. ##
  557. build "ffmpeg"
  558. download "https://git.ffmpeg.org/gitweb/ffmpeg.git/snapshot/553eb0773763798a6b9656b621cb125e1f6edbcc.tar.gz"
  559. # shellcheck disable=SC2086
  560. ./configure "${CONFIGURE_OPTIONS[@]}" \
  561. --disable-debug \
  562. --disable-doc \
  563. --disable-shared \
  564. --enable-gpl \
  565. --enable-nonfree \
  566. --enable-pthreads \
  567. --enable-static \
  568. --enable-small \
  569. --enable-version3 \
  570. --extra-cflags="${CFLAGS}" \
  571. --extra-ldexeflags="${LDEXEFLAGS}" \
  572. --extra-ldflags="${LDFLAGS}" \
  573. --extra-libs="${EXTRALIBS}" \
  574. --pkgconfigdir="$WORKSPACE/lib/pkgconfig" \
  575. --pkg-config-flags="--static" \
  576. --prefix="${WORKSPACE}"
  577. execute make -j $MJOBS
  578. execute make install
  579. INSTALL_FOLDER="/usr/bin"
  580. if [[ "$OSTYPE" == "darwin"* ]]; then
  581. INSTALL_FOLDER="/usr/local/bin"
  582. fi
  583. verify_binary_type
  584. echo ""
  585. echo "Building done. The following binaries can be found here:"
  586. echo "- ffmpeg: $WORKSPACE/bin/ffmpeg"
  587. echo "- ffprobe: $WORKSPACE/bin/ffprobe"
  588. echo "- ffplay: $WORKSPACE/bin/ffplay"
  589. echo ""
  590. if [[ "$AUTOINSTALL" == "yes" ]]; then
  591. if command_exists "sudo"; then
  592. sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
  593. sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
  594. sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
  595. echo "Done. FFmpeg is now installed to your system."
  596. else
  597. cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
  598. cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
  599. sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
  600. echo "Done. FFmpeg is now installed to your system."
  601. fi
  602. elif [[ ! "$SKIPINSTALL" == "yes" ]]; then
  603. read -r -p "Install these binaries to your $INSTALL_FOLDER folder? Existing binaries will be replaced. [Y/n] " response
  604. case $response in
  605. [yY][eE][sS] | [yY])
  606. if command_exists "sudo"; then
  607. sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
  608. sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
  609. sudo cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
  610. else
  611. cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg"
  612. cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe"
  613. cp "$WORKSPACE/bin/ffplay" "$INSTALL_FOLDER/ffplay"
  614. fi
  615. echo "Done. FFmpeg is now installed to your system."
  616. ;;
  617. esac
  618. fi
  619. exit 0