Skip to content

Commit c214cce

Browse files
author
Clement Champetier
committed
Transcoder: refactoring getAudioProfileFromFile to getProfileFromFile
Create a video or audio profile depending on the input stream type.
1 parent f304bb4 commit c214cce

File tree

2 files changed

+49
-25
lines changed

2 files changed

+49
-25
lines changed

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void Transcoder::addTranscodeStream( const std::string& filename, const size_t s
340340
{
341341
// Get profile from input file
342342
InputFile* referenceFile = addInputFile( filename, streamIndex );
343-
ProfileLoader::Profile profile = getAudioProfileFromFile( *referenceFile, streamIndex );
343+
ProfileLoader::Profile profile = getProfileFromFile( *referenceFile, streamIndex );
344344

345345
addTranscodeStream( filename, streamIndex, subStreamIndex, profile, offset );
346346
}
@@ -416,35 +416,59 @@ InputFile* Transcoder::addInputFile( const std::string& filename, const size_t s
416416
return referenceFile;
417417
}
418418

419-
ProfileLoader::Profile Transcoder::getAudioProfileFromFile( InputFile& inputFile, const size_t streamIndex )
419+
ProfileLoader::Profile Transcoder::getProfileFromFile( InputFile& inputFile, const size_t streamIndex )
420420
{
421421
NoDisplayProgress progress;
422422
inputFile.analyse( progress, eAnalyseLevelHeader );
423423

424+
const VideoProperties* videoProperties = NULL;
424425
const AudioProperties* audioProperties = NULL;
425-
for( size_t i = 0; i < inputFile.getProperties().getAudioProperties().size(); i++ )
426-
{
427-
if( inputFile.getProperties().getAudioProperties().at( i ).getStreamIndex() == streamIndex )
428-
{
429-
audioProperties = &inputFile.getProperties().getAudioProperties().at( i );
426+
switch( inputFile.getStream( streamIndex ).getStreamType() )
427+
{
428+
case AVMEDIA_TYPE_VIDEO:
429+
{
430+
videoProperties = &inputFile.getProperties().getVideoPropertiesWithStreamIndex( streamIndex );
431+
break;
432+
}
433+
case AVMEDIA_TYPE_AUDIO:
434+
{
435+
audioProperties = &inputFile.getProperties().getAudioPropertiesWithStreamIndex( streamIndex );
436+
break;
437+
}
438+
default:
430439
break;
431-
}
432-
}
433-
if( audioProperties == NULL )
434-
throw std::runtime_error( "cannot set audio stream properties" );
435-
436-
ProfileLoader::Profile audioProfile;
437-
audioProfile[ constants::avProfileIdentificator ] = "presetRewrap";
438-
audioProfile[ constants::avProfileIdentificatorHuman ] = "Preset rewrap";
439-
audioProfile[ constants::avProfileType ] = avtranscoder::constants::avProfileTypeAudio;
440-
audioProfile[ constants::avProfileCodec ] = audioProperties->getCodecName();
441-
audioProfile[ constants::avProfileSampleFormat ] = audioProperties->getSampleFormatName();
442-
std::stringstream ss;
443-
ss << audioProperties->getSampleRate();
444-
audioProfile[ constants::avProfileSampleRate ] = ss.str();
445-
audioProfile[ constants::avProfileChannel ] = "1";
446-
447-
return audioProfile;
440+
}
441+
442+
// common fileds in profile types
443+
ProfileLoader::Profile profile;
444+
profile[ constants::avProfileIdentificator ] = "profileFromInput";
445+
profile[ constants::avProfileIdentificatorHuman ] = "profile from input";
446+
447+
// video
448+
if( videoProperties != NULL )
449+
{
450+
profile[ constants::avProfileType ] = avtranscoder::constants::avProfileTypeVideo;
451+
profile[ constants::avProfileCodec ] = videoProperties->getCodecName();
452+
profile[ constants::avProfilePixelFormat ] = videoProperties->getPixelProperties().getPixelFormatName();
453+
std::stringstream ss;
454+
ss << videoProperties->getFps();
455+
profile[ constants::avProfileFrameRate ] = ss.str();
456+
profile[ constants::avProfileWidth ] = videoProperties->getWidth();
457+
profile[ constants::avProfileHeight ] = videoProperties->getHeight();
458+
}
459+
// audio
460+
else if( audioProperties != NULL )
461+
{
462+
profile[ constants::avProfileType ] = avtranscoder::constants::avProfileTypeAudio;
463+
profile[ constants::avProfileCodec ] = audioProperties->getCodecName();
464+
profile[ constants::avProfileSampleFormat ] = audioProperties->getSampleFormatName();
465+
std::stringstream ss;
466+
ss << audioProperties->getSampleRate();
467+
profile[ constants::avProfileSampleRate ] = ss.str();
468+
profile[ constants::avProfileChannel ] = "1";
469+
}
470+
471+
return profile;
448472
}
449473

450474
double Transcoder::getStreamDuration( size_t indexStream ) const

src/AvTranscoder/transcoder/Transcoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class AvExport Transcoder
148148

149149
InputFile* addInputFile( const std::string& filename, const size_t streamIndex );
150150

151-
ProfileLoader::Profile getAudioProfileFromFile( InputFile& inputFile, const size_t streamIndex ); ///< The function analyses the inputFile
151+
ProfileLoader::Profile getProfileFromFile( InputFile& inputFile, const size_t streamIndex ); ///< The function analyses the inputFile
152152

153153
/**
154154
* @brief Get the duration of the stream, in seconds

0 commit comments

Comments
 (0)