From 69abe094ab69d1ce9b188ce0e77652e6e4d6090f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 17 Dec 2014 19:20:48 +0000 Subject: [PATCH] From Javier Taibo, " I have found that since version 1.1, FFMPEG changed the way audio streams are retrieved, from packed to planar format. SDL interprets packed audio, as is used in the osgmovie example. To make the audio work when the OSGffmpeg plug-in is compiled against recent FFMPEG versions, FFmpegDecoderAudio must check for planar formats and in these cases request the samples as packed. This way all works as before. It can be checked with osgmovie example application. $ osgmovie --audio movie.avi.ffmpeg FFmpegImageStream::open audio failed, audio stream will be disabled: unknown audio format With the attached FFmpegDecoderAudio.cpp, audio sounds correctly. I am also attaching a modified version of FindFFmpeg.cmake that allows to set as FFMPEG_DIR the ffmpeg compiled in the source directory structure. It should not break anything as it only adds some additional search paths. " Note from Robert Osfield, I have found in testing that audio quality is not good for planar floating point formats, even with adding support for SDL2 to the osgmovie example. I haven't yet tracked down the cause of these audio problems or a solution. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14609 16af8721-9629-0410-8352-f15c8da7e697 --- CMakeModules/FindFFmpeg.cmake | 6 +++++ src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp | 23 ++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CMakeModules/FindFFmpeg.cmake b/CMakeModules/FindFFmpeg.cmake index 1cccf4e62..6521783c4 100644 --- a/CMakeModules/FindFFmpeg.cmake +++ b/CMakeModules/FindFFmpeg.cmake @@ -32,6 +32,8 @@ MACRO(FFMPEG_FIND varname shortname headername) PATHS ${FFMPEG_ROOT}/include $ENV{FFMPEG_DIR}/include + ${FFMPEG_ROOT} + $ENV{FFMPEG_DIR} ~/Library/Frameworks /Library/Frameworks /usr/local/include @@ -49,6 +51,8 @@ MACRO(FFMPEG_FIND varname shortname headername) PATHS ${FFMPEG_ROOT}/include $ENV{FFMPEG_DIR}/include + ${FFMPEG_ROOT} + $ENV{FFMPEG_DIR} ~/Library/Frameworks /Library/Frameworks /usr/local/include @@ -67,6 +71,8 @@ MACRO(FFMPEG_FIND varname shortname headername) PATHS ${FFMPEG_ROOT}/lib $ENV{FFMPEG_DIR}/lib + ${FFMPEG_ROOT}/lib${shortname} + $ENV{FFMPEG_DIR}/lib${shortname} ~/Library/Frameworks /Library/Frameworks /usr/local/lib diff --git a/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp b/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp index b16e92f54..a290033eb 100644 --- a/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp +++ b/src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp @@ -128,8 +128,7 @@ void FFmpegDecoderAudio::open(AVStream * const stream) m_frequency = m_context->sample_rate; m_nb_channels = m_context->channels; - OSG_NOTICE<<"FFmpegDecoderAudio::open(..), m_nb_channels="<sample_fmt="<sample_fmt<sample_fmt="<sample_fmt<sample_fmt) { @@ -149,6 +148,26 @@ void FFmpegDecoderAudio::open(AVStream * const stream) break; case AV_SAMPLE_FMT_DBL: throw std::runtime_error("unhandled audio format AV_SAMPLE_FMT_DBL"); + + case AV_SAMPLE_FMT_U8P: + m_sample_format = osg::AudioStream::SAMPLE_FORMAT_U8; + m_context->request_sample_fmt = av_get_packed_sample_fmt( m_context->sample_fmt ); + break; + case AV_SAMPLE_FMT_S16P: + m_sample_format = osg::AudioStream::SAMPLE_FORMAT_S16; + m_context->request_sample_fmt = av_get_packed_sample_fmt( m_context->sample_fmt ); + break; + case AV_SAMPLE_FMT_S32P: + m_sample_format = osg::AudioStream::SAMPLE_FORMAT_S32; + m_context->request_sample_fmt = av_get_packed_sample_fmt( m_context->sample_fmt ); + break; + case AV_SAMPLE_FMT_FLTP: + m_sample_format = osg::AudioStream::SAMPLE_FORMAT_F32; + m_context->request_sample_fmt = av_get_packed_sample_fmt( m_context->sample_fmt ); + break; + case AV_SAMPLE_FMT_DBLP: + throw std::runtime_error("unhandled audio format AV_SAMPLE_FMT_DBLP"); + default: throw std::runtime_error("unknown audio format"); }