diff --git a/app/genericProcessor/genericProcessor.cpp b/app/genericProcessor/genericProcessor.cpp index 95591013..db03b50e 100644 --- a/app/genericProcessor/genericProcessor.cpp +++ b/app/genericProcessor/genericProcessor.cpp @@ -114,14 +114,11 @@ int main( int argc, char** argv ) // set verbose of all stream transcoder.setVerbose( verbose ); transcoder.setProcessMethod( avtranscoder::eProcessMethodLongest ); - transcoder.init(); if( verbose ) std::cout << "start Transcode" << std::endl; avtranscoder::ConsoleProgress progress; - - // video re-wrapping or transcoding if necessary transcoder.process( progress ); std::cout << std::endl; diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.cpp b/src/AvTranscoder/transcoder/StreamTranscoder.cpp index a881db5a..41fa3e00 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.cpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.cpp @@ -259,7 +259,7 @@ StreamTranscoder::~StreamTranscoder() void StreamTranscoder::init() { - // rewrap + // rewrap case: no need to take care of the latency of codec if( ! _inputEssence ) return; diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 5e9df8f7..2791bbd2 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -22,7 +22,11 @@ Transcoder::Transcoder( OutputFile& outputFile ) , _mainStreamIndex( 0 ) , _verbose( false ) { + // Initialize the OutputFile _outputFile.setup(); + + // Print no output from ffmpeg + av_log_set_level( AV_LOG_QUIET ); } Transcoder::~Transcoder() @@ -252,19 +256,17 @@ void Transcoder::init() bool Transcoder::processFrame() { if( _streamTranscoders.size() == 0 ) - { return false; - } if( _verbose ) std::cout << "process frame" << std::endl; + for( size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex ) { if( _verbose ) std::cout << "process stream " << streamIndex << "/" << _streamTranscoders.size() - 1 << std::endl; bool streamProcessStatus = _streamTranscoders.at( streamIndex )->processFrame(); - if( ! streamProcessStatus ) { _streamTranscoders.clear(); @@ -276,51 +278,30 @@ bool Transcoder::processFrame() void Transcoder::process( IProgress& progress ) { - size_t frame = 0; - - if( ! _streamTranscoders.size() ) - { + if( _streamTranscoders.size() == 0 ) throw std::runtime_error( "missing input streams in transcoder" ); - } - + + manageInfinityStreamFromProcessMethod(); + if( _verbose ) std::cout << "begin transcoding" << std::endl; + init(); _outputFile.beginWrap(); - double totalDuration = std::numeric_limits::max(); - switch( _eProcessMethod ) - { - case eProcessMethodShortest : - totalDuration = getMinTotalDuration(); - break; - case eProcessMethodLongest : - totalDuration = getMaxTotalDuration(); - break; - case eProcessMethodBasedOnStream : - totalDuration = getStreamDuration( _mainStreamIndex ); - break; - case eProcessMethodInfinity : - totalDuration = std::numeric_limits::max(); - break; - } + double totalDuration = getTotalDurationFromProcessMethod(); - if( _verbose ) - av_log_set_level( AV_LOG_DEBUG ); - - while( 1 ) + size_t frame = 0; + bool frameProcessed = true; + while( frameProcessed ) { if( _verbose ) std::cout << "process frame " << frame << std::endl; - bool frameProcessed = processFrame(); - if( ! frameProcessed ) - break; + frameProcessed = processFrame(); if( progress.progress( _outputFile.getProgressDuration(), totalDuration ) == eJobStatusCancel ) - { break; - } ++frame; } @@ -335,34 +316,6 @@ void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod, const si { _eProcessMethod = eProcessMethod; _mainStreamIndex = indexBasedStream; - - for( size_t i = 0; i < _streamTranscoders.size(); ++i ) - { - switch( _eProcessMethod ) - { - case eProcessMethodShortest : - if( _streamTranscoders.at( i )->getDuration() == getMinTotalDuration() ) - _streamTranscoders.at( i )->setInfinityStream( false ); - else - _streamTranscoders.at( i )->setInfinityStream( true ); - break; - case eProcessMethodLongest : - if( _streamTranscoders.at( i )->getDuration() == getMaxTotalDuration() ) - _streamTranscoders.at( i )->setInfinityStream( false ); - else - _streamTranscoders.at( i )->setInfinityStream( true ); - break; - case eProcessMethodBasedOnStream : - if( i != _mainStreamIndex ) - _streamTranscoders.at( i )->setInfinityStream( true ); - else - _streamTranscoders.at( i )->setInfinityStream( false ); - break; - case eProcessMethodInfinity : - _streamTranscoders.at( i )->setInfinityStream( true ); - break; - } - } } void Transcoder::setVerbose( bool verbose ) @@ -373,6 +326,10 @@ void Transcoder::setVerbose( bool verbose ) (*it)->setVerbose( _verbose ); } _outputFile.setVerbose( _verbose ); + + // Print stuff which is only useful for ffmpeg developers. + if( _verbose ) + av_log_set_level( AV_LOG_DEBUG ); } void Transcoder::addRewrapStream( const std::string& filename, const size_t streamIndex ) @@ -528,4 +485,52 @@ double Transcoder::getMaxTotalDuration() const return maxTotalDuration; } +double Transcoder::getTotalDurationFromProcessMethod() const +{ + switch( _eProcessMethod ) + { + case eProcessMethodShortest : + return getMinTotalDuration(); + case eProcessMethodLongest : + return getMaxTotalDuration(); + case eProcessMethodBasedOnStream : + return getStreamDuration( _mainStreamIndex ); + case eProcessMethodInfinity : + return std::numeric_limits::max(); + default: + return getMaxTotalDuration(); + } +} + +void Transcoder::manageInfinityStreamFromProcessMethod() +{ + for( size_t i = 0; i < _streamTranscoders.size(); ++i ) + { + switch( _eProcessMethod ) + { + case eProcessMethodShortest : + if( _streamTranscoders.at( i )->getDuration() == getMinTotalDuration() ) + _streamTranscoders.at( i )->setInfinityStream( false ); + else + _streamTranscoders.at( i )->setInfinityStream( true ); + break; + case eProcessMethodLongest : + if( _streamTranscoders.at( i )->getDuration() == getMaxTotalDuration() ) + _streamTranscoders.at( i )->setInfinityStream( false ); + else + _streamTranscoders.at( i )->setInfinityStream( true ); + break; + case eProcessMethodBasedOnStream : + if( i != _mainStreamIndex ) + _streamTranscoders.at( i )->setInfinityStream( true ); + else + _streamTranscoders.at( i )->setInfinityStream( false ); + break; + case eProcessMethodInfinity : + _streamTranscoders.at( i )->setInfinityStream( true ); + break; + } + } +} + } diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index fcd34c96..ea50ddce 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -43,7 +43,9 @@ enum EProcessMethod class AvExport Transcoder { public: - + /** + * @note Set FFmpeg log level to quite. + */ Transcoder( OutputFile& outputFile ); ~Transcoder(); @@ -112,7 +114,9 @@ class AvExport Transcoder /** * @brief Process all the streams, and ended the process depending on the transcode politic. - * @param progress + * @note The function manages all process: init(), beginWrap(), processFrame()s, and endWrap(). + * @param progress: choose a progress, or create your own in C++ or in bindings by inherit IProgress class. + * @see IProgress */ void process( IProgress& progress ); @@ -124,20 +128,19 @@ class AvExport Transcoder /** * @brief Set the transcodage politic. - * @note Call it after adding the streams. * @note By default eProcessMethodLongest. * @param indexBasedStream: in case of process method eProcessMethodBasedOnStream, stop transcode at the end of the indicated stream. */ void setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream = 0 ); /** - * @brief Set verbose mode for the Transcoder and its streams. + * @brief Set verbose mode for the Transcoder, its streams, and its output file. * @note If you call it before adding the streams, no verbose mode will be set for the new streams. + * @note set av log level to AV_LOG_DEBUG */ void setVerbose( bool verbose = true ); private: - void addRewrapStream( const std::string& filename, const size_t streamIndex ); void addTranscodeStream( const std::string& filename, const size_t streamIndex, const size_t subStreamIndex, const size_t offset ); ///< Get profile from input @@ -164,6 +167,17 @@ class AvExport Transcoder */ double getMaxTotalDuration() const; + /** + * @brief Get the duration of the output program + * @note Depends on the streams, the process method, and the main stream index. + */ + double getTotalDurationFromProcessMethod() const; + + /** + * @brief Set for each StreamTranscoder if it is an infinity stream (switch to generator at the end of the stream). + */ + void manageInfinityStreamFromProcessMethod(); + private: OutputFile& _outputFile; ///< The output media file after process. std::vector< InputFile* > _inputFiles; ///< The list of input files which contain added streams. diff --git a/test/pyTest/testTranscoderAdd.py b/test/pyTest/testTranscoderAdd.py index ea5a6f91..ebb2304c 100644 --- a/test/pyTest/testTranscoderAdd.py +++ b/test/pyTest/testTranscoderAdd.py @@ -25,6 +25,5 @@ def testAddStreamTranscoder(): # process progress = av.NoDisplayProgress() - transcoder.init() transcoder.process( progress ) diff --git a/test/pyTest/testTranscoderTranscode.py b/test/pyTest/testTranscoderTranscode.py index 72f969fa..e593e3fa 100644 --- a/test/pyTest/testTranscoderTranscode.py +++ b/test/pyTest/testTranscoderTranscode.py @@ -17,7 +17,6 @@ def testTranscodeWave24b48kmono(): transcoder.add( inputFileName, 0, "wave24b48kmono" ) - transcoder.init() progress = av.ConsoleProgress() transcoder.process( progress ) @@ -47,7 +46,6 @@ def testTranscodeWave16b48kmono(): transcoder.add( inputFileName, 0, "wave16b48kmono" ) - transcoder.init() progress = av.ConsoleProgress() transcoder.process( progress ) @@ -77,7 +75,6 @@ def testTranscodeWave16b48kmono(): # transcoder.add( inputFileName, 0, "dnxhd120" ) -# transcoder.init() # progress = av.ConsoleProgress() # transcoder.process( progress ) @@ -106,7 +103,6 @@ def testTranscodeWave16b48kmono(): # transcoder.add( inputFileName, 0, "dnxhd185" ) -# transcoder.init() # progress = av.ConsoleProgress() # transcoder.process( progress ) @@ -135,7 +131,6 @@ def testTranscodeWave16b48kmono(): # transcoder.add( inputFileName, 0, "dnxhd185x" ) -# transcoder.init() # progress = av.ConsoleProgress() # transcoder.process( progress ) @@ -164,7 +159,6 @@ def testTranscodeWave16b48kmono(): # transcoder.add( inputFileName, 0, "xdcamhd422" ) -# transcoder.init() # progress = av.ConsoleProgress() # transcoder.process( progress ) @@ -213,7 +207,6 @@ def testTranscodeWave16b48kmono(): # transcoder.add( inputFileName, 0, customProfile ) -# transcoder.init() # progress = av.ConsoleProgress() # transcoder.process( progress )