Skip to content

Commit 0746921

Browse files
author
Clement Champetier
committed
Transcoder: added possibility to add several inputs without any profile
The profile is found from the inputs.
1 parent c18072c commit 0746921

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
55
#include <AvTranscoder/stat/VideoStat.hpp>
66

7+
#include <cassert>
78
#include <limits>
89
#include <algorithm>
910

@@ -74,12 +75,26 @@ void Transcoder::addStream(const InputStreamDesc& inputStreamDesc, const Profile
7475

7576
void Transcoder::addStream(const std::vector<InputStreamDesc>& inputStreamDescArray, const std::string& profileName, const float offset)
7677
{
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+
7889
addStream(inputStreamDescArray, encodingProfile, offset);
7990
}
8091

8192
void Transcoder::addStream(const std::vector<InputStreamDesc>& inputStreamDescArray, const ProfileLoader::Profile& profile, const float offset)
8293
{
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+
8398
addTranscodeStream(inputStreamDescArray, profile, offset);
8499
}
85100

@@ -287,7 +302,18 @@ InputFile* Transcoder::addInputFile(const std::string& filename, const int strea
287302
}
288303

289304
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);
291317
InputFile inputFile(inputStreamDesc._filename);
292318

293319
const StreamProperties* streamProperties = &inputFile.getProperties().getStreamPropertiesWithIndex(inputStreamDesc._streamIndex);
@@ -335,18 +361,22 @@ ProfileLoader::Profile Transcoder::getProfileFromInput(const InputStreamDesc& in
335361
std::stringstream ss;
336362
ss << audioProperties->getSampleRate();
337363
profile[constants::avProfileSampleRate] = ss.str();
338-
ss.str("");
364+
ss.str("");
339365
// 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)
346368
{
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+
}
349377
}
378+
ss << nbChannels;
379+
profile[constants::avProfileChannel] = ss.str();
350380
}
351381

352382
return profile;

src/AvTranscoder/transcoder/Transcoder.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class AvExport Transcoder
6868
//@{
6969
// @brief Add a new stream to the output file, created from the given input description to process.
7070
// @param inputStreamDescArray: the type of the described streams should be of the same type.
71-
void addStream(const std::vector<InputStreamDesc>& inputStreamDescArray, const std::string& profileName, float offset = 0);
71+
// @param profile: if empty, get the profile from the inputs.
72+
void addStream(const std::vector<InputStreamDesc>& inputStreamDescArray, const std::string& profileName = "", float offset = 0);
7273
void addStream(const std::vector<InputStreamDesc>& inputStreamDescArray, const ProfileLoader::Profile& profile, const float offset = 0);
7374
//@}
7475

@@ -145,9 +146,10 @@ class AvExport Transcoder
145146
InputFile* addInputFile(const std::string& filename, const int streamIndex, const float offset);
146147

147148
/**
148-
* @return The profile from the given input.
149+
* @return The profile from the given inputs.
149150
*/
150151
ProfileLoader::Profile getProfileFromInput(const InputStreamDesc& inputStreamDesc);
152+
ProfileLoader::Profile getProfileFromInputs(const std::vector<InputStreamDesc>& inputStreamDescArray);
151153

152154
/**
153155
* @brief Get the duration of the stream, in seconds

0 commit comments

Comments
 (0)