Add Opus audio library and configure FFmpeg to use it
authorSybren A. Stüvel <sybren@blender.org>
Fri, 4 Oct 2019 14:29:37 +0000 (16:29 +0200)
committerSybren A. Stüvel <sybren@blender.org>
Fri, 4 Oct 2019 14:30:01 +0000 (16:30 +0200)
Opus support was enabled in 2ddfd51810e0. This commit adds the Opus
library and configures FFmpeg to be compiled with Opus support.

NOTE: It may be required to run `cmake -U '*FFMPEG_LIBRARIES*' .` in
your Blender build directory in order to refresh the `FFMPEG_LIBRARIES`
setting and add libopus.

build_files/build_environment/CMakeLists.txt
build_files/build_environment/cmake/ffmpeg.cmake
build_files/build_environment/cmake/harvest.cmake
build_files/build_environment/cmake/opus.cmake [new file with mode: 0644]
build_files/build_environment/cmake/versions.cmake
build_files/build_environment/install_deps.sh
build_files/cmake/platform/platform_apple.cmake

index 9756ad28454f925674465a9c29cc416368ee7d12..e7590727822b74097405a9e17802812a78007703 100644 (file)
@@ -128,6 +128,7 @@ if(NOT WIN32 OR ENABLE_MINGW64)
     include(cmake/ogg.cmake)
     include(cmake/vorbis.cmake)
     include(cmake/theora.cmake)
+    include(cmake/opus.cmake)
     include(cmake/vpx.cmake)
     include(cmake/x264.cmake)
     include(cmake/xvidcore.cmake)
index fc0116e9ee91f2abe5937944306c1640e09d2692..307a5f97aa6ea7fb40d9067e1b1620b18f66fa23 100644 (file)
 #
 # ***** END GPL LICENSE BLOCK *****
 
-set(FFMPEG_CFLAGS "-I${mingw_LIBDIR}/lame/include -I${mingw_LIBDIR}/openjpeg/include/ -I${mingw_LIBDIR}/ogg/include -I${mingw_LIBDIR}/vorbis/include -I${mingw_LIBDIR}/theora/include -I${mingw_LIBDIR}/vpx/include -I${mingw_LIBDIR}/x264/include -I${mingw_LIBDIR}/xvidcore/include -I${mingw_LIBDIR}/zlib/include")
-set(FFMPEG_LDFLAGS "-L${mingw_LIBDIR}/lame/lib -L${mingw_LIBDIR}/openjpeg/lib -L${mingw_LIBDIR}/ogg/lib -L${mingw_LIBDIR}/vorbis/lib -L${mingw_LIBDIR}/theora/lib -L${mingw_LIBDIR}/vpx/lib -L${mingw_LIBDIR}/x264/lib -L${mingw_LIBDIR}/xvidcore/lib -L${mingw_LIBDIR}/zlib/lib")
+set(FFMPEG_CFLAGS "-I${mingw_LIBDIR}/lame/include -I${mingw_LIBDIR}/openjpeg/include/ -I${mingw_LIBDIR}/ogg/include -I${mingw_LIBDIR}/vorbis/include -I${mingw_LIBDIR}/theora/include -I${mingw_LIBDIR}/opus/include -I${mingw_LIBDIR}/vpx/include -I${mingw_LIBDIR}/x264/include -I${mingw_LIBDIR}/xvidcore/include -I${mingw_LIBDIR}/zlib/include")
+set(FFMPEG_LDFLAGS "-L${mingw_LIBDIR}/lame/lib -L${mingw_LIBDIR}/openjpeg/lib -L${mingw_LIBDIR}/ogg/lib -L${mingw_LIBDIR}/vorbis/lib -L${mingw_LIBDIR}/theora/lib -L${mingw_LIBDIR}/opus/lib -L${mingw_LIBDIR}/vpx/lib -L${mingw_LIBDIR}/x264/lib -L${mingw_LIBDIR}/xvidcore/lib -L${mingw_LIBDIR}/zlib/lib")
 set(FFMPEG_EXTRA_FLAGS --pkg-config-flags=--static --extra-cflags=${FFMPEG_CFLAGS} --extra-ldflags=${FFMPEG_LDFLAGS})
