Skip to content

Commit f05574b

Browse files
author
Clement Champetier
committed
Transcoder: added a check of the stream type when adding a list of inputs
Added a python test to check this behavior.
1 parent 21b89b2 commit f05574b

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,21 @@ void Transcoder::addTranscodeStream(const std::vector<InputStreamDesc>& inputStr
255255
<< "with encodingProfile=" << profile.at(constants::avProfileIdentificatorHuman) << std::endl
256256
<< "and offset=" << offset << "s")
257257

258-
// Add input file
258+
// Create all streams from the given inputs
259259
std::vector<IInputStream*> inputStreams;
260+
AVMediaType commonStreamType = AVMEDIA_TYPE_UNKNOWN;
260261
for(std::vector<InputStreamDesc>::const_iterator it = inputStreamDescArray.begin(); it != inputStreamDescArray.end(); ++it)
261262
{
262263
InputFile* referenceFile = addInputFile(it->_filename, it->_streamIndex, offset);
263264
inputStreams.push_back(&referenceFile->getStream(it->_streamIndex));
265+
266+
// Check stream type
267+
const AVMediaType currentStreamType = referenceFile->getProperties().getStreamPropertiesWithIndex(it->_streamIndex).getStreamType();
268+
if(commonStreamType == AVMEDIA_TYPE_UNKNOWN)
269+
commonStreamType = currentStreamType;
270+
else if(currentStreamType != commonStreamType)
271+
throw std::runtime_error("All the given inputs should be of the same type (video, audio...).");
272+
264273
}
265274

266275
_streamTranscodersAllocated.push_back(
@@ -380,8 +389,10 @@ ProfileLoader::Profile Transcoder::getProfileFromInputs(const std::vector<InputS
380389
else
381390
{
382391
InputFile inputFile(it->_filename);
383-
const AudioProperties& audioStream = dynamic_cast<const AudioProperties&>(inputFile.getProperties().getStreamPropertiesWithIndex(inputStreamDesc._streamIndex));
384-
nbChannels += audioStream.getNbChannels();
392+
const StreamProperties& currentStream = inputFile.getProperties().getStreamPropertiesWithIndex(inputStreamDesc._streamIndex);
393+
if(currentStream.getStreamType() != AVMEDIA_TYPE_AUDIO)
394+
throw std::runtime_error("All the given inputs should be audio streams.");
395+
nbChannels += dynamic_cast<const AudioProperties&>(currentStream).getNbChannels();
385396
}
386397
}
387398
ss << nbChannels;

test/pyTest/testTranscoderAdd.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ def testEmptyListOfInputs():
6969
transcoder.addStream(inputs)
7070

7171

72+
@raises(RuntimeError)
73+
def testAllSeveralInputsWithDifferentType():
74+
"""
75+
Add one video and one audio to create one output stream.
76+
"""
77+
# inputs
78+
inputs = av.InputStreamDescVector()
79+
inputs.append(av.InputStreamDesc(os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE'], 0))
80+
inputs.append(av.InputStreamDesc(os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE'], 0))
81+
82+
# output
83+
outputFileName = "testAllSeveralInputsWithDifferentType.mov"
84+
ouputFile = av.OutputFile(outputFileName)
85+
86+
transcoder = av.Transcoder(ouputFile)
87+
transcoder.addStream(inputs)
88+
89+
7290
def testAddSeveralInputsToCreateOneOutput():
7391
"""
7492
Add several audio inputs and create one output stream.

0 commit comments

Comments
 (0)