diff --git a/app/avTranscoder/avTranscoder.cpp b/app/avTranscoder/avTranscoder.cpp index ffc01613..7ecdde44 100644 --- a/app/avTranscoder/avTranscoder.cpp +++ b/app/avTranscoder/avTranscoder.cpp @@ -26,11 +26,12 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename ) // init video decoders InputVideo inputVideo( input.getStream( 0 ) ); - Image sourceImage( input.getStream( 0 ).getVideoDesc().getImageDesc() ); + ImageDesc imageDesc = input.getStream( 0 ).getVideoDesc().getImageDesc(); + Image sourceImage( imageDesc ); // init video encoder OutputVideo outputVideo; - outputVideo.setProfile( profile.getProfile( "xdcamhd422" ) ); + outputVideo.setProfile( profile.getProfile( "xdcamhd422" ), imageDesc ); Image imageToEncode( outputVideo.getVideoDesc().getImageDesc() ); DataStream codedImage; diff --git a/app/presetChecker/presetChecker.cpp b/app/presetChecker/presetChecker.cpp index 80525ae9..5d37342e 100644 --- a/app/presetChecker/presetChecker.cpp +++ b/app/presetChecker/presetChecker.cpp @@ -25,13 +25,13 @@ int main( int argc, char** argv ) if( profile.find( avtranscoder::Profile::avProfileType )->second == avtranscoder::Profile::avProfileTypeVideo ) { avtranscoder::OutputVideo outputVideo; - outputVideo.setProfile( profile ); + outputVideo.setProfile( profile, outputVideo.getVideoDesc().getImageDesc() ); } if( profile.find( avtranscoder::Profile::avProfileType )->second == avtranscoder::Profile::avProfileTypeAudio ) { avtranscoder::OutputAudio outputAudio; - outputAudio.setProfile( profile ); + outputAudio.setProfile( profile, outputAudio.getAudioDesc().getFrameDesc() ); } } diff --git a/src/AvTranscoder/EssenceStream/OutputAudio.cpp b/src/AvTranscoder/EssenceStream/OutputAudio.cpp index df2ad8a7..50ba4531 100644 --- a/src/AvTranscoder/EssenceStream/OutputAudio.cpp +++ b/src/AvTranscoder/EssenceStream/OutputAudio.cpp @@ -12,6 +12,9 @@ extern "C" { #include #include +#include +#include + namespace avtranscoder { @@ -166,12 +169,21 @@ bool OutputAudio::encodeFrame( DataStream& codedFrame ) #endif } -void OutputAudio::setProfile( Profile::ProfileDesc& desc ) +void OutputAudio::setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc& frameDesc ) { - _audioDesc.setAudioCodec( desc["codec"] ); - size_t sample_rate = atoi( desc["sample_rate"].c_str() ); - size_t channels = atoi( desc["channels"].c_str() ); - _audioDesc.setAudioParameters( sample_rate, channels, av_get_sample_fmt( desc["sample_fmt"].c_str() ) ); + if( ! desc.count( Profile::avProfileCodec ) || + ! desc.count( Profile::avProfileSampleFormat ) || + ! desc.count( Profile::avProfileSampleRate ) || + ! desc.count( Profile::avProfileChannel ) ) + { + throw std::runtime_error( "The profile " + desc[ Profile::avProfileIdentificatorHuman ] + " is invalid." ); + } + + _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() ) ); setup(); } diff --git a/src/AvTranscoder/EssenceStream/OutputAudio.hpp b/src/AvTranscoder/EssenceStream/OutputAudio.hpp index 111eaec0..3632ecd8 100644 --- a/src/AvTranscoder/EssenceStream/OutputAudio.hpp +++ b/src/AvTranscoder/EssenceStream/OutputAudio.hpp @@ -5,6 +5,7 @@ #include #include +#include #include @@ -28,7 +29,7 @@ class OutputAudio : public OutputEssence */ bool encodeFrame( DataStream& codedFrame ); - void setProfile( Profile::ProfileDesc& desc ); + void setProfile( Profile::ProfileDesc& desc, const AudioFrameDesc& frameDesc ); AudioDesc& getAudioDesc() { return _audioDesc; } diff --git a/src/AvTranscoder/EssenceStream/OutputEssence.hpp b/src/AvTranscoder/EssenceStream/OutputEssence.hpp index bd99d772..f7942dc5 100644 --- a/src/AvTranscoder/EssenceStream/OutputEssence.hpp +++ b/src/AvTranscoder/EssenceStream/OutputEssence.hpp @@ -49,13 +49,6 @@ class AvExport OutputEssence */ virtual bool encodeFrame( DataStream& codedFrame ) = 0; - /** - * @brief Set the profile for the encoder - * @note see Profile to get list of supported profiles - * @param desc description of the selected profile - */ - virtual void setProfile( Profile::ProfileDesc& desc ) = 0; - }; } diff --git a/src/AvTranscoder/EssenceStream/OutputVideo.cpp b/src/AvTranscoder/EssenceStream/OutputVideo.cpp index 07981d94..42e212f1 100644 --- a/src/AvTranscoder/EssenceStream/OutputVideo.cpp +++ b/src/AvTranscoder/EssenceStream/OutputVideo.cpp @@ -15,6 +15,9 @@ extern "C" { #include #include +#include +#include + namespace avtranscoder { @@ -176,11 +179,25 @@ bool OutputVideo::encodeFrame( DataStream& codedFrame ) #endif } -void OutputVideo::setProfile( Profile::ProfileDesc& desc ) +void OutputVideo::setProfile( Profile::ProfileDesc& desc, const avtranscoder::ImageDesc& imageDesc ) { - _videoDesc.setVideoCodec( desc[ "codec" ] ); - _videoDesc.setTimeBase( 1, 25 ); // 25 fps - _videoDesc.setImageParameters( 1920, 1080, av_get_pix_fmt( desc[ "pix_fmt" ].c_str() ) ); + if( ! desc.count( Profile::avProfileCodec ) || + ! desc.count( Profile::avProfilePixelFormat ) || + ! desc.count( Profile::avProfileFrameRate ) ) + { + throw std::runtime_error( "The profile " + desc[ Profile::avProfileIdentificatorHuman ] + " is invalid." ); + } + + if( ( desc.count( Profile::avProfileWidth ) && std::strtoul( desc[ Profile::avProfileWidth ].c_str(), NULL, 0 ) != imageDesc.getWidth() ) || + ( desc.count( Profile::avProfileHeight ) && std::strtoul( desc[ Profile::avProfileHeight ].c_str(), NULL, 0 ) != imageDesc.getHeight() ) ) + { + throw std::runtime_error( "Invalid imageDesc with the profile " + desc[ Profile::avProfileIdentificatorHuman ] + "." ); + } + + _videoDesc.setVideoCodec( desc[ Profile::avProfileCodec ] ); + const size_t frameRate = std::strtoul( desc[ Profile::avProfileFrameRate ].c_str(), NULL, 0 ); + _videoDesc.setTimeBase( 1, frameRate ); + _videoDesc.setImageParameters( imageDesc ); for( Profile::ProfileDesc::iterator it = desc.begin(); it != desc.end(); ++it ) { @@ -190,13 +207,15 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc ) continue; if( (*it).first == Profile::avProfileType ) continue; - if( (*it).first == "codec" ) + if( (*it).first == Profile::avProfileCodec ) + continue; + if( (*it).first == Profile::avProfilePixelFormat ) continue; - if( (*it).first == "pix_fmt" ) + if( (*it).first == Profile::avProfileWidth ) continue; - if( (*it).first == "width" ) + if( (*it).first == Profile::avProfileHeight ) continue; - if( (*it).first == "height" ) + if( (*it).first == Profile::avProfileFrameRate ) continue; try @@ -219,13 +238,15 @@ void OutputVideo::setProfile( Profile::ProfileDesc& desc ) continue; if( (*it).first == Profile::avProfileType ) continue; - if( (*it).first == "codec" ) + if( (*it).first == Profile::avProfileCodec ) + continue; + if( (*it).first == Profile::avProfilePixelFormat ) continue; - if( (*it).first == "pix_fmt" ) + if( (*it).first == Profile::avProfileWidth ) continue; - if( (*it).first == "width" ) + if( (*it).first == Profile::avProfileHeight ) continue; - if( (*it).first == "height" ) + if( (*it).first == Profile::avProfileFrameRate ) continue; try diff --git a/src/AvTranscoder/EssenceStream/OutputVideo.hpp b/src/AvTranscoder/EssenceStream/OutputVideo.hpp index 145c0d17..c9e60ff7 100644 --- a/src/AvTranscoder/EssenceStream/OutputVideo.hpp +++ b/src/AvTranscoder/EssenceStream/OutputVideo.hpp @@ -12,6 +12,7 @@ extern "C" { #include #include +#include #include @@ -43,7 +44,7 @@ class AvExport OutputVideo : public OutputEssence */ bool encodeFrame( DataStream& codedFrame ); - void setProfile( Profile::ProfileDesc& desc ); + void setProfile( Profile::ProfileDesc& desc, const avtranscoder::ImageDesc& imageDesc ); VideoDesc& getVideoDesc() { return _videoDesc; } diff --git a/src/AvTranscoder/OptionLoader.cpp b/src/AvTranscoder/OptionLoader.cpp index 53630c91..00867a01 100644 --- a/src/AvTranscoder/OptionLoader.cpp +++ b/src/AvTranscoder/OptionLoader.cpp @@ -65,11 +65,11 @@ OptionLoader::OptionLoader() AVCodec* c = NULL; while( ( c = av_codec_next( c ) ) != NULL ) { -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 53, 34, 0 ) - if( ! c->encode2 ) +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 ) + if( ! c->encode ) continue; #else - if( ! c->encode ) + if( ! c->encode2 ) continue; #endif switch( c->type ) @@ -153,10 +153,10 @@ OptionLoader::OptionMap OptionLoader::loadVideoCodecOptions() // iterate on codecs while( _codec ) { -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 53, 34, 0 ) - if( _codec->encode2 ) -#else +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 ) if( _codec->encode ) +#else + if( _codec->encode2 ) #endif { // add only video codec @@ -189,10 +189,10 @@ OptionLoader::OptionMap OptionLoader::loadAudioCodecOptions() // iterate on codecs while( _codec ) { -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 53, 34, 0 ) - if( _codec->encode2 ) -#else +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 53, 34, 0 ) if( _codec->encode ) +#else + if( _codec->encode2 ) #endif { // add only audio codec @@ -276,7 +276,7 @@ OptionLoader::OptionArray OptionLoader::loadOptions( void* av_class, int req_fla return options; } -std::vector OptionLoader::getPixelFormats ( const std::string& videoCodecName ) const +std::vector OptionLoader::getPixelFormats( const std::string& videoCodecName ) const { std::vector pixelFormats; @@ -284,7 +284,13 @@ std::vector OptionLoader::getPixelFormats ( const std::string& vide if( videoCodecName == "" ) { const AVPixFmtDescriptor* pixFmtDesc = NULL; + +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT( 51, 44, 0 ) + for( int pix_fmt = 0; pix_fmt < PIX_FMT_NB; ++pix_fmt ) + pixFmtDesc = &av_pix_fmt_descriptors[pix_fmt]; +#else while( ( pixFmtDesc = av_pix_fmt_desc_next( pixFmtDesc ) ) != NULL ) +#endif { if( ! pixFmtDesc->name ) continue; @@ -301,7 +307,11 @@ std::vector OptionLoader::getPixelFormats ( const std::string& vide size_t pix_fmt = 0; while( videoCodec->pix_fmts[pix_fmt] != -1 ) { +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT( 51, 44, 0 ) + const AVPixFmtDescriptor* pix_desc = &av_pix_fmt_descriptors[ videoCodec->pix_fmts[pix_fmt] ]; +#else const AVPixFmtDescriptor* pix_desc = av_pix_fmt_desc_get( videoCodec->pix_fmts[pix_fmt] ); +#endif if( ! pix_desc->name ) continue; pixelFormats.push_back( std::string( pix_desc->name ) ); diff --git a/src/AvTranscoder/Profile.cpp b/src/AvTranscoder/Profile.cpp index 5d524344..05cf6e56 100644 --- a/src/AvTranscoder/Profile.cpp +++ b/src/AvTranscoder/Profile.cpp @@ -19,7 +19,14 @@ const std::string Profile::avProfileIdentificatorHuman( "avProfileLong" ); const std::string Profile::avProfileType( "avProfileType" ); const std::string Profile::avProfileTypeVideo( "avProfileTypeVideo" ); const std::string Profile::avProfileTypeAudio( "avProfileTypeAudio" ); - +const std::string Profile::avProfileCodec( "codec" ); +const std::string Profile::avProfilePixelFormat( "pix_fmt" ); +const std::string Profile::avProfileSampleFormat( "sample_fmt" ); +const std::string Profile::avProfileFrameRate( "r" ); +const std::string Profile::avProfileSampleRate( "ar" ); +const std::string Profile::avProfileChannel( "channel" ); +const std::string Profile::avProfileWidth( "width" ); +const std::string Profile::avProfileHeight( "height" ); Profile::Profile( bool autoload ) { diff --git a/src/AvTranscoder/Profile.hpp b/src/AvTranscoder/Profile.hpp index b7092d45..445f8e0d 100644 --- a/src/AvTranscoder/Profile.hpp +++ b/src/AvTranscoder/Profile.hpp @@ -18,6 +18,16 @@ class Profile static const std::string avProfileTypeVideo; static const std::string avProfileTypeAudio; + + static const std::string avProfileCodec; + static const std::string avProfilePixelFormat; + static const std::string avProfileSampleFormat; + static const std::string avProfileFrameRate; + static const std::string avProfileSampleRate; + static const std::string avProfileChannel; + + static const std::string avProfileWidth; + static const std::string avProfileHeight; // typedef std::pair< std::string, std::string > KeyDesc; typedef std::map< std::string, std::string > ProfileDesc; diff --git a/src/AvTranscoder/Profiles/DNxHD.hpp b/src/AvTranscoder/Profiles/DNxHD.hpp index e37bef4d..482f795e 100644 --- a/src/AvTranscoder/Profiles/DNxHD.hpp +++ b/src/AvTranscoder/Profiles/DNxHD.hpp @@ -10,28 +10,31 @@ void loadDNxHD( Profile::ProfilesDesc& profiles ) dnxhd120[ Profile::avProfileIdentificator ] = "dnxhd120"; dnxhd120[ Profile::avProfileIdentificatorHuman ] = "DNxHD 120"; dnxhd120[ Profile::avProfileType ] = Profile::avProfileTypeVideo; - dnxhd120[ "codec" ] = "dnxhd"; + dnxhd120[ Profile::avProfileCodec ] = "dnxhd"; dnxhd120[ "b" ] = "120000000"; - dnxhd120[ "pix_fmt" ] = "yuv422p"; + dnxhd120[ Profile::avProfilePixelFormat ] = "yuv422p"; dnxhd120[ "g" ] = "1"; + dnxhd120[ Profile::avProfileFrameRate ] = "25"; Profile::ProfileDesc dnxhd185; dnxhd185[ Profile::avProfileIdentificator ] = "dnxhd185"; dnxhd185[ Profile::avProfileIdentificatorHuman ] = "DNxHD 185"; dnxhd185[ Profile::avProfileType ] = Profile::avProfileTypeVideo; - dnxhd185[ "codec" ] = "dnxhd"; + dnxhd185[ Profile::avProfileCodec ] = "dnxhd"; dnxhd185[ "b" ] = "185000000"; - dnxhd185[ "pix_fmt" ] = "yuv422p"; + dnxhd185[ Profile::avProfilePixelFormat ] = "yuv422p"; dnxhd185[ "g" ] = "1"; + dnxhd185[ Profile::avProfileFrameRate ] = "25"; Profile::ProfileDesc dnxhd185x; dnxhd185x[ Profile::avProfileIdentificator ] = "dnxhd185x"; dnxhd185x[ Profile::avProfileIdentificatorHuman ] = "DNxHD 185 X"; dnxhd185x[ Profile::avProfileType ] = Profile::avProfileTypeVideo; - dnxhd185x[ "codec" ] = "dnxhd"; + dnxhd185x[ Profile::avProfileCodec ] = "dnxhd"; dnxhd185x[ "b" ] = "185000000"; - dnxhd185x[ "pix_fmt" ] = "yuv422p10"; + dnxhd185x[ Profile::avProfilePixelFormat ] = "yuv422p10"; dnxhd185x[ "g" ] = "1"; + dnxhd185x[ Profile::avProfileFrameRate ] = "25"; profiles.push_back( dnxhd120 ); profiles.push_back( dnxhd185 ); diff --git a/src/AvTranscoder/Profiles/Wave.hpp b/src/AvTranscoder/Profiles/Wave.hpp index d770c235..3e12d150 100644 --- a/src/AvTranscoder/Profiles/Wave.hpp +++ b/src/AvTranscoder/Profiles/Wave.hpp @@ -12,10 +12,10 @@ void loadWave( Profile::ProfilesDesc& profiles ) wave24b48kMono[ Profile::avProfileIdentificatorHuman ] = "Wave 24bits 48kHz mono"; wave24b48kMono[ Profile::avProfileType ] = Profile::avProfileTypeAudio; - wave24b48kMono[ "codec" ] = "pcm_s24le"; - wave24b48kMono[ "sample_fmt" ] = "s32"; - wave24b48kMono[ "sample_rate" ] = "48000"; - wave24b48kMono[ "channels" ] = "1"; + wave24b48kMono[ Profile::avProfileCodec ] = "pcm_s24le"; + wave24b48kMono[ Profile::avProfileSampleFormat ] = "s32"; + wave24b48kMono[ Profile::avProfileSampleRate ] = "48000"; + wave24b48kMono[ Profile::avProfileChannel ] = "1"; Profile::ProfileDesc wave16b48kMono; @@ -23,10 +23,10 @@ void loadWave( Profile::ProfilesDesc& profiles ) wave16b48kMono[ Profile::avProfileIdentificatorHuman ] = "Wave 16bits 48kHz mono"; wave16b48kMono[ Profile::avProfileType ] = Profile::avProfileTypeAudio; - wave16b48kMono[ "codec" ] = "pcm_s16le"; - wave16b48kMono[ "sample_fmt" ] = "s16"; - wave16b48kMono[ "sample_rate" ] = "48000"; - wave16b48kMono[ "channels" ] = "1"; + wave16b48kMono[ Profile::avProfileCodec ] = "pcm_s16le"; + wave16b48kMono[ Profile::avProfileSampleFormat ] = "s16"; + wave16b48kMono[ Profile::avProfileSampleRate ] = "48000"; + wave16b48kMono[ Profile::avProfileChannel ] = "1"; profiles.push_back( wave24b48kMono ); profiles.push_back( wave16b48kMono ); diff --git a/src/AvTranscoder/Profiles/XdCamHd422.hpp b/src/AvTranscoder/Profiles/XdCamHd422.hpp index af1226ab..40558ef3 100644 --- a/src/AvTranscoder/Profiles/XdCamHd422.hpp +++ b/src/AvTranscoder/Profiles/XdCamHd422.hpp @@ -13,7 +13,7 @@ void loadXdCamHD422( Profile::ProfilesDesc& profiles ) xdCamHd422[ Profile::avProfileType ] = Profile::avProfileTypeVideo; - xdCamHd422[ "codec" ] = "mpeg2video"; + xdCamHd422[ Profile::avProfileCodec ] = "mpeg2video"; xdCamHd422[ "profile" ] = "0"; // FF_PROFILE_MPEG2_422 xdCamHd422[ "level" ] = "2"; @@ -23,8 +23,9 @@ void loadXdCamHD422( Profile::ProfilesDesc& profiles ) xdCamHd422[ "qmin" ] = "2"; xdCamHd422[ "qmax" ] = "12"; xdCamHd422[ "dc" ] = "2"; // 10 - 8 = 2 + xdCamHd422[ Profile::avProfileFrameRate ] = "25"; - xdCamHd422[ "pix_fmt" ] = "yuv422p"; + xdCamHd422[ Profile::avProfilePixelFormat ] = "yuv422p"; // color informations are not used in FFmpeg/LibAV for Mpeg2 xdCamHd422[ "colorspace" ] = "1"; // AVCOL_SPC_BT709 diff --git a/src/AvTranscoder/Transcoder/StreamTranscoder.cpp b/src/AvTranscoder/Transcoder/StreamTranscoder.cpp index 86149b80..53fbf7bf 100644 --- a/src/AvTranscoder/Transcoder/StreamTranscoder.cpp +++ b/src/AvTranscoder/Transcoder/StreamTranscoder.cpp @@ -3,6 +3,9 @@ #include +#include +#include + #include #include @@ -19,8 +22,6 @@ StreamTranscoder::StreamTranscoder( , _outputStream( NULL ) , _sourceBuffer( NULL ) , _frameBuffer( NULL ) - , _videoFrameBuffer( NULL ) - , _audioFrameBuffer( NULL ) , _inputEssence( NULL ) , _outputEssence( NULL ) , _transform( NULL ) @@ -53,8 +54,6 @@ StreamTranscoder::StreamTranscoder( , _outputStream( NULL ) , _sourceBuffer( NULL ) , _frameBuffer( NULL ) - , _videoFrameBuffer( NULL ) - , _audioFrameBuffer( NULL ) , _inputEssence( NULL ) , _outputEssence( NULL ) , _transform( NULL ) @@ -71,13 +70,12 @@ StreamTranscoder::StreamTranscoder( OutputVideo* outputVideo = new OutputVideo(); _outputEssence = outputVideo; - _outputEssence->setProfile( profile ); + outputVideo->setProfile( profile, _inputStream->getVideoDesc().getImageDesc() ); _outputStream = &outputFile.addVideoStream( outputVideo->getVideoDesc() ); _sourceBuffer = new Image( _inputStream->getVideoDesc().getImageDesc() ); - _videoFrameBuffer = new Image( outputVideo->getVideoDesc().getImageDesc() ); - _frameBuffer = _videoFrameBuffer; + _frameBuffer = new Image( outputVideo->getVideoDesc().getImageDesc() ); _transform = new VideoEssenceTransform(); @@ -91,13 +89,12 @@ StreamTranscoder::StreamTranscoder( OutputAudio* outputAudio = new OutputAudio(); _outputEssence = outputAudio; - _outputEssence->setProfile( profile ); + outputAudio->setProfile( profile, _inputStream->getAudioDesc().getFrameDesc() ); _outputStream = &outputFile.addAudioStream( outputAudio->getAudioDesc() ); _sourceBuffer = new AudioFrame( _inputStream->getAudioDesc().getFrameDesc() ); - _audioFrameBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() ); - _frameBuffer = _audioFrameBuffer; + _frameBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() ); _transform = new AudioEssenceTransform(); @@ -120,8 +117,6 @@ StreamTranscoder::StreamTranscoder( , _outputStream( NULL ) , _sourceBuffer( NULL ) , _frameBuffer( NULL ) - , _videoFrameBuffer( NULL ) - , _audioFrameBuffer( NULL ) , _inputEssence( &inputEssence ) , _outputEssence( NULL ) , _transform( NULL ) @@ -135,24 +130,34 @@ StreamTranscoder::StreamTranscoder( OutputAudio* outputAudio = new OutputAudio(); _outputEssence = outputAudio; - _outputEssence->setProfile( profile ); - + AudioFrameDesc srcAudioFrameDesc; // @todo better solution ? + outputAudio->setProfile( profile, srcAudioFrameDesc ); + + static_cast( _inputEssence )->setAudioDesc( outputAudio->getAudioDesc() ); + _outputStream = &outputFile.addAudioStream( outputAudio->getAudioDesc() ); - _audioFrameBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() ); - _frameBuffer = _audioFrameBuffer; + _sourceBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() ); + _frameBuffer = new AudioFrame( outputAudio->getAudioDesc().getFrameDesc() ); + + _transform = new AudioEssenceTransform(); + return; } if( profile.find( Profile::avProfileType )->second == Profile::avProfileTypeVideo ) { OutputVideo* outputVideo = new OutputVideo(); - + _outputEssence = outputVideo; - _outputEssence->setProfile( profile ); + ImageDesc srcImageDesc; // @todo better solution ? + outputVideo->setProfile( profile, srcImageDesc ); _outputStream = &outputFile.addVideoStream( outputVideo->getVideoDesc() ); - _videoFrameBuffer = new Image( outputVideo->getVideoDesc().getImageDesc() ); - _frameBuffer = _videoFrameBuffer; + _sourceBuffer = new Image( outputVideo->getVideoDesc().getImageDesc() ); + _frameBuffer = new Image( outputVideo->getVideoDesc().getImageDesc() ); + + _transform = new VideoEssenceTransform(); + return; } @@ -199,24 +204,20 @@ bool StreamTranscoder::processTranscode() assert( _sourceBuffer != NULL ); assert( _frameBuffer != NULL ); - std::cout << "transcode" << std::endl; - DataStream dataStream; if( _inputEssence->readNextFrame( *_sourceBuffer ) ) - { + { _transform->convert( *_sourceBuffer, *_frameBuffer ); _outputEssence->encodeFrame( *_frameBuffer, dataStream ); } else { - std::cout << "encode last frame" << std::endl; if( ! _outputEssence->encodeFrame( dataStream ) ) { return false; } } - std::cout << "wrap" << std::endl; _outputStream->wrap( dataStream ); return true; } diff --git a/src/AvTranscoder/Transcoder/StreamTranscoder.hpp b/src/AvTranscoder/Transcoder/StreamTranscoder.hpp index 32bab884..10257307 100644 --- a/src/AvTranscoder/Transcoder/StreamTranscoder.hpp +++ b/src/AvTranscoder/Transcoder/StreamTranscoder.hpp @@ -56,8 +56,6 @@ class StreamTranscoder Frame* _sourceBuffer; Frame* _frameBuffer; - Image* _videoFrameBuffer; - AudioFrame* _audioFrameBuffer; InputEssence* _inputEssence; OutputEssence* _outputEssence; diff --git a/src/AvTranscoder/Transcoder/Transcoder.cpp b/src/AvTranscoder/Transcoder/Transcoder.cpp index 8ce3b530..1f18a8b8 100644 --- a/src/AvTranscoder/Transcoder/Transcoder.cpp +++ b/src/AvTranscoder/Transcoder/Transcoder.cpp @@ -20,14 +20,6 @@ Transcoder::~Transcoder() { delete (*it); } - for( std::vector< DummyAudio* >::iterator it = _dummyAudio.begin(); it != _dummyAudio.end(); ++it ) - { - delete (*it); - } - for( std::vector< DummyVideo* >::iterator it = _dummyVideo.begin(); it != _dummyVideo.end(); ++it ) - { - delete (*it); - } for( std::vector< StreamTranscoder* >::iterator it = _streamTranscoders.begin(); it != _streamTranscoders.end(); ++it ) { delete (*it); @@ -175,15 +167,15 @@ void Transcoder::addDummyStream( Profile::ProfileDesc& profile ) if( profile.find( Profile::avProfileType )->second == Profile::avProfileTypeAudio ) { - _dummyAudio.push_back( new DummyAudio() ); - StreamTranscoder* streamTranscoder = new StreamTranscoder( *_dummyAudio.back(), _outputFile, profile ); + DummyAudio* dummyAudio = new DummyAudio(); + StreamTranscoder* streamTranscoder = new StreamTranscoder( *dummyAudio, _outputFile, profile ); _streamTranscoders.push_back( streamTranscoder ); } if( profile.find( Profile::avProfileType )->second == Profile::avProfileTypeVideo ) { - _dummyVideo.push_back( new DummyVideo() ); - StreamTranscoder* streamTranscoder = new StreamTranscoder( *_dummyVideo.back(), _outputFile, profile ); + DummyVideo* dummyVideo = new DummyVideo(); + StreamTranscoder* streamTranscoder = new StreamTranscoder( *dummyVideo, _outputFile, profile ); _streamTranscoders.push_back( streamTranscoder ); } } diff --git a/src/AvTranscoder/Transcoder/Transcoder.hpp b/src/AvTranscoder/Transcoder/Transcoder.hpp index 000f0120..60ee3c2e 100644 --- a/src/AvTranscoder/Transcoder/Transcoder.hpp +++ b/src/AvTranscoder/Transcoder/Transcoder.hpp @@ -60,8 +60,6 @@ class Transcoder std::vector< InputStream* > _inputStreams; std::vector< StreamTranscoder* > _streamTranscoders; - std::vector< DummyAudio* > _dummyAudio; - std::vector< DummyVideo* > _dummyVideo; Profile _profile; bool _verbose;