|
4 | 4 | #include <AvTranscoder/progress/NoDisplayProgress.hpp>
|
5 | 5 | #include <AvTranscoder/stat/VideoStat.hpp>
|
6 | 6 |
|
| 7 | +#include <cassert> |
7 | 8 | #include <limits>
|
8 | 9 | #include <algorithm>
|
9 | 10 |
|
@@ -74,12 +75,26 @@ void Transcoder::addStream(const InputStreamDesc& inputStreamDesc, const Profile
|
74 | 75 |
|
75 | 76 | void Transcoder::addStream(const std::vector<InputStreamDesc>& inputStreamDescArray, const std::string& profileName, const float offset)
|
76 | 77 | {
|
77 |
| - const ProfileLoader::Profile& encodingProfile = _profileLoader.getProfile(profileName); |
| 78 | + // Check number of inputs |
| 79 | + if(inputStreamDescArray.empty()) |
| 80 | + throw std::runtime_error("Need a description of at least one input stream to start the process."); |
| 81 | + |
| 82 | + // Get encoding profile |
| 83 | + ProfileLoader::Profile encodingProfile; |
| 84 | + if(profileName.empty()) |
| 85 | + encodingProfile = getProfileFromInputs(inputStreamDescArray); |
| 86 | + else |
| 87 | + encodingProfile = _profileLoader.getProfile(profileName); |
| 88 | + |
78 | 89 | addStream(inputStreamDescArray, encodingProfile, offset);
|
79 | 90 | }
|
80 | 91 |
|
81 | 92 | void Transcoder::addStream(const std::vector<InputStreamDesc>& inputStreamDescArray, const ProfileLoader::Profile& profile, const float offset)
|
82 | 93 | {
|
| 94 | + // Check number of inputs |
| 95 | + if(inputStreamDescArray.empty()) |
| 96 | + throw std::runtime_error("Need a description of at least one input stream to start the process."); |
| 97 | + |
83 | 98 | addTranscodeStream(inputStreamDescArray, profile, offset);
|
84 | 99 | }
|
85 | 100 |
|
@@ -287,7 +302,18 @@ InputFile* Transcoder::addInputFile(const std::string& filename, const int strea
|
287 | 302 | }
|
288 | 303 |
|
289 | 304 | ProfileLoader::Profile Transcoder::getProfileFromInput(const InputStreamDesc& inputStreamDesc)
|
290 |
| -{ |
| 305 | +{ |
| 306 | + std::vector<InputStreamDesc> inputStreamDescArray; |
| 307 | + inputStreamDescArray.push_back(inputStreamDesc); |
| 308 | + return getProfileFromInputs(inputStreamDescArray); |
| 309 | +} |
| 310 | + |
| 311 | +ProfileLoader::Profile Transcoder::getProfileFromInputs(const std::vector<InputStreamDesc>& inputStreamDescArray) |
| 312 | +{ |
| 313 | + assert(inputStreamDescArray.size() >= 1); |
| 314 | + |
| 315 | + // Get properties from the first input |
| 316 | + const InputStreamDesc& inputStreamDesc = inputStreamDescArray.at(0); |
291 | 317 | InputFile inputFile(inputStreamDesc._filename);
|
292 | 318 |
|
293 | 319 | const StreamProperties* streamProperties = &inputFile.getProperties().getStreamPropertiesWithIndex(inputStreamDesc._streamIndex);
|
@@ -335,18 +361,22 @@ ProfileLoader::Profile Transcoder::getProfileFromInput(const InputStreamDesc& in
|
335 | 361 | std::stringstream ss;
|
336 | 362 | ss << audioProperties->getSampleRate();
|
337 | 363 | profile[constants::avProfileSampleRate] = ss.str();
|
338 |
| - ss.str(""); |
| 364 | + ss.str(""); |
339 | 365 | // override number of channels parameters to manage demultiplexing
|
340 |
| - if(inputStreamDesc.demultiplexing()) |
341 |
| - { |
342 |
| - ss << inputStreamDesc._channelIndexArray.size(); |
343 |
| - profile[constants::avProfileChannel] = ss.str(); |
344 |
| - } |
345 |
| - else |
| 366 | + size_t nbChannels = 0; |
| 367 | + for(std::vector<InputStreamDesc>::const_iterator it = inputStreamDescArray.begin(); it != inputStreamDescArray.end(); ++it) |
346 | 368 | {
|
347 |
| - ss << audioProperties->getNbChannels(); |
348 |
| - profile[constants::avProfileChannel] = ss.str(); |
| 369 | + if(inputStreamDesc.demultiplexing()) |
| 370 | + nbChannels += it->_channelIndexArray.size(); |
| 371 | + else |
| 372 | + { |
| 373 | + InputFile inputFile(it->_filename); |
| 374 | + const AudioProperties& audioStream = dynamic_cast<const AudioProperties&>(inputFile.getProperties().getStreamPropertiesWithIndex(inputStreamDesc._streamIndex)); |
| 375 | + nbChannels += audioStream.getNbChannels(); |
| 376 | + } |
349 | 377 | }
|
| 378 | + ss << nbChannels; |
| 379 | + profile[constants::avProfileChannel] = ss.str(); |
350 | 380 | }
|
351 | 381 |
|
352 | 382 | return profile;
|
|
0 commit comments