Skip to content

Transcoder: add process method based on stream #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/AvTranscoder/transcoder/Transcoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Transcoder::Transcoder( OutputFile& outputFile )
, _outputFps( 25 )
, _finalisedStreams( 0 )
, _eProcessMethod ( eProcessMethodLongest )
, _mainStreamIndex( 0 )
, _verbose( false )
{
_outputFile.setup();
Expand Down Expand Up @@ -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<double>::max();
break;
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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;
Expand Down Expand Up @@ -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<double>::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;
}
Expand All @@ -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;
}
Expand Down
14 changes: 12 additions & 2 deletions src/AvTranscoder/transcoder/Transcoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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.
Expand All @@ -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;

Expand All @@ -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;
};

Expand Down