Skip to content

Commit 7756c2c

Browse files
author
Clement Champetier
committed
Merge branch 'develop' into dev_transcoderRewrapToMultiChannels
Conflicts: src/AvTranscoder/transcoder/StreamTranscoder.cpp
2 parents 9868167 + 7e1bf7d commit 7756c2c

File tree

10 files changed

+64
-58
lines changed

10 files changed

+64
-58
lines changed

src/AvTranscoder/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define AVTRANSCODER_VERSION_MAJOR 0
55
#define AVTRANSCODER_VERSION_MINOR 9
6-
#define AVTRANSCODER_VERSION_MICRO 6
6+
#define AVTRANSCODER_VERSION_MICRO 7
77

88
#include <AvTranscoder/system.hpp>
99

src/AvTranscoder/decoder/AudioDecoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool AudioDecoder::decodeNextFrame(Frame& frameBuffer)
9797
&got_frame, &data.getAVPacket());
9898
if(ret < 0)
9999
{
100-
throw std::runtime_error("an error occured during audio decoding" + getDescriptionFromErrorCode(ret));
100+
throw std::runtime_error("An error occurred during audio decoding: " + getDescriptionFromErrorCode(ret));
101101
}
102102

103103
// if no frame could be decompressed

src/AvTranscoder/decoder/VideoDecoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ bool VideoDecoder::decodeNextFrame(Frame& frameBuffer)
9595
&got_frame, &data.getAVPacket());
9696
if(ret < 0)
9797
{
98-
throw std::runtime_error("an error occured during video decoding - " + getDescriptionFromErrorCode(ret));
98+
throw std::runtime_error("An error occurred during video decoding: " + getDescriptionFromErrorCode(ret));
9999
}
100100

101101
// if no frame could be decompressed

src/AvTranscoder/properties/StreamProperties.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ StreamProperties::StreamProperties(const FileProperties& fileProperties, const s
3838
if(_codec)
3939
{
4040
// load specific options of the codec
41-
if(avcodec_open2(_codecContext, _codec, NULL) == 0)
42-
{
43-
loadOptions(_options, _codecContext);
44-
avcodec_close(_codecContext);
45-
}
41+
loadOptions(_options, _codecContext);
4642
}
4743
}
4844
}

src/AvTranscoder/properties/VideoProperties.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ class AvExport VideoProperties : public StreamProperties
4040
Rational getSar() const; // sample/pixel aspect ratio
4141
Rational getDar() const; // display aspect ratio
4242

43-
size_t getBitRate() const; ///< in bits/s, 0 if unknown
43+
/**
44+
* @return The video bitrate in bits/s.
45+
* @warning If there is no such info available in the container, this data is estimated by decoding the first GOP.
46+
*/
47+
size_t getBitRate() const;
4448
size_t getMaxBitRate() const;
4549
size_t getMinBitRate() const;
46-
size_t getNbFrames() const; ///< 0 if unknown
50+
/**
51+
* @note 0 if unknown.
52+
* @warning In case of a raw format, this data is estimated from the fps and the duration.
53+
*/
54+
size_t getNbFrames() const;
4755
size_t getTicksPerFrame() const;
4856
size_t getWidth() const;
4957
size_t getHeight() const;
@@ -63,7 +71,8 @@ class AvExport VideoProperties : public StreamProperties
6371

6472
/**
6573
* @brief Override method.
66-
* @return the stream duration in seconds, 0 if not available
74+
* @return The stream duration in seconds, 0 if not available.
75+
* @warning In case of a raw format, this data is estimated from the file size.
6776
*/
6877
float getDuration() const;
6978

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,8 @@ void StreamTranscoder::preProcessCodecLatency()
358358

359359
bool StreamTranscoder::processFrame()
360360
{
361-
const EProcessCase processCase = getProcessCase();
362361
std::string msg = "Current process case of the stream is a ";
363-
switch(processCase)
362+
switch(getProcessCase())
364363
{
365364
case eProcessCaseTranscode:
366365
msg += "transcode.";
@@ -374,9 +373,6 @@ bool StreamTranscoder::processFrame()
374373
}
375374
LOG_DEBUG(msg)
376375

377-
if(processCase == eProcessCaseGenerator)
378-
return processTranscode();
379-
380376
// Manage offset
381377
if(_offset > 0)
382378
{
@@ -385,7 +381,7 @@ bool StreamTranscoder::processFrame()
385381
{
386382
LOG_INFO("End of positive offset")
387383

388-
if(getProcessCase() == eProcessCaseTranscode)
384+
if(_inputDecoder)
389385
switchToInputDecoder();
390386
else
391387
_currentDecoder = NULL;
@@ -395,9 +391,7 @@ bool StreamTranscoder::processFrame()
395391
{
396392
// process generator
397393
if(_currentDecoder != _generator)
398-
{
399394
switchToGeneratorDecoder();
400-
}
401395
}
402396
}
403397
else if(_offset < 0)
@@ -408,14 +402,14 @@ bool StreamTranscoder::processFrame()
408402
{
409403
LOG_INFO("End of negative offset")
410404

411-
switchToGeneratorDecoder();
405+
if(_needToSwitchToGenerator)
406+
switchToGeneratorDecoder();
412407
_offset = 0;
413408
}
414409
}
415410

416-
if(processCase == eProcessCaseRewrap)
411+
if(getProcessCase() == eProcessCaseRewrap)
417412
return processRewrap();
418-
419413
return processTranscode();
420414
}
421415

src/AvTranscoder/transcoder/StreamTranscoder.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ class AvExport StreamTranscoder
106106
void setOffset(const float offset);
107107

108108
//@{
109-
// Get the current process case.
109+
// @brief Get the current process case.
110+
// @warning Could vary during the process.
110111
enum EProcessCase
111112
{
112113
eProcessCaseTranscode,

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,21 @@ bool Transcoder::processFrame()
105105
return false;
106106

107107
// For each stream, process a frame
108-
size_t nbStreamProcessStatusFailed = 0;
109108
for(size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex)
110109
{
111-
LOG_DEBUG("Process stream " << streamIndex << "/" << (_streamTranscoders.size() - 1))
110+
LOG_DEBUG("Process stream " << streamIndex + 1 << "/" << _streamTranscoders.size())
111+
112+
// if a stream failed to process
112113
if(!_streamTranscoders.at(streamIndex)->processFrame())
113114
{
114-
LOG_WARN("Failed to process stream " << streamIndex)
115-
++nbStreamProcessStatusFailed;
116-
}
117-
}
118-
119-
// Get the number of streams without the generators (they always succeed)
120-
size_t nbStreamsWithoutGenerator = _streamTranscoders.size();
121-
for(size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex)
122-
{
123-
if(_streamTranscoders.at(streamIndex)->getProcessCase() == StreamTranscoder::eProcessCaseGenerator)
124-
--nbStreamsWithoutGenerator;
125-
}
115+
LOG_WARN("Failed to process stream at index " << streamIndex)
126116

127-
// If all streams failed to process a new frame
128-
if(nbStreamsWithoutGenerator != 0 && nbStreamsWithoutGenerator == nbStreamProcessStatusFailed)
129-
{
130-
LOG_INFO("End of process because all streams (except generators) failed to process a new frame.")
131-
return false;
117+
// if this is the end of the main stream
118+
if(streamIndex == _mainStreamIndex) {
119+
LOG_INFO("End of process because the main stream at index " << _mainStreamIndex << " failed to process a new frame.")
120+
return false;
121+
}
122+
}
132123
}
133124
return true;
134125
}
@@ -174,7 +165,7 @@ ProcessStat Transcoder::process(IProgress& progress)
174165
}
175166

176167
// check progressDuration
177-
if(progressDuration >= expectedOutputDuration)
168+
if(_eProcessMethod == eProcessMethodBasedOnDuration && progressDuration >= expectedOutputDuration)
178169
{
179170
LOG_INFO("End of process because the output program duration ("
180171
<< progressDuration << "s) is equal or upper than " << expectedOutputDuration << "s.")
@@ -184,7 +175,7 @@ ProcessStat Transcoder::process(IProgress& progress)
184175

185176
_outputFile.endWrap();
186177

187-
LOG_INFO("End of process: " << frame << " frames processed")
178+
LOG_INFO("End of process: " << ++frame << " frames processed")
188179

189180
LOG_INFO("Get process statistics")
190181
ProcessStat processStat;
@@ -360,32 +351,43 @@ ProfileLoader::Profile Transcoder::getProfileFromFile(InputFile& inputFile, cons
360351
return profile;
361352
}
362353

363-
float Transcoder::getStreamDuration(size_t indexStream) const
354+
float Transcoder::getStreamDuration(const size_t indexStream) const
364355
{
365356
return _streamTranscoders.at(indexStream)->getDuration();
366357
}
367358

368-
float Transcoder::getMinTotalDuration() const
359+
float Transcoder::getMinTotalDuration()
369360
{
370361
float minTotalDuration = std::numeric_limits<float>::max();
371-
for(size_t i = 0; i < _streamTranscoders.size(); ++i)
362+
for(size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex)
372363
{
373-
minTotalDuration = std::min(getStreamDuration(i), minTotalDuration);
364+
const float streamDuration = getStreamDuration(streamIndex);
365+
if(std::min(streamDuration, minTotalDuration) == streamDuration)
366+
{
367+
minTotalDuration = streamDuration;
368+
_mainStreamIndex = streamIndex;
369+
}
370+
374371
}
375372
return minTotalDuration;
376373
}
377374

378-
float Transcoder::getMaxTotalDuration() const
375+
float Transcoder::getMaxTotalDuration()
379376
{
380377
float maxTotalDuration = 0;
381-
for(size_t i = 0; i < _streamTranscoders.size(); ++i)
378+
for(size_t streamIndex = 0; streamIndex < _streamTranscoders.size(); ++streamIndex)
382379
{
383-
maxTotalDuration = std::max(getStreamDuration(i), maxTotalDuration);
380+
const float streamDuration = getStreamDuration(streamIndex);
381+
if(std::max(streamDuration, maxTotalDuration) == streamDuration)
382+
{
383+
maxTotalDuration = streamDuration;
384+
_mainStreamIndex = streamIndex;
385+
}
384386
}
385387
return maxTotalDuration;
386388
}
387389

388-
float Transcoder::getExpectedOutputDuration() const
390+
float Transcoder::getExpectedOutputDuration()
389391
{
390392
switch(_eProcessMethod)
391393
{

src/AvTranscoder/transcoder/Transcoder.hpp

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

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

203204
/**
204205
* @brief Get the duration of the longest stream, in seconds
206+
* @note Set the index of the main stream to stop the process at the end of the longest stream.
205207
*/
206-
float getMaxTotalDuration() const;
208+
float getMaxTotalDuration();
207209

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

214216
/**
215217
* @brief Get the current duration of the output program
@@ -239,7 +241,7 @@ class AvExport Transcoder
239241

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

test/pyTest/testOffset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def testRewrapAudioNegativeOffset():
137137
assert_equals( src_audioStream.getNbSamples() + ( offset * dst_audioStream.getSampleRate() * dst_audioStream.getNbChannels() ), dst_audioStream.getNbSamples() )
138138

139139

140+
# The output video stream has not the correct duration.
141+
@nottest
140142
def testTranscodeVideoPositiveOffset():
141143
"""
142144
Transcode one video stream (profile mpeg2) with offset at the beginning of the process.

0 commit comments

Comments
 (0)