@@ -340,7 +340,7 @@ void Transcoder::addTranscodeStream( const std::string& filename, const size_t s
340
340
{
341
341
// Get profile from input file
342
342
InputFile* referenceFile = addInputFile ( filename, streamIndex );
343
- ProfileLoader::Profile profile = getAudioProfileFromFile ( *referenceFile, streamIndex );
343
+ ProfileLoader::Profile profile = getProfileFromFile ( *referenceFile, streamIndex );
344
344
345
345
addTranscodeStream ( filename, streamIndex, subStreamIndex, profile, offset );
346
346
}
@@ -416,35 +416,59 @@ InputFile* Transcoder::addInputFile( const std::string& filename, const size_t s
416
416
return referenceFile;
417
417
}
418
418
419
- ProfileLoader::Profile Transcoder::getAudioProfileFromFile ( InputFile& inputFile, const size_t streamIndex )
419
+ ProfileLoader::Profile Transcoder::getProfileFromFile ( InputFile& inputFile, const size_t streamIndex )
420
420
{
421
421
NoDisplayProgress progress;
422
422
inputFile.analyse ( progress, eAnalyseLevelHeader );
423
423
424
+ const VideoProperties* videoProperties = NULL ;
424
425
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 :
430
439
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;
448
472
}
449
473
450
474
double Transcoder::getStreamDuration ( size_t indexStream ) const
0 commit comments