-set(FFMPEG_ENV PKG_CONFIG_PATH=${mingw_LIBDIR}/openjpeg/lib/pkgconfig:${mingw_LIBDIR}/x264/lib/pkgconfig:${mingw_LIBDIR}/vorbis/lib/pkgconfig:${mingw_LIBDIR}/ogg/lib/pkgconfig:${mingw_LIBDIR}:${mingw_LIBDIR}/vpx/lib/pkgconfig:${mingw_LIBDIR}/theora/lib/pkgconfig:${mingw_LIBDIR}/openjpeg/lib/pkgconfig)
+set(FFMPEG_ENV PKG_CONFIG_PATH=${mingw_LIBDIR}/openjpeg/lib/pkgconfig:${mingw_LIBDIR}/x264/lib/pkgconfig:${mingw_LIBDIR}/vorbis/lib/pkgconfig:${mingw_LIBDIR}/ogg/lib/pkgconfig:${mingw_LIBDIR}:${mingw_LIBDIR}/vpx/lib/pkgconfig:${mingw_LIBDIR}/theora/lib/pkgconfig:${mingw_LIBDIR}/openjpeg/lib/pkgconfig:${mingw_LIBDIR}/opus/lib/pkgconfig)
 
 if(WIN32)
   set(FFMPEG_ENV set ${FFMPEG_ENV} &&)
@@ -73,6 +73,7 @@ ExternalProject_Add(external_ffmpeg
     --disable-libgsm
     --disable-libspeex
     --enable-libvpx
+    --enable-libopus
     --prefix=${LIBDIR}/ffmpeg
     --enable-libtheora
     --enable-libvorbis
@@ -130,6 +131,7 @@ add_dependencies(
   external_openjpeg
   external_xvidcore
   external_x264
+  external_opus
   external_vpx
   external_theora
   external_vorbis
index 526e72e2e33fd71dec513d4c8cce7e9dc88db176..b10b413c39a6d1a0f50575311a3ca1e99617b32e 100644 (file)
@@ -192,6 +192,7 @@ harvest(theora/lib ffmpeg/lib "*.a")
 harvest(tiff/include tiff/include "*.h")
 harvest(tiff/lib tiff/lib "*.a")
 harvest(vorbis/lib ffmpeg/lib "*.a")
+harvest(opus/lib ffmpeg/lib "*.a")
 harvest(vpx/lib ffmpeg/lib "*.a")
 harvest(webp/lib ffmpeg/lib "*.a")
 harvest(x264/lib ffmpeg/lib "*.a")
diff --git a/build_files/build_environment/cmake/opus.cmake b/build_files/build_environment/cmake/opus.cmake
new file mode 100644 (file)
index 0000000..abaad94
--- /dev/null
@@ -0,0 +1,35 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ***** END GPL LICENSE BLOCK *****
+
+ExternalProject_Add(external_opus
+  URL ${OPUS_URI}
+  DOWNLOAD_DIR ${DOWNLOAD_DIR}
+  URL_HASH SHA256=${OPUS_HASH}
+  PREFIX ${BUILD_DIR}/opus
+  CONFIGURE_COMMAND ${CONFIGURE_ENV} && cd ${BUILD_DIR}/opus/src/external_opus/ && ${CONFIGURE_COMMAND} --prefix=${LIBDIR}/opus
+    --disable-shared
+    --enable-static
+    --with-pic
+  BUILD_COMMAND ${CONFIGURE_ENV} && cd ${BUILD_DIR}/opus/src/external_opus/ && make -j${MAKE_THREADS}
+  INSTALL_COMMAND ${CONFIGURE_ENV} && cd ${BUILD_DIR}/opus/src/external_opus/ && make install
+  INSTALL_DIR ${LIBDIR}/opus
+)
+
+if(MSVC)
+  set_target_properties(external_opus PROPERTIES FOLDER Mingw)
+endif()
index c3b713096d6b47c75ae75d64cc47305ff07ec7eb..621ac6b8bb4784c3d93151d0cac48d67c0bfcdea 100644 (file)
@@ -192,6 +192,10 @@ set(VPX_VERSION 1.7.0)
 set(VPX_URI https://github.com/webmproject/libvpx/archive/v${VPX_VERSION}/libvpx-v${VPX_VERSION}.tar.gz)
 set(VPX_HASH 1fec931eb5c94279ad219a5b6e0202358e94a93a90cfb1603578c326abfc1238)
 
+set(OPUS_VERSION 1.3.1)
+set(OPUS_URI https://archive.mozilla.org/pub/opus/opus-${OPUS_VERSION}.tar.gz)
+set(OPUS_HASH 65b58e1e25b2a114157014736a3d9dfeaad8d41be1c8179866f144a2fb44ff9d)
+
 set(X264_URI http://download.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20180811-2245-stable.tar.bz2)
 set(X264_HASH ae8a868a0e236a348b35d79f3ee80294b169d1195408b689f9851383661ed7aa)
 
index f594add3a5bb06ebdedc6ae2ba5a4982ea4961ff..a73873b1b46841e181968d5e97c482b5575d4204 100755 (executable)
@@ -431,6 +431,9 @@ X264_VERSION_MIN=0.118
 VPX_USE=false
 VPX_VERSION_MIN=0.9.7
 VPX_DEV=""
+OPUS_USE=false
+OPUS_VERSION_MIN=1.1.1
+OPUS_DEV=""
 MP3LAME_USE=false
 MP3LAME_DEV=""
 OPENJPEG_USE=false
@@ -2754,6 +2757,10 @@ compile_FFmpeg() {
       extra="$extra --enable-libvpx"
     fi
 
+    if [ "$OPUS_USE" = true ]; then
+      extra="$extra --enable-libopus"
+    fi
+
     if [ "$MP3LAME_USE" = true ]; then
       extra="$extra --enable-libmp3lame"
     fi
@@ -2991,6 +2998,14 @@ install_DEB() {
       install_packages_DEB $VPX_DEV
       VPX_USE=true
     fi
+
+    PRINT ""
+    OPUS_DEV="libopus-dev"
+    check_package_version_ge_DEB $OPUS_DEV $OPUS_VERSION_MIN
+    if [ $? -eq 0 ]; then
+      install_packages_DEB $OPUS_DEV
+      OPUS_USE=true
+    fi
   fi
 
   # Check cmake/glew versions and disable features for older distros.
@@ -3605,6 +3620,18 @@ install_RPM() {
     install_packages_RPM libspnav-devel
   fi
 
+  if [ "$WITH_ALL" = true ]; then
+    PRINT ""
+    OPUS_DEV="libopus-devel"
+    check_package_version_ge_RPM $OPUS_DEV $OPUS_VERSION_MIN
+    if [ $? -eq 0 ]; then
+      install_packages_RPM $OPUS_DEV
+      OPUS_USE=true
+    fi
+    PRINT ""
+    install_packages_RPM libspnav-devel
+  fi
+
   PRINT ""
   CLANG_FORMAT="clang"  # Yeah, on fedora/suse clang-format is part of main clang package...
   check_package_version_ge_RPM $CLANG_FORMAT $CLANG_FORMAT_VERSION_MIN
@@ -4077,6 +4104,14 @@ install_ARCH() {
       install_packages_ARCH $VPX_DEV
       VPX_USE=true
     fi
+
+    PRINT ""
+    OPUS_DEV="opus"
+    check_package_version_ge_ARCH $OPUS_DEV $OPUS_VERSION_MIN
+    if [ $? -eq 0 ]; then
+      install_packages_ARCH $OPUS_DEV
+      OPUS_USE=true
+    fi
   fi
 
 
@@ -4633,6 +4668,10 @@ print_info_ffmpeglink() {
     _packages="$_packages $VPX_DEV"
   fi
 
+  if [ "$OPUS_USE" = true ]; then
+    _packages="$_packages $OPUS_DEV"
+  fi
+
   if [ "$MP3LAME_USE" = true ]; then
     _packages="$_packages $MP3LAME_DEV"
   fi
index 249546dd21619c4972665e3364502d0e75342300..3cc6eb004762b5ba2687a14f381d138619da4362 100644 (file)
@@ -158,7 +158,7 @@ if(WITH_CODEC_FFMPEG)
     mp3lame swscale x264 xvidcore
     theora theoradec theoraenc
     vorbis vorbisenc vorbisfile ogg
-    vpx swresample)
+    opus vpx swresample)
   set(FFMPEG_LIBPATH ${FFMPEG}/lib)
 endif()