@@ -19,6 +19,7 @@ Transcoder::Transcoder( IOutputFile& outputFile )
19
19
, _profileLoader( true )
20
20
, _eProcessMethod ( eProcessMethodBasedOnStream )
21
21
, _mainStreamIndex( 0 )
22
+ , _outputDuration( 0 )
22
23
, _verbose( false )
23
24
{
24
25
// Initialize the OutputFile
@@ -268,7 +269,7 @@ void Transcoder::process( IProgress& progress )
268
269
if ( _streamTranscoders.size () == 0 )
269
270
throw std::runtime_error ( " missing input streams in transcoder" );
270
271
271
- manageInfinityStreamFromProcessMethod ();
272
+ manageSwitchToGenerator ();
272
273
273
274
if ( _verbose )
274
275
std::cout << " begin transcoding" << std::endl;
@@ -277,7 +278,7 @@ void Transcoder::process( IProgress& progress )
277
278
278
279
preProcessCodecLatency ();
279
280
280
- double totalDuration = getOutputDuration ();
281
+ double outputDuration = getOutputDuration ();
281
282
282
283
size_t frame = 0 ;
283
284
bool frameProcessed = true ;
@@ -289,7 +290,13 @@ void Transcoder::process( IProgress& progress )
289
290
frameProcessed = processFrame ();
290
291
291
292
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 )
293
300
break ;
294
301
295
302
++frame;
@@ -301,10 +308,11 @@ void Transcoder::process( IProgress& progress )
301
308
_outputFile.endWrap ();
302
309
}
303
310
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 )
305
312
{
306
313
_eProcessMethod = eProcessMethod;
307
314
_mainStreamIndex = indexBasedStream;
315
+ _outputDuration = outputDuration;
308
316
}
309
317
310
318
void Transcoder::setVerbose ( bool verbose )
@@ -487,14 +495,16 @@ double Transcoder::getOutputDuration() const
487
495
return getMaxTotalDuration ();
488
496
case eProcessMethodBasedOnStream :
489
497
return getStreamDuration ( _mainStreamIndex );
498
+ case eProcessMethodBasedOnDuration :
499
+ return _outputDuration;
490
500
case eProcessMethodInfinity :
491
501
return std::numeric_limits<double >::max ();
492
502
default :
493
503
return getMaxTotalDuration ();
494
504
}
495
505
}
496
506
497
- void Transcoder::manageInfinityStreamFromProcessMethod ()
507
+ void Transcoder::manageSwitchToGenerator ()
498
508
{
499
509
for ( size_t i = 0 ; i < _streamTranscoders.size (); ++i )
500
510
{
@@ -518,6 +528,12 @@ void Transcoder::manageInfinityStreamFromProcessMethod()
518
528
else
519
529
_streamTranscoders.at ( i )->canSwitchToGenerator ( false );
520
530
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 ;
521
537
case eProcessMethodInfinity :
522
538
_streamTranscoders.at ( i )->canSwitchToGenerator ( true );
523
539
break ;
0 commit comments