diff --git a/src/AvTranscoder/file/OutputFile.cpp b/src/AvTranscoder/file/OutputFile.cpp index b3efd712..d143b6ff 100644 --- a/src/AvTranscoder/file/OutputFile.cpp +++ b/src/AvTranscoder/file/OutputFile.cpp @@ -293,11 +293,10 @@ void OutputFile::setProfile( const ProfileLoader::Profile& profile ) double OutputFile::getProgressDuration() { - AVStream* firstOutputStream = _formatContext->streams[0]; - if( firstOutputStream == NULL ) + if( _formatContext->nb_streams == 0 ) throw std::runtime_error( "at least one stream must be set to get the progress duration" ); - double duration = av_q2d( firstOutputStream->time_base ) * firstOutputStream->cur_dts; - return duration; + AVStream* firstOutputStream = _formatContext->streams[0]; + return av_q2d( firstOutputStream->time_base ) * firstOutputStream->cur_dts; } } diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.cpp b/src/AvTranscoder/transcoder/StreamTranscoder.cpp index 41fa3e00..034d8138 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.cpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.cpp @@ -257,7 +257,7 @@ StreamTranscoder::~StreamTranscoder() delete _inputEssence; } -void StreamTranscoder::init() +void StreamTranscoder::preProcessCodecLatency() { // rewrap case: no need to take care of the latency of codec if( ! _inputEssence ) diff --git a/src/AvTranscoder/transcoder/StreamTranscoder.hpp b/src/AvTranscoder/transcoder/StreamTranscoder.hpp index e5d40ff8..2567f37f 100644 --- a/src/AvTranscoder/transcoder/StreamTranscoder.hpp +++ b/src/AvTranscoder/transcoder/StreamTranscoder.hpp @@ -41,11 +41,11 @@ class AvExport StreamTranscoder ~StreamTranscoder(); /** - * @brief Init before encoding to pre-process frames necessary to delete the latency. + * @brief Pre-process codec latency. * @note This can be called several times with no side effects. * @note Can take a little bit of time. */ - void init(); + void preProcessCodecLatency(); /** * @brief process a single frame for the current stream diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index 2791bbd2..0a20f12d 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -243,13 +243,13 @@ void Transcoder::add( StreamTranscoder& stream ) _streamTranscoders.push_back( &stream ); } -void Transcoder::init() +void Transcoder::preProcessCodecLatency() { for( size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex ) { if( _verbose ) std::cout << "init stream " << streamIndex << std::endl; - _streamTranscoders.at( streamIndex )->init(); + _streamTranscoders.at( streamIndex )->preProcessCodecLatency(); } } @@ -285,10 +285,11 @@ void Transcoder::process( IProgress& progress ) if( _verbose ) std::cout << "begin transcoding" << std::endl; - init(); - + _outputFile.beginWrap(); + preProcessCodecLatency(); + double totalDuration = getTotalDurationFromProcessMethod(); size_t frame = 0; diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index ea50ddce..acc65f33 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -100,11 +100,11 @@ class AvExport Transcoder void add( StreamTranscoder& streamTranscoder); /** - * @brief Initialize all streams added, by ensure process necessary frames in case of latency. + * @brief Initialize all added streams, processing codec latency. * @note This can be called several times with no side effects. * @note Can take a little bit of time. */ - void init(); + void preProcessCodecLatency(); /** * @brief Process the next frame of all streams. diff --git a/test/pyTest/testSetFrame.py b/test/pyTest/testSetFrame.py index 241cdf22..744a85c7 100644 --- a/test/pyTest/testSetFrame.py +++ b/test/pyTest/testSetFrame.py @@ -35,8 +35,8 @@ def testSetVideoFrame(): videoEssence = transcoder.getStreamTranscoder( 0 ).getCurrentEssence() # start process - transcoder.init() ouputFile.beginWrap() + transcoder.preProcessCodecLatency() # process 255 frames for i in range(0,255): @@ -88,8 +88,8 @@ def testSetAudioFrame(): audioEssence = transcoder.getStreamTranscoder( 0 ).getCurrentEssence() # start process - transcoder.init() ouputFile.beginWrap() + transcoder.preProcessCodecLatency() # process 255 frames for i in range(0,255): diff --git a/test/pyTest/testTranscoderDummy.py b/test/pyTest/testTranscoderDummy.py index cdc145f4..6964c824 100644 --- a/test/pyTest/testTranscoderDummy.py +++ b/test/pyTest/testTranscoderDummy.py @@ -90,8 +90,6 @@ def testTranscodeDummyAudio(): audioCodec.setAudioParameters( audioDesc ) transcoder.add( "", 0, "wave24b48kmono", audioCodec ) - transcoder.init() - ouputFile.beginWrap() transcoder.processFrame() ouputFile.endWrap() @@ -116,8 +114,6 @@ def testTranscodeDummyVideo(): videoCodec.setImageParameters( imageDesc ) transcoder.add( "", 0, "dnxhd120", videoCodec ) - transcoder.init() - ouputFile.beginWrap() transcoder.processFrame() ouputFile.endWrap()