diff --git a/src/AvTranscoder/transcoder/Transcoder.cpp b/src/AvTranscoder/transcoder/Transcoder.cpp index ba5b1546..54407c2c 100644 --- a/src/AvTranscoder/transcoder/Transcoder.cpp +++ b/src/AvTranscoder/transcoder/Transcoder.cpp @@ -17,6 +17,7 @@ Transcoder::Transcoder( OutputFile& outputFile ) , _outputFps( 25 ) , _finalisedStreams( 0 ) , _eProcessMethod ( eProcessMethodLongest ) + , _mainStreamIndex( 0 ) , _verbose( false ) { _outputFile.setup(); @@ -275,6 +276,9 @@ void Transcoder::process( IProgress& progress ) case eProcessMethodLongest : totalDuration = getMaxTotalDuration(); break; + case eProcessMethodBasedOnStream : + totalDuration = getStreamDuration( _mainStreamIndex ); + break; case eProcessMethodInfinity : totalDuration = std::numeric_limits::max(); break; @@ -304,9 +308,10 @@ void Transcoder::process( IProgress& progress ) _outputFile.endWrap(); } -void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod ) +void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream ) { _eProcessMethod = eProcessMethod; + _mainStreamIndex = indexBasedStream; for( size_t i = 0; i < _streamTranscoders.size(); ++i ) { @@ -324,6 +329,12 @@ void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod ) 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; @@ -447,13 +458,18 @@ InputFile* Transcoder::addInputFile( const std::string& filename, const size_t s return referenceFile; } +double Transcoder::getStreamDuration( size_t indexStream ) const +{ + return _streamTranscoders.at( indexStream )->getDuration(); +} + double Transcoder::getMinTotalDuration() const { double minTotalDuration = std::numeric_limits::max(); for( size_t i = 0; i < _streamTranscoders.size(); ++i ) { - minTotalDuration = std::min( _streamTranscoders.at( i )->getDuration(), minTotalDuration ); + minTotalDuration = std::min( getStreamDuration( i ), minTotalDuration ); } return minTotalDuration; } @@ -464,7 +480,7 @@ double Transcoder::getMaxTotalDuration() const for( size_t i = 0; i < _streamTranscoders.size(); ++i ) { - maxTotalDuration = std::max( _streamTranscoders.at( i )->getDuration(), maxTotalDuration ); + maxTotalDuration = std::max( getStreamDuration( i ), maxTotalDuration ); } return maxTotalDuration; } diff --git a/src/AvTranscoder/transcoder/Transcoder.hpp b/src/AvTranscoder/transcoder/Transcoder.hpp index b1c77005..574ba615 100644 --- a/src/AvTranscoder/transcoder/Transcoder.hpp +++ b/src/AvTranscoder/transcoder/Transcoder.hpp @@ -27,12 +27,14 @@ namespace avtranscoder * @brief: Enum to set a policy of how we manage the transcode in case of several streams. * eProcessMethodShortest: stop transcode at the end of the shortest stream. * eProcessMethodLongest: stop transcode at the end of the longest stream (default method). + * eProcessMethodBasedOnStream: stop transcode at the end of an indicated stream (@see _indexBasedStream). * eProcessMethodInfinity: stop transcode by outside of avTranscoder. */ enum EProcessMethod { eProcessMethodShortest = 0, eProcessMethodLongest, + eProcessMethodBasedOnStream, eProcessMethodInfinity, }; @@ -116,8 +118,9 @@ class Transcoder /** * @brief Set the transcodage politic. * @note If you call it before adding the streams, the process will stop at the end of the shortest stream. + * @param indexBasedStream: in case of process method eProcessMethodBasedOnStream, stop transcode at the end of the indicated stream. */ - void setProcessMethod( const EProcessMethod eProcessMethod ); + void setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream = 0 ); /** * @brief Set verbose mode for the Transcoder and his streams. @@ -139,9 +142,14 @@ class Transcoder InputFile* addInputFile( const std::string& filename, const size_t streamIndex ); + /** + * @brief Get the duration of the stream. + */ + double getStreamDuration( size_t indexStream ) const; + /** * @brief Get the duration of the shortest stream. - * @note if there is only generated streams, return limit of double. + * @note if there is only generated streams, return limit of double. */ double getMinTotalDuration() const; @@ -168,6 +176,8 @@ class Transcoder size_t _finalisedStreams; EProcessMethod _eProcessMethod; + size_t _mainStreamIndex; ///< Index of stream used to stop the process of transcode in case of eProcessMethodBasedOnStream. + bool _verbose; };