From 39314e1f0ed1d1b339dcebc3be925005fab9187c Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 16 Jul 2014 16:10:04 +0200 Subject: [PATCH 1/6] OptionLoader: add getSampleFormats --- src/AvTranscoder/OptionLoader.cpp | 31 +++++++++++++++++++++++++++++++ src/AvTranscoder/OptionLoader.hpp | 6 ++++++ 2 files changed, 37 insertions(+) diff --git a/src/AvTranscoder/OptionLoader.cpp b/src/AvTranscoder/OptionLoader.cpp index 00867a01..8d147329 100644 --- a/src/AvTranscoder/OptionLoader.cpp +++ b/src/AvTranscoder/OptionLoader.cpp @@ -7,6 +7,7 @@ extern "C" { #include #include #include +#include } #ifndef AV_OPT_FLAG_FILTERING_PARAM @@ -322,4 +323,34 @@ std::vector OptionLoader::getPixelFormats( const std::string& video return pixelFormats; } +std::vector OptionLoader::getSampleFormats( const std::string& audioCodecName ) const +{ + std::vector sampleFormats; + + if( audioCodecName.empty() ) + { + for( size_t sampleFormat = 0; sampleFormat < AV_SAMPLE_FMT_NB; ++sampleFormat) + { + sampleFormats.push_back( av_get_sample_fmt_name( static_cast( sampleFormat ) ) ); + } + } + else + { + const AVCodec* audioCodec = avcodec_find_encoder_by_name( audioCodecName.c_str() ); + if( audioCodec && audioCodec->sample_fmts != NULL ) + { + size_t sample_fmt = 0; + while( audioCodec->sample_fmts[sample_fmt] != -1 ) + { + const char* sampleFormatName = av_get_sample_fmt_name( audioCodec->sample_fmts[sample_fmt] ); + if( sampleFormatName ) + sampleFormats.push_back( std::string( sampleFormatName ) ); + sample_fmt++; + } + } + } + + return sampleFormats; +} + } diff --git a/src/AvTranscoder/OptionLoader.hpp b/src/AvTranscoder/OptionLoader.hpp index 0acb7efc..ca264eb8 100644 --- a/src/AvTranscoder/OptionLoader.hpp +++ b/src/AvTranscoder/OptionLoader.hpp @@ -67,6 +67,12 @@ class OptionLoader */ std::vector getPixelFormats( const std::string& videoCodecName = "" ) const; + /** + * Get array of sample format supported by an audio codec. + * @param audioCodecName: the audio codec name (empty if not indicated, and so get all sample formats supported by all audio codecs). + */ + std::vector getSampleFormats( const std::string& audioCodecName = "" ) const; + private: /** * @brief: load array of Option depending on the flags. From cf40e098e85848c65d7683d9eb2b3f52860bd784 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 16 Jul 2014 16:11:19 +0200 Subject: [PATCH 2/6] OptionLoader: update getSampleFormats * Add const. * Fix if videoCodec is NULL (no codec corresponding to the videoCodecName). --- src/AvTranscoder/OptionLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AvTranscoder/OptionLoader.cpp b/src/AvTranscoder/OptionLoader.cpp index 8d147329..802c5812 100644 --- a/src/AvTranscoder/OptionLoader.cpp +++ b/src/AvTranscoder/OptionLoader.cpp @@ -301,9 +301,9 @@ std::vector OptionLoader::getPixelFormats( const std::string& video // specific video codec else { - AVCodec* videoCodec = avcodec_find_encoder_by_name( videoCodecName.c_str() ); + const AVCodec* videoCodec = avcodec_find_encoder_by_name( videoCodecName.c_str() ); - if( videoCodec->pix_fmts != NULL ) + if( videoCodec && videoCodec->pix_fmts != NULL ) { size_t pix_fmt = 0; while( videoCodec->pix_fmts[pix_fmt] != -1 ) From c4bf09dd26ae9d7bc736b6cacf84a6f0bd76acce Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 16 Jul 2014 16:11:38 +0200 Subject: [PATCH 3/6] OptionLoader: update doc of getPixelFormats --- src/AvTranscoder/OptionLoader.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AvTranscoder/OptionLoader.hpp b/src/AvTranscoder/OptionLoader.hpp index ca264eb8..d0296071 100644 --- a/src/AvTranscoder/OptionLoader.hpp +++ b/src/AvTranscoder/OptionLoader.hpp @@ -62,7 +62,7 @@ class OptionLoader std::vector& getAudioCodecsShortNames() { return _audioCodecsShortNames; } /** - * Get array of pixel format supported by video codec. + * Get array of pixel format supported by a video codec. * @param videoCodecName: the video codec name (empty if not indicated, and so get all pixel formats supported by all video codecs). */ std::vector getPixelFormats( const std::string& videoCodecName = "" ) const; From e3ce42d6011f14e79751313a7c29c93b1600d323 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 17 Jul 2014 15:37:38 +0200 Subject: [PATCH 4/6] OutputAudio: completely set profile * Completely set the profile of the audioDesc, by using all key of the ProfileDesc. * Like the videoDesc, set parameters twice (before and after a setup), to set the parameters which need a setup. --- .../EssenceStream/OutputAudio.cpp | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/AvTranscoder/EssenceStream/OutputAudio.cpp b/src/AvTranscoder/EssenceStream/OutputAudio.cpp index e7730cc7..1bccd899 100644 --- a/src/AvTranscoder/EssenceStream/OutputAudio.cpp +++ b/src/AvTranscoder/EssenceStream/OutputAudio.cpp @@ -195,8 +195,50 @@ void OutputAudio::setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc& size_t channels = std::strtoul( desc[ Profile::avProfileChannel ].c_str(), NULL, 0 ); _audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( desc[ Profile::avProfileSampleFormat ].c_str() ) ); + + for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it ) + { + if( (*it).first == Profile::avProfileIdentificator || + (*it).first == Profile::avProfileIdentificatorHuman || + (*it).first == Profile::avProfileType || + (*it).first == Profile::avProfileCodec || + (*it).first == Profile::avProfileSampleFormat || + (*it).first == Profile::avProfileSampleRate || + (*it).first == Profile::avProfileChannel ) + continue; + + try + { + _audioDesc.set( (*it).first, (*it).second ); + } + catch( std::exception& e ) + { + std::cout << "warning: " << e.what() << std::endl; + } + } setup(); + + for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it ) + { + if( (*it).first == Profile::avProfileIdentificator || + (*it).first == Profile::avProfileIdentificatorHuman || + (*it).first == Profile::avProfileType || + (*it).first == Profile::avProfileCodec || + (*it).first == Profile::avProfileSampleFormat || + (*it).first == Profile::avProfileSampleRate || + (*it).first == Profile::avProfileChannel ) + continue; + + try + { + _audioDesc.set( (*it).first, (*it).second ); + } + catch( std::exception& e ) + { + std::cout << "2.warning: " << e.what() << std::endl; + } + } } } From e8f0e7f17f078100f536ec0e6334acc04cd3df00 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 17 Jul 2014 15:38:14 +0200 Subject: [PATCH 5/6] OutputVideo: refactoring setProfile --- .../EssenceStream/OutputVideo.cpp | 46 +++++++------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/src/AvTranscoder/EssenceStream/OutputVideo.cpp b/src/AvTranscoder/EssenceStream/OutputVideo.cpp index 42e212f1..a340c23b 100644 --- a/src/AvTranscoder/EssenceStream/OutputVideo.cpp +++ b/src/AvTranscoder/EssenceStream/OutputVideo.cpp @@ -201,21 +201,14 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc, const avtranscoder::Im for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it ) { - if( (*it).first == Profile::avProfileIdentificator ) - continue; - if( (*it).first == Profile::avProfileIdentificatorHuman ) - continue; - if( (*it).first == Profile::avProfileType ) - continue; - if( (*it).first == Profile::avProfileCodec ) - continue; - if( (*it).first == Profile::avProfilePixelFormat ) - continue; - if( (*it).first == Profile::avProfileWidth ) - continue; - if( (*it).first == Profile::avProfileHeight ) - continue; - if( (*it).first == Profile::avProfileFrameRate ) + if( (*it).first == Profile::avProfileIdentificator || + (*it).first == Profile::avProfileIdentificatorHuman || + (*it).first == Profile::avProfileType || + (*it).first == Profile::avProfileCodec || + (*it).first == Profile::avProfilePixelFormat || + (*it).first == Profile::avProfileWidth || + (*it).first == Profile::avProfileHeight|| + (*it).first == Profile::avProfileFrameRate) continue; try @@ -232,21 +225,14 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc, const avtranscoder::Im for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it ) { - if( (*it).first == Profile::avProfileIdentificator ) - continue; - if( (*it).first == Profile::avProfileIdentificatorHuman ) - continue; - if( (*it).first == Profile::avProfileType ) - continue; - if( (*it).first == Profile::avProfileCodec ) - continue; - if( (*it).first == Profile::avProfilePixelFormat ) - continue; - if( (*it).first == Profile::avProfileWidth ) - continue; - if( (*it).first == Profile::avProfileHeight ) - continue; - if( (*it).first == Profile::avProfileFrameRate ) + if( (*it).first == Profile::avProfileIdentificator || + (*it).first == Profile::avProfileIdentificatorHuman || + (*it).first == Profile::avProfileType || + (*it).first == Profile::avProfileCodec || + (*it).first == Profile::avProfilePixelFormat || + (*it).first == Profile::avProfileWidth || + (*it).first == Profile::avProfileHeight|| + (*it).first == Profile::avProfileFrameRate) continue; try From 90b51133f337b064e9bdccbe9402b9acb5e24b5e Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Thu, 17 Jul 2014 15:40:26 +0200 Subject: [PATCH 6/6] OutputAudio: refactoring setProfile --- src/AvTranscoder/EssenceStream/OutputAudio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AvTranscoder/EssenceStream/OutputAudio.cpp b/src/AvTranscoder/EssenceStream/OutputAudio.cpp index 1bccd899..2d6d83af 100644 --- a/src/AvTranscoder/EssenceStream/OutputAudio.cpp +++ b/src/AvTranscoder/EssenceStream/OutputAudio.cpp @@ -191,9 +191,9 @@ void OutputAudio::setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc& throw std::runtime_error( "Profile " + desc[ Profile::avProfileIdentificatorHuman ] + ": bad audio channel layout." ); _audioDesc.setAudioCodec( desc[ Profile::avProfileCodec ] ); + size_t sample_rate = std::strtoul( desc[ Profile::avProfileSampleRate ].c_str(), NULL, 0 ); size_t channels = std::strtoul( desc[ Profile::avProfileChannel ].c_str(), NULL, 0 ); - _audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( desc[ Profile::avProfileSampleFormat ].c_str() ) ); for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it )