1
1
#include " Transcoder.hpp"
2
+ #include < limits>
2
3
3
4
namespace avtranscoder
4
5
{
@@ -11,6 +12,7 @@ Transcoder::Transcoder( OutputFile& outputFile )
11
12
, _dummyAudio()
12
13
, _dummyVideo()
13
14
, _profile( true )
15
+ , _outputFps( 25 )
14
16
, _finalisedStreams( 0 )
15
17
, _eProcessMethod ( eProcessMethodLongest )
16
18
, _verbose( false )
@@ -258,7 +260,9 @@ void Transcoder::process( ProgressListener& progress )
258
260
dataStreams.push_back ( dataStream );
259
261
}
260
262
261
- if ( ! _inputStreams.size () )
263
+ if ( ! _inputStreams.size () &&
264
+ ! _dummyVideo.size () &&
265
+ ! _dummyAudio.size () )
262
266
{
263
267
throw std::runtime_error ( " missing input streams in transcoder" );
264
268
}
@@ -268,7 +272,27 @@ void Transcoder::process( ProgressListener& progress )
268
272
269
273
_outputFile.beginWrap ();
270
274
271
- double totalDuration = _inputStreams.at ( 0 )->getDuration ();
275
+ double totalDuration = std::numeric_limits<double >::max ();
276
+ double minTotalDuration = std::numeric_limits<double >::max ();
277
+ double maxTotalDuration = 0 ;
278
+
279
+ for ( size_t i = 0 ; i < _inputStreams.size (); ++i )
280
+ {
281
+ minTotalDuration = std::min ( _inputStreams.at ( i )->getDuration (), minTotalDuration );
282
+ maxTotalDuration = std::max ( _inputStreams.at ( i )->getDuration (), maxTotalDuration );
283
+ }
284
+ switch ( _eProcessMethod )
285
+ {
286
+ case eProcessMethodShortest :
287
+ totalDuration = minTotalDuration;
288
+ break ;
289
+ case eProcessMethodLongest :
290
+ totalDuration = maxTotalDuration;
291
+ break ;
292
+ case eProcessMethodInfinity :
293
+ totalDuration = std::numeric_limits<double >::max ();
294
+ break ;
295
+ }
272
296
273
297
if ( _verbose )
274
298
av_log_set_level ( AV_LOG_DEBUG );
@@ -280,7 +304,7 @@ void Transcoder::process( ProgressListener& progress )
280
304
if ( ! processFrame () )
281
305
break ;
282
306
283
- if ( progress.progress ( _inputStreams. at ( 0 )-> getPacketDuration () * ( frame ), totalDuration ) == eJobStatusCancel )
307
+ if ( progress.progress ( 1 / _outputFps * ( frame ), totalDuration ) == eJobStatusCancel )
284
308
{
285
309
break ;
286
310
}
0 commit comments