Skip to content

Commit 932707b

Browse files
author
Clement Champetier
committed
Transcoder: refactore case when getting profile from input file
1 parent d7c7cad commit 932707b

File tree

2 files changed

+48
-42
lines changed

2 files changed

+48
-42
lines changed

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -138,27 +138,7 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
138138
{
139139
if( _verbose )
140140
std::cout << "Add transcoded stream (because of demultiplexing)" << std::endl;
141-
// Create profile as input configuration
142-
InputFile inputFile( filename );
143-
NoDisplayProgress progress;
144-
inputFile.analyse( progress, InputFile::eAnalyseLevelFast );
145-
AudioProperties audioProperties = inputFile.getProperties().audioStreams.at( streamIndex ); // Warning: only manage audio case
146-
147-
ProfileLoader::Profile profile;
148-
profile[ constants::avProfileIdentificator ] = "presetRewrap";
149-
profile[ constants::avProfileIdentificatorHuman ] = "Preset rewrap";
150-
profile[ constants::avProfileType ] = avtranscoder::constants::avProfileTypeAudio;
151-
profile[ constants::avProfileCodec ] = audioProperties.codecName;
152-
profile[ constants::avProfileSampleFormat ] = audioProperties.sampleFormat;
153-
std::stringstream ss;
154-
ss << audioProperties.sampleRate;
155-
profile[ constants::avProfileSampleRate ] = ss.str();
156-
profile[ constants::avProfileChannel ] = "1";
157-
158-
// Add profile
159-
_profileLoader.update( profile );
160-
161-
add( filename, streamIndex, subStreamIndex, profile, offset );
141+
addTranscodeStream( filename, streamIndex, subStreamIndex, offset );
162142
}
163143
}
164144
// Transcode
@@ -194,27 +174,7 @@ void Transcoder::add( const std::string& filename, const size_t streamIndex, con
194174
{
195175
if( _verbose )
196176
std::cout << "Add transcoded stream (because of demultiplexing)" << std::endl;
197-
// Create profile as input configuration
198-
InputFile inputFile( filename );
199-
NoDisplayProgress progress;
200-
inputFile.analyse( progress, InputFile::eAnalyseLevelFast );
201-
AudioProperties audioProperties = inputFile.getProperties().audioStreams.at( streamIndex ); // Warning: only manage audio case
202-
203-
ProfileLoader::Profile profile;
204-
profile[ constants::avProfileIdentificator ] = "presetRewrap";
205-
profile[ constants::avProfileIdentificatorHuman ] = "Preset rewrap";
206-
profile[ constants::avProfileType ] = avtranscoder::constants::avProfileTypeAudio;
207-
profile[ constants::avProfileCodec ] = audioProperties.codecName;
208-
profile[ constants::avProfileSampleFormat ] = audioProperties.sampleFormat;
209-
std::stringstream ss;
210-
ss << audioProperties.sampleRate;
211-
profile[ constants::avProfileSampleRate ] = ss.str();
212-
profile[ constants::avProfileChannel ] = "1";
213-
214-
// Add profile
215-
_profileLoader.update( profile );
216-
217-
add( filename, streamIndex, subStreamIndex, profile, offset );
177+
addTranscodeStream( filename, streamIndex, subStreamIndex, offset );
218178
}
219179
}
220180
// Transcode
@@ -417,6 +377,47 @@ void Transcoder::addRewrapStream( const std::string& filename, const size_t stre
417377
_streamTranscoders.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile ) );
418378
}
419379

380+
void Transcoder::addTranscodeStream( const std::string& filename, const size_t streamIndex, const size_t subStreamIndex, const size_t offset )
381+
{
382+
InputFile* referenceFile = addInputFile( filename, streamIndex );
383+
384+
// Create profile as input configuration
385+
NoDisplayProgress progress;
386+
referenceFile->analyse( progress, InputFile::eAnalyseLevelFast );
387+
AudioProperties audioProperties = referenceFile->getProperties().audioStreams.at( streamIndex );
388+
389+
ProfileLoader::Profile profile;
390+
profile[ constants::avProfileIdentificator ] = "presetRewrap";
391+
profile[ constants::avProfileIdentificatorHuman ] = "Preset rewrap";
392+
profile[ constants::avProfileType ] = avtranscoder::constants::avProfileTypeAudio;
393+
profile[ constants::avProfileCodec ] = audioProperties.codecName;
394+
profile[ constants::avProfileSampleFormat ] = audioProperties.sampleFormat;
395+
std::stringstream ss;
396+
ss << audioProperties.sampleRate;
397+
profile[ constants::avProfileSampleRate ] = ss.str();
398+
profile[ constants::avProfileChannel ] = "1";
399+
400+
// Add profile
401+
_profileLoader.update( profile );
402+
403+
switch( referenceFile->getStreamType( streamIndex ) )
404+
{
405+
case AVMEDIA_TYPE_VIDEO:
406+
case AVMEDIA_TYPE_AUDIO:
407+
{
408+
_streamTranscoders.push_back( new StreamTranscoder( referenceFile->getStream( streamIndex ), _outputFile, profile, subStreamIndex , offset ) );
409+
break;
410+
}
411+
case AVMEDIA_TYPE_DATA:
412+
case AVMEDIA_TYPE_SUBTITLE:
413+
case AVMEDIA_TYPE_ATTACHMENT:
414+
default:
415+
{
416+
throw std::runtime_error( "unsupported media type in transcode setup" );
417+
}
418+
}
419+
}
420+
420421
void Transcoder::addTranscodeStream( const std::string& filename, const size_t streamIndex, ProfileLoader::Profile& profile, const size_t offset )
421422
{
422423
InputFile* referenceFile = addInputFile( filename, streamIndex );

src/AvTranscoder/transcoder/Transcoder.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ class AvExport Transcoder
141141

142142
void addRewrapStream( const std::string& filename, const size_t streamIndex );
143143

144+
/**
145+
* @note Get profile from input
146+
*/
147+
void addTranscodeStream( const std::string& filename, const size_t streamIndex, const size_t subStreamIndex, const size_t offset );
148+
144149
void addTranscodeStream( const std::string& filename, const size_t streamIndex, ProfileLoader::Profile& profile, const size_t offset = 0 );
145150

146151
void addTranscodeStream( const std::string& filename, const size_t streamIndex, const size_t subStreamIndex, ProfileLoader::Profile& profile, const size_t offset = 0 );

0 commit comments

Comments
 (0)