@@ -338,53 +338,11 @@ void Transcoder::addRewrapStream( const std::string& filename, const size_t stre
338
338
339
339
void Transcoder::addTranscodeStream ( const std::string& filename, const size_t streamIndex, const size_t subStreamIndex, const double offset )
340
340
{
341
+ // Get profile from input file
341
342
InputFile* referenceFile = addInputFile ( filename, streamIndex );
343
+ ProfileLoader::Profile profile = getAudioProfileFromFile ( *referenceFile, streamIndex );
342
344
343
- // Create profile as input configuration
344
- NoDisplayProgress progress;
345
- referenceFile->analyse ( progress, eAnalyseLevelHeader );
346
-
347
- const AudioProperties* audioProperties = NULL ;
348
- for ( size_t i = 0 ; i < referenceFile->getProperties ().getAudioProperties ().size (); i++ )
349
- {
350
- if ( referenceFile->getProperties ().getAudioProperties ().at ( i ).getStreamId () == streamIndex )
351
- {
352
- audioProperties = &referenceFile->getProperties ().getAudioProperties ().at ( i );
353
- }
354
- }
355
- if ( audioProperties == NULL )
356
- throw std::runtime_error ( " cannot set audio stream properties" );
357
-
358
- ProfileLoader::Profile profile;
359
- profile[ constants::avProfileIdentificator ] = " presetRewrap" ;
360
- profile[ constants::avProfileIdentificatorHuman ] = " Preset rewrap" ;
361
- profile[ constants::avProfileType ] = avtranscoder::constants::avProfileTypeAudio;
362
- profile[ constants::avProfileCodec ] = audioProperties->getCodecName ();
363
- profile[ constants::avProfileSampleFormat ] = audioProperties->getSampleFormatName ();
364
- std::stringstream ss;
365
- ss << audioProperties->getSampleRate ();
366
- profile[ constants::avProfileSampleRate ] = ss.str ();
367
- profile[ constants::avProfileChannel ] = " 1" ;
368
-
369
- // Add profile
370
- _profileLoader.loadProfile ( profile );
371
-
372
- switch ( referenceFile->getStream ( streamIndex ).getStreamType () )
373
- {
374
- case AVMEDIA_TYPE_VIDEO:
375
- case AVMEDIA_TYPE_AUDIO:
376
- {
377
- _streamTranscoders.push_back ( new StreamTranscoder ( referenceFile->getStream ( streamIndex ), _outputFile, profile, subStreamIndex , offset ) );
378
- break ;
379
- }
380
- case AVMEDIA_TYPE_DATA:
381
- case AVMEDIA_TYPE_SUBTITLE:
382
- case AVMEDIA_TYPE_ATTACHMENT:
383
- default :
384
- {
385
- throw std::runtime_error ( " unsupported media type in transcode setup" );
386
- }
387
- }
345
+ addTranscodeStream ( filename, streamIndex, subStreamIndex, profile, offset );
388
346
}
389
347
390
348
void Transcoder::addTranscodeStream ( const std::string& filename, const size_t streamIndex, const size_t subStreamIndex, ProfileLoader::Profile& profile, const double offset )
@@ -458,6 +416,37 @@ InputFile* Transcoder::addInputFile( const std::string& filename, const size_t s
458
416
return referenceFile;
459
417
}
460
418
419
+ ProfileLoader::Profile Transcoder::getAudioProfileFromFile ( InputFile& inputFile, const size_t streamIndex )
420
+ {
421
+ NoDisplayProgress progress;
422
+ inputFile.analyse ( progress, eAnalyseLevelHeader );
423
+
424
+ 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 );
430
+ 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;
448
+ }
449
+
461
450
double Transcoder::getStreamDuration ( size_t indexStream ) const
462
451
{
463
452
return _streamTranscoders.at ( indexStream )->getDuration ();
0 commit comments