Skip to content

Commit 4d83e9f

Browse files
Merge pull request #44 from cchampet/dev_Transcoder_duration
Transcoder: can process transcode with only dummy
2 parents 3e97128 + 7897e51 commit 4d83e9f

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/AvTranscoder/Transcoder/Transcoder.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Transcoder.hpp"
2+
#include <limits>
23

34
namespace avtranscoder
45
{
@@ -11,6 +12,7 @@ Transcoder::Transcoder( OutputFile& outputFile )
1112
, _dummyAudio()
1213
, _dummyVideo()
1314
, _profile( true )
15+
, _outputFps( 25 )
1416
, _finalisedStreams( 0 )
1517
, _eProcessMethod ( eProcessMethodLongest )
1618
, _verbose( false )
@@ -258,7 +260,9 @@ void Transcoder::process( ProgressListener& progress )
258260
dataStreams.push_back( dataStream );
259261
}
260262

261-
if( ! _inputStreams.size() )
263+
if( ! _inputStreams.size() &&
264+
! _dummyVideo.size() &&
265+
! _dummyAudio.size() )
262266
{
263267
throw std::runtime_error( "missing input streams in transcoder" );
264268
}
@@ -268,7 +272,27 @@ void Transcoder::process( ProgressListener& progress )
268272

269273
_outputFile.beginWrap();
270274

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+
}
272296

273297
if( _verbose )
274298
av_log_set_level( AV_LOG_DEBUG );
@@ -280,7 +304,7 @@ void Transcoder::process( ProgressListener& progress )
280304
if( ! processFrame() )
281305
break;
282306

283-
if( progress.progress( _inputStreams.at( 0 )->getPacketDuration() * ( frame ), totalDuration ) == eJobStatusCancel )
307+
if( progress.progress( 1 / _outputFps * ( frame ), totalDuration ) == eJobStatusCancel )
284308
{
285309
break;
286310
}

src/AvTranscoder/Transcoder/Transcoder.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class Transcoder
126126

127127
Profile _profile;
128128

129+
double _outputFps;
130+
129131
size_t _finalisedStreams;
130132
EProcessMethod _eProcessMethod;
131133

0 commit comments

Comments
 (0)