diff --git a/src/AvTranscoder/EssenceStream/OutputAudio.cpp b/src/AvTranscoder/EssenceStream/OutputAudio.cpp index e7730cc7..2d6d83af 100644 --- a/src/AvTranscoder/EssenceStream/OutputAudio.cpp +++ b/src/AvTranscoder/EssenceStream/OutputAudio.cpp @@ -191,12 +191,54 @@ 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 ) + { + 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; + } + } } } 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 diff --git a/src/AvTranscoder/OptionLoader.cpp b/src/AvTranscoder/OptionLoader.cpp index 00867a01..802c5812 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 @@ -300,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 ) @@ -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..d0296071 100644 --- a/src/AvTranscoder/OptionLoader.hpp +++ b/src/AvTranscoder/OptionLoader.hpp @@ -62,11 +62,17 @@ 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; + /** + * 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.