Skip to content

Commit b9b4853

Browse files
committed
Merge pull request #77 from cchampet/dev_addMethodBasedOnDuration
Add transcoding policy eProcessMethodBasedOnDuration
2 parents aaa66ef + 4ad4052 commit b9b4853

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Transcoder::Transcoder( IOutputFile& outputFile )
1919
, _profileLoader( true )
2020
, _eProcessMethod ( eProcessMethodBasedOnStream )
2121
, _mainStreamIndex( 0 )
22+
, _outputDuration( 0 )
2223
, _verbose( false )
2324
{
2425
// Initialize the OutputFile
@@ -268,7 +269,7 @@ void Transcoder::process( IProgress& progress )
268269
if( _streamTranscoders.size() == 0 )
269270
throw std::runtime_error( "missing input streams in transcoder" );
270271

271-
manageInfinityStreamFromProcessMethod();
272+
manageSwitchToGenerator();
272273

273274
if( _verbose )
274275
std::cout << "begin transcoding" << std::endl;
@@ -277,7 +278,7 @@ void Transcoder::process( IProgress& progress )
277278

278279
preProcessCodecLatency();
279280

280-
double totalDuration = getOutputDuration();
281+
double outputDuration = getOutputDuration();
281282

282283
size_t frame = 0;
283284
bool frameProcessed = true;
@@ -289,7 +290,13 @@ void Transcoder::process( IProgress& progress )
289290
frameProcessed = processFrame();
290291

291292
double progressDuration = _outputFile.getStream( 0 ).getStreamDuration();
292-
if( progress.progress( ( progressDuration > totalDuration )? totalDuration : progressDuration, totalDuration ) == eJobStatusCancel )
293+
294+
// check progressDuration
295+
if( progressDuration > outputDuration )
296+
break;
297+
298+
// check if JobStatusCancel
299+
if( progress.progress( ( progressDuration > outputDuration ) ? outputDuration : progressDuration, outputDuration ) == eJobStatusCancel )
293300
break;
294301

295302
++frame;
@@ -301,10 +308,11 @@ void Transcoder::process( IProgress& progress )
301308
_outputFile.endWrap();
302309
}
303310

304-
void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream )
311+
void Transcoder::setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream, const double outputDuration )
305312
{
306313
_eProcessMethod = eProcessMethod;
307314
_mainStreamIndex = indexBasedStream;
315+
_outputDuration = outputDuration;
308316
}
309317

310318
void Transcoder::setVerbose( bool verbose )
@@ -487,14 +495,16 @@ double Transcoder::getOutputDuration() const
487495
return getMaxTotalDuration();
488496
case eProcessMethodBasedOnStream :
489497
return getStreamDuration( _mainStreamIndex );
498+
case eProcessMethodBasedOnDuration :
499+
return _outputDuration;
490500
case eProcessMethodInfinity :
491501
return std::numeric_limits<double>::max();
492502
default:
493503
return getMaxTotalDuration();
494504
}
495505
}
496506

497-
void Transcoder::manageInfinityStreamFromProcessMethod()
507+
void Transcoder::manageSwitchToGenerator()
498508
{
499509
for( size_t i = 0; i < _streamTranscoders.size(); ++i )
500510
{
@@ -518,6 +528,12 @@ void Transcoder::manageInfinityStreamFromProcessMethod()
518528
else
519529
_streamTranscoders.at( i )->canSwitchToGenerator( false );
520530
break;
531+
case eProcessMethodBasedOnDuration :
532+
if( _streamTranscoders.at( i )->getDuration() > _outputDuration )
533+
_streamTranscoders.at( i )->canSwitchToGenerator( false );
534+
else
535+
_streamTranscoders.at( i )->canSwitchToGenerator( true );
536+
break;
521537
case eProcessMethodInfinity :
522538
_streamTranscoders.at( i )->canSwitchToGenerator( true );
523539
break;

src/AvTranscoder/transcoder/Transcoder.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ namespace avtranscoder
2020
* eProcessMethodShortest: stop transcode at the end of the shortest stream.
2121
* eProcessMethodLongest: stop transcode at the end of the longest stream.
2222
* eProcessMethodBasedOnStream: stop transcode at the end of an indicated stream (@see _indexBasedStream attribute of Transcoder).
23+
* eProcessMethodBasedOnDuration: stop transcode at the end of an indicated duration, in seconds (@see _outputDuration attribute of Transcoder).
2324
* eProcessMethodInfinity: stop transcode by outside of avTranscoder (streaming mode)
2425
*/
2526
enum EProcessMethod
2627
{
2728
eProcessMethodShortest = 0,
2829
eProcessMethodLongest,
2930
eProcessMethodBasedOnStream,
31+
eProcessMethodBasedOnDuration,
3032
eProcessMethodInfinity,
3133
};
3234

@@ -125,8 +127,9 @@ class AvExport Transcoder
125127
* @brief Set the transcoding policy.
126128
* @note By default eProcessMethodBasedOnStream at index 0.
127129
* @param indexBasedStream: in case of process method eProcessMethodBasedOnStream, stop transcode at the end of the indicated stream.
130+
* @param outputDuration: in case of process method eProcessMethodBasedOnDuration, stop transcode at the end of the indicated duration.
128131
*/
129-
void setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream = 0 );
132+
void setProcessMethod( const EProcessMethod eProcessMethod, const size_t indexBasedStream = 0, const double outputDuration = 0 );
130133

131134
/**
132135
* @brief Set verbose mode for the Transcoder, its streams, and its output file.
@@ -168,9 +171,9 @@ class AvExport Transcoder
168171
double getOutputDuration() const;
169172

170173
/**
171-
* @brief Set for each StreamTranscoder if it is an infinity stream (switch to generator at the end of the stream).
174+
* @brief Set for each StreamTranscoder if it can switch to generator at the end.
172175
*/
173-
void manageInfinityStreamFromProcessMethod();
176+
void manageSwitchToGenerator();
174177

175178
private:
176179
IOutputFile& _outputFile; ///< The output media file after process (has link)
@@ -183,6 +186,7 @@ class AvExport Transcoder
183186

184187
EProcessMethod _eProcessMethod; ///< Transcoding policy
185188
size_t _mainStreamIndex; ///< Index of stream used to stop the process of transcode in case of eProcessMethodBasedOnStream.
189+
double _outputDuration; ///< Duration of output media used to stop the process of transcode in case of eProcessMethodBasedOnDuration.
186190

187191
bool _verbose;
188192
};

0 commit comments

Comments
 (0)