Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFmpeg audio import #55

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ option(WITH_DEVILIMAGEIMPORTER "Build DevIlImageImporter plugin" OFF)
option(WITH_DRFLACAUDIOIMPORTER "Build DrFlacAudioImporter plugin" OFF)
option(WITH_DRWAVAUDIOIMPORTER "Build DrWavAudioImporter plugin" OFF)
option(WITH_FAAD2AUDIOIMPORTER "Build Faad2AudioImporter plugin" OFF)
option(WITH_FFMPEGAUDIOIMPORTER "Build FfmpegAudioImporter plugin" OFF)
cmake_dependent_option(WITH_FREETYPEFONT "Build FreeTypeFont plugin" OFF "NOT WITH_HARFBUZZFONT" ON)
option(WITH_HARFBUZZFONT "Build HarfBuzzFont plugin" OFF)
option(WITH_JPEGIMAGECONVERTER "Build JpegImageConverter plugin" OFF)
Expand Down
3 changes: 3 additions & 0 deletions doc/building-plugins.dox
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ By default no plugins are built and you need to select them manually:
- `WITH_FAAD2AUDIOIMPORTER` --- Build the
@ref Audio::Faad2Importer "Faad2AudioImporter" plugin. Depends on
[FAAD2](https://www.audiocoding.com/faad2.html).
- `WITH_FFMPEGAUDIOIMPORTER` --- Build the
@ref Audio::FfmpegImporter "FfmpegAudioImporter" plugin. Depends on
[FFmpeg](https://www.ffmpeg.org/).
- `WITH_FREETYPEFONT` --- Build the @ref Text::FreeTypeFont "FreeTypeFont"
plugin. Depends on [FreeType](http://www.freetype.org/).
- `WITH_HARFBUZZFONT` --- Build the @ref Text::HarfBuzzFont "HarfBuzzFont"
Expand Down
2 changes: 2 additions & 0 deletions doc/changelog-plugins.dox
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ namespace Magnum {

- New @ref Audio::Faad2Importer "Faad2AudioImporter" plugin for importing
AAC files using [FAAD2](https://www.audiocoding.com/faad2.html)
- New @ref Audio::FfmpegImporter "FfmpegAudioImporter" plugin for importing
virtually all existing audio formats

@subsection changelog-plugins-latest-changes Changes and improvements

Expand Down
2 changes: 2 additions & 0 deletions doc/cmake-plugins.dox
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ This command will not try to find any actual plugin. The plugins are:
plugin
- `Faad2AudioImporter` --- @ref Audio::Faad2Importer "Faad2AudioImporter"
plugin
- `FfmpegAudioImporter` --- @ref Audio::FfmpegImporter "FfmpegAudioImporter"
plugin
- `FreeTypeFont` --- @ref Text::FreeTypeFont "FreeTypeFont" plugin
- `HarfBuzzFont` --- @ref Text::HarfBuzzFont "HarfBuzzFont" plugin
- `JpegImageConverter` --- @ref Trade::JpegImageConverter "JpegImageConverter"
Expand Down
86 changes: 86 additions & 0 deletions modules/FindFFmpeg.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#.rst:
# Find FFmpeg
# -------------
#
# Finds the FFmpeg library. Basic usage:
#
# find_package(FFmpeg REQUIRED avformat avcodec)
#
# This module defines:
#
# FFmpeg_FOUND - True if FFmpeg is found
# FFmpeg_<component>_FOUND - True if given FFmpeg compoment is found
# FFmpeg::ffmpeg - Imported target for the ffmpeg executable
# FFmpeg::<component> - Imported target for given library component
#
# The <component> is any of these:
#
# avcodec
# avdevice
# avfilter
# avformat
# avresample
# avutil
# swresample
# swscale
#
# Additionally these variables are defined for internal usage:
#
# FFmpeg_<component>_LIBRARY - FFmpeg component library location
# FFmpeg_<component>_INCLUDE_DIR - FFmpeg component Include dir
#

#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
# Vladimír Vondruš <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#

find_program(FFmpeg_EXECUTABLE ffmpeg)
if(FFmpeg_EXECUTABLE)
add_executable(FFmpeg::ffmpeg IMPORTED)
mark_as_advanced(FFmpeg_EXECUTABLE)
set_property(TARGET FFmpeg::ffmpeg PROPERTY IMPORTED_LOCATION ${FFmpeg_EXECUTABLE})
endif()

foreach(_component ${FFmpeg_FIND_COMPONENTS})
find_library(FFmpeg_${_component}_LIBRARY NAMES ${_component})
find_path(FFmpeg_${_component}_INCLUDE_DIR NAMES lib${_component}/${_component}.h)

if(FFmpeg_${_component}_LIBRARY AND FFmpeg_${_component}_INCLUDE_DIR)
set(FFmpeg_${_component}_FOUND ON)

if(NOT TARGET FFmpeg::${_component})
add_library(FFmpeg::${_component} UNKNOWN IMPORTED)
set_target_properties(FFmpeg::${_component} PROPERTIES
IMPORTED_LOCATION ${FFmpeg_${_component}_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${FFmpeg_${_component}_INCLUDE_DIR})
endif()
endif()

mark_as_advanced(
FFmpeg_${_component}_LIBRARY
FFmpeg_${_component}_INCLUDE_DIR)
endforeach()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFmpeg REQUIRED_VARS FFmpeg_EXECUTABLE HANDLE_COMPONENTS)
16 changes: 11 additions & 5 deletions modules/FindMagnumPlugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ mark_as_advanced(MAGNUMPLUGINS_INCLUDE_DIR)
set(_MAGNUMPLUGINS_LIBRARY_COMPONENT_LIST OpenDdl)
set(_MAGNUMPLUGINS_PLUGIN_COMPONENT_LIST
AssimpImporter DdsImporter DevIlImageImporter
DrFlacAudioImporter DrWavAudioImporter Faad2AudioImporter FreeTypeFont
HarfBuzzFont JpegImageConverter JpegImporter MiniExrImageConverter
OpenGexImporter PngImageConverter PngImporter StanfordImporter
StbImageConverter StbImageImporter StbTrueTypeFont StbVorbisAudioImporter
TinyGltfImporter)
DrFlacAudioImporter DrWavAudioImporter Faad2AudioImporter
FfmpegAudioImporter FreeTypeFont HarfBuzzFont JpegImageConverter
JpegImporter MiniExrImageConverter OpenGexImporter PngImageConverter
PngImporter StanfordImporter StbImageConverter StbImageImporter
StbTrueTypeFont StbVorbisAudioImporter TinyGltfImporter)
if(MAGNUM_BUILD_DEPRECATED)
list(APPEND _MAGNUMPLUGINS_PLUGIN_COMPONENT_LIST ColladaImporter)
endif()
Expand Down Expand Up @@ -297,6 +297,12 @@ foreach(_component ${MagnumPlugins_FIND_COMPONENTS})
set_property(TARGET MagnumPlugins::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES FAAD2::FAAD2)

# FfmpegAudioImporter plugin dependencies
elseif(_component STREQUAL FffmpegAudioImporter)
find_package(FFmpeg REQUIRED avcodec avformat avutil)
set_property(TARGET MagnumPlugins::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES FFmpeg::avcodec FFmpeg::avformat FFmpeg::avutil)

# FreeTypeFont plugin dependencies
elseif(_component STREQUAL FreeTypeFont)
find_package(Freetype)
Expand Down
3 changes: 2 additions & 1 deletion package/archlinux/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pkgdesc="Plugins for the Magnum C++11/C++14 graphics engine"
arch=('i686' 'x86_64')
url="https://magnum.graphics"
license=('MIT')
depends=('magnum' 'qt4' 'devil' 'faad2' 'freetype2' 'harfbuzz' 'libjpeg' 'libpng' 'assimp')
depends=('magnum' 'qt4' 'devil' 'faad2' 'ffmpeg' 'freetype2' 'harfbuzz' 'libjpeg' 'libpng' 'assimp')
makedepends=('cmake' 'ninja')
options=(!strip)
provides=('magnum-plugins-git')
Expand All @@ -29,6 +29,7 @@ build() {
-DWITH_DRFLACAUDIOIMPORTER=ON \
-DWITH_DRWAVAUDIOIMPORTER=ON \
-DWITH_FAAD2AUDIOIMPORTER=ON \
-DWITH_FFMPEGAUDIOIMPORTER=ON \
-DWITH_FREETYPEFONT=ON \
-DWITH_HARFBUZZFONT=ON \
-DWITH_JPEGIMAGECONVERTER=ON \
Expand Down
4 changes: 4 additions & 0 deletions src/MagnumPlugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ if(WITH_FAAD2AUDIOIMPORTER)
add_subdirectory(Faad2AudioImporter)
endif()

if(WITH_FFMPEGAUDIOIMPORTER)
add_subdirectory(FfmpegAudioImporter)
endif()

if(WITH_FREETYPEFONT)
add_subdirectory(FreeTypeFont)
endif()
Expand Down
70 changes: 70 additions & 0 deletions src/MagnumPlugins/FfmpegAudioImporter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
# Vladimír Vondruš <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#

find_package(Magnum REQUIRED Audio)
find_package(FFmpeg REQUIRED avcodec avformat avutil)

if(BUILD_PLUGINS_STATIC)
set(MAGNUM_FFMPEGAUDIOIMPORTER_BUILD_STATIC 1)
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/configure.h)

# FfmpegAudioImporter plugin
add_plugin(FfmpegAudioImporter
"${MAGNUM_PLUGINS_AUDIOIMPORTER_DEBUG_BINARY_INSTALL_DIR};${MAGNUM_PLUGINS_AUDIOIMPORTER_DEBUG_LIBRARY_INSTALL_DIR}"
"${MAGNUM_PLUGINS_AUDIOIMPORTER_RELEASE_BINARY_INSTALL_DIR};${MAGNUM_PLUGINS_AUDIOIMPORTER_RELEASE_LIBRARY_INSTALL_DIR}"
FfmpegAudioImporter.conf
FfmpegImporter.cpp
FfmpegImporter.h)
if(BUILD_PLUGINS_STATIC AND BUILD_STATIC_PIC)
set_target_properties(FfmpegAudioImporter PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
target_include_directories(FfmpegAudioImporter PUBLIC
${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src)
# Include the stb_*.h files as a system directory to supress warnings
target_include_directories(FfmpegAudioImporter SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external/stb)
target_link_libraries(FfmpegAudioImporter PUBLIC
Magnum::Audio FFmpeg::avcodec FFmpeg::avformat FFmpeg::avutil)

install(FILES FfmpegImporter.h ${CMAKE_CURRENT_BINARY_DIR}/configure.h
DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/FfmpegAudioImporter)

# Automatic static plugin import
if(BUILD_PLUGINS_STATIC)
install(FILES importStaticPlugin.cpp DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/FfmpegAudioImporter)
if(NOT CMAKE_VERSION VERSION_LESS 3.1)
target_sources(FfmpegAudioImporter INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/importStaticPlugin.cpp)
endif()
endif()

if(BUILD_TESTS)
add_subdirectory(Test)
endif()

# MagnumPlugins FfmpegAudioImporter target alias for superprojects
add_library(MagnumPlugins::FfmpegAudioImporter ALIAS FfmpegAudioImporter)
Empty file.
Loading