Skip to content

Commit 046f6db

Browse files
author
Clement Champetier
committed
Transcoder: removed check of progress duration as a stop condition
Use _mainStreamIndex attribute in all process methods to stop the process.
1 parent 66a7b43 commit 046f6db

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ bool Transcoder::processFrame()
243243
{
244244
LOG_WARN("Failed to process stream " << streamIndex)
245245
++nbStreamProcessStatusFailed;
246+
247+
// if this is the end of the main stream
248+
if(streamIndex == _mainStreamIndex) {
249+
LOG_INFO("End of process because the main stream at index " << _mainStreamIndex << " failed to process a new frame.")
250+
return false;
251+
}
246252
}
247253
}
248254

@@ -302,14 +308,6 @@ ProcessStat Transcoder::process(IProgress& progress)
302308
LOG_INFO("End of process because the job was canceled.")
303309
break;
304310
}
305-
306-
// check progressDuration
307-
if(progressDuration >= expectedOutputDuration)
308-
{
309-
LOG_INFO("End of process because the output program duration ("
310-
<< progressDuration << "s) is equal or upper than " << expectedOutputDuration << "s.")
311-
break;
312-
}
313311
}
314312

315313
_outputFile.endWrap();
@@ -498,32 +496,43 @@ ProfileLoader::Profile Transcoder::getProfileFromFile(InputFile& inputFile, cons
498496
return profile;
499497
}
500498

501-
float Transcoder::getStreamDuration(size_t indexStream) const
499+
float Transcoder::getStreamDuration(const size_t indexStream) const
502500
{
503501
return _streamTranscoders.at(indexStream)->getDuration();
504502
}
505503

506-
float Transcoder::getMinTotalDuration() const
504+
float Transcoder::getMinTotalDuration()
507505
{
508506
float minTotalDuration = std::numeric_limits<float>::max();
509-
for(size_t i = 0; i < _streamTranscoders.size(); ++i)
507+
for(size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex)
510508
{
511-
minTotalDuration = std::min(getStreamDuration(i), minTotalDuration);
509+
const float streamDuration = getStreamDuration(streamIndex);
510+
if(std::min(streamDuration, minTotalDuration) == streamDuration)
511+
{
512+
minTotalDuration = streamDuration;
513+
_mainStreamIndex = streamIndex;
514+
}
515+
512516
}
513517
return minTotalDuration;
514518
}
515519

516-
float Transcoder::getMaxTotalDuration() const
520+
float Transcoder::getMaxTotalDuration()
517521
{
518522
float maxTotalDuration = 0;
519-
for(size_t i = 0; i < _streamTranscoders.size(); ++i)
523+
for(size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex)
520524
{
521-
maxTotalDuration = std::max(getStreamDuration(i), maxTotalDuration);
525+
const float streamDuration = getStreamDuration(streamIndex);
526+
if(std::max(streamDuration, maxTotalDuration) == streamDuration)
527+
{
528+
maxTotalDuration = streamDuration;
529+
_mainStreamIndex = streamIndex;
530+
}
522531
}
523532
return maxTotalDuration;
524533
}
525534

526-
float Transcoder::getExpectedOutputDuration() const
535+
float Transcoder::getExpectedOutputDuration()
527536
{
528537
switch(_eProcessMethod)
529538
{

src/AvTranscoder/transcoder/Transcoder.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,22 @@ class AvExport Transcoder
197197
float getStreamDuration(size_t indexStream) const;
198198

199199
/**
200-
* @brief Get the duration of the shortest stream, in seconds
201-
*/
202-
float getMinTotalDuration() const;
200+
* @brief Get the duration of the shortest stream, in seconds
201+
* @note Set the index of the main stream to stop the process at the end of the shortest stream.
202+
*/
203+
float getMinTotalDuration();
203204

204205
/**
205206
* @brief Get the duration of the longest stream, in seconds
207+
* @note Set the index of the main stream to stop the process at the end of the longest stream.
206208
*/
207-
float getMaxTotalDuration() const;
209+
float getMaxTotalDuration();
208210

209211
/**
210212
* @brief Get the expected duration of the output program
211213
* @note Depends on the streams, the process method, and the main stream index.
212214
*/
213-
float getExpectedOutputDuration() const;
215+
float getExpectedOutputDuration();
214216

215217
/**
216218
* @brief Get the current duration of the output program
@@ -240,7 +242,7 @@ class AvExport Transcoder
240242

241243
EProcessMethod _eProcessMethod; ///< Processing policy
242244
size_t
243-
_mainStreamIndex; ///< Index of stream used to stop the process of transcode in case of eProcessMethodBasedOnStream.
245+
_mainStreamIndex; ///< Index of stream used to stop the process.
244246
float _outputDuration; ///< Duration of output media used to stop the process of transcode in case of
245247
/// eProcessMethodBasedOnDuration.
246248
};

0 commit comments

Comments
 (0)