Skip to content

Commit 5ebabd0

Browse files
Merge pull request #106 from cchampet/feature/FTDMAT-326
Transcoder: add process method based on stream
2 parents 7d0c399 + 0cb94e6 commit 5ebabd0

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Transcoder::Transcoder( OutputFile& outputFile )
1717
, _outputFps( 25 )
1818
, _finalisedStreams( 0 )
1919
, _eProcessMethod ( eProcessMethodLongest )
20+
, _mainStreamIndex( 0 )
2021
, _verbose( false )
2122
{
2223
_outputFile.setup();
@@ -275,6 +276,9 @@ void Transcoder::process( IProgress& progress )
275276
case eProcessMethodLongest :
276277
totalDuration = getMaxTotalDuration();
277278
break;
279+
case eProcessMethodBasedOnStream :
280+
totalDuration = getStreamDuration( _mainStreamIndex );
281+
break;
278282
case eProcessMethodInfinity :
279283
totalDuration = std::numeric_limits<double>::max();
280284
break;
@@ -304,9 +308,10 @@ void Transcoder::process( IProgress& progress )
304308
_outputFile.endWrap();
305309
}
306310

307-
void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod )
311+
void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream )
308312
{
309313
_eProcessMethod = eProcessMethod;
314+
_mainStreamIndex = indexBasedStream;
310315

311316
for( size_t i = 0; i < _streamTranscoders.size(); ++i )
312317
{
@@ -324,6 +329,12 @@ void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod )
324329
else
325330
_streamTranscoders.at( i )->setInfinityStream( true );
326331
break;
332+
case eProcessMethodBasedOnStream :
333+
if( i != _mainStreamIndex )
334+
_streamTranscoders.at( i )->setInfinityStream( true );
335+
else
336+
_streamTranscoders.at( i )->setInfinityStream( false );
337+
break;
327338
case eProcessMethodInfinity :
328339
_streamTranscoders.at( i )->setInfinityStream( true );
329340
break;
@@ -447,13 +458,18 @@ InputFile* Transcoder::addInputFile( const std::string& filename, const size_t s
447458
return referenceFile;
448459
}
449460

461+
double Transcoder::getStreamDuration( size_t indexStream ) const
462+
{
463+
return _streamTranscoders.at( indexStream )->getDuration();
464+
}
465+
450466
double Transcoder::getMinTotalDuration() const
451467
{
452468
double minTotalDuration = std::numeric_limits<double>::max();
453469

454470
for( size_t i = 0; i < _streamTranscoders.size(); ++i )
455471
{
456-
minTotalDuration = std::min( _streamTranscoders.at( i )->getDuration(), minTotalDuration );
472+
minTotalDuration = std::min( getStreamDuration( i ), minTotalDuration );
457473
}
458474
return minTotalDuration;
459475
}
@@ -464,7 +480,7 @@ double Transcoder::getMaxTotalDuration() const
464480

465481
for( size_t i = 0; i < _streamTranscoders.size(); ++i )
466482
{
467-
maxTotalDuration = std::max( _streamTranscoders.at( i )->getDuration(), maxTotalDuration );
483+
maxTotalDuration = std::max( getStreamDuration( i ), maxTotalDuration );
468484
}
469485
return maxTotalDuration;
470486
}

src/AvTranscoder/transcoder/Transcoder.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ namespace avtranscoder
2727
* @brief: Enum to set a policy of how we manage the transcode in case of several streams.
2828
* eProcessMethodShortest: stop transcode at the end of the shortest stream.
2929
* eProcessMethodLongest: stop transcode at the end of the longest stream (default method).
30+
* eProcessMethodBasedOnStream: stop transcode at the end of an indicated stream (@see _indexBasedStream).
3031
* eProcessMethodInfinity: stop transcode by outside of avTranscoder.
3132
*/
3233
enum EProcessMethod
3334
{
3435
eProcessMethodShortest = 0,
3536
eProcessMethodLongest,
37+
eProcessMethodBasedOnStream,
3638
eProcessMethodInfinity,
3739
};
3840

@@ -116,8 +118,9 @@ class Transcoder
116118
/**
117119
* @brief Set the transcodage politic.
118120
* @note If you call it before adding the streams, the process will stop at the end of the shortest stream.
121+
* @param indexBasedStream: in case of process method eProcessMethodBasedOnStream, stop transcode at the end of the indicated stream.
119122
*/
120-
void setProcessMethod( const EProcessMethod eProcessMethod );
123+
void setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream = 0 );
121124

122125
/**
123126
* @brief Set verbose mode for the Transcoder and his streams.
@@ -139,9 +142,14 @@ class Transcoder
139142

140143
InputFile* addInputFile( const std::string& filename, const size_t streamIndex );
141144

145+
/**
146+
* @brief Get the duration of the stream.
147+
*/
148+
double getStreamDuration( size_t indexStream ) const;
149+
142150
/**
143151
* @brief Get the duration of the shortest stream.
144-
* @note if there is only generated streams, return limit of double.
152+
* @note if there is only generated streams, return limit of double.
145153
*/
146154
double getMinTotalDuration() const;
147155

@@ -168,6 +176,8 @@ class Transcoder
168176
size_t _finalisedStreams;
169177
EProcessMethod _eProcessMethod;
170178

179+
size_t _mainStreamIndex; ///< Index of stream used to stop the process of transcode in case of eProcessMethodBasedOnStream.
180+
171181
bool _verbose;
172182
};
173183

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy