@@ -417,10 +417,30 @@ int RGYOutputAvcodec::AutoSelectSamplingRate(const int *samplingRateList, int sr
417
417
}
418
418
419
419
AVSampleFormat RGYOutputAvcodec::AutoSelectSampleFmt (const AVSampleFormat *samplefmtList, const AVCodecContext *srcAudioCtx) {
420
- AVSampleFormat srcFormat = srcAudioCtx->sample_fmt ;
420
+ const AVSampleFormat srcFormat = srcAudioCtx->sample_fmt ;
421
421
if (samplefmtList == nullptr ) {
422
422
return srcFormat;
423
423
}
424
+
425
+ static const auto sampleFmtLevel = make_array<AVSampleFormat>(
426
+ AV_SAMPLE_FMT_DBLP,
427
+ AV_SAMPLE_FMT_DBL,
428
+ AV_SAMPLE_FMT_FLTP,
429
+ AV_SAMPLE_FMT_FLT,
430
+ AV_SAMPLE_FMT_S32P,
431
+ AV_SAMPLE_FMT_S32,
432
+ AV_SAMPLE_FMT_S16P,
433
+ AV_SAMPLE_FMT_S16,
434
+ AV_SAMPLE_FMT_U8P,
435
+ AV_SAMPLE_FMT_U8
436
+ );
437
+ for (const auto fmt : sampleFmtLevel) {
438
+ for (int i = 0 ; samplefmtList[i] >= 0 ; i++) {
439
+ if (fmt == samplefmtList[i]) {
440
+ return fmt;
441
+ }
442
+ }
443
+ }
424
444
if (srcFormat == AV_SAMPLE_FMT_NONE) {
425
445
return samplefmtList[0 ];
426
446
}
@@ -429,29 +449,6 @@ AVSampleFormat RGYOutputAvcodec::AutoSelectSampleFmt(const AVSampleFormat *sampl
429
449
return samplefmtList[i];
430
450
}
431
451
}
432
- static const auto sampleFmtLevel = make_array<std::pair<AVSampleFormat, int >>(
433
- std::make_pair (AV_SAMPLE_FMT_DBLP, 8 ),
434
- std::make_pair (AV_SAMPLE_FMT_DBL, 8 ),
435
- std::make_pair (AV_SAMPLE_FMT_FLTP, 6 ),
436
- std::make_pair (AV_SAMPLE_FMT_FLT, 6 ),
437
- std::make_pair (AV_SAMPLE_FMT_S32P, 4 ),
438
- std::make_pair (AV_SAMPLE_FMT_S32, 4 ),
439
- std::make_pair (AV_SAMPLE_FMT_S16P, 2 ),
440
- std::make_pair (AV_SAMPLE_FMT_S16, 2 ),
441
- std::make_pair (AV_SAMPLE_FMT_U8P, 1 ),
442
- std::make_pair (AV_SAMPLE_FMT_U8, 1 )
443
- );
444
- int srcFormatLevel = std::find_if (sampleFmtLevel.begin (), sampleFmtLevel.end (),
445
- [srcFormat](const std::pair<AVSampleFormat, int >& targetFormat) { return targetFormat.first == srcFormat;})->second ;
446
- auto foundFormat = std::find_if (sampleFmtLevel.begin (), sampleFmtLevel.end (),
447
- [srcFormatLevel](const std::pair<AVSampleFormat, int >& targetFormat) { return targetFormat.second == srcFormatLevel; });
448
- for (; foundFormat != sampleFmtLevel.end (); foundFormat++) {
449
- for (int i = 0 ; samplefmtList[i] >= 0 ; i++) {
450
- if (foundFormat->first == samplefmtList[i]) {
451
- return samplefmtList[i];
452
- }
453
- }
454
- }
455
452
return samplefmtList[0 ];
456
453
}
457
454
@@ -1321,7 +1318,7 @@ RGY_ERR RGYOutputAvcodec::InitAudio(AVMuxAudio *muxAudio, AVOutputStreamPrm *inp
1321
1318
// そのときにはとりあえずAV_SAMPLE_FMT_S16で適当にフィルタを初期化しておく
1322
1319
// 実際のsample_fmtはAVFrameに設定されており、フィルタ実行前の再度のInitAudioFilterで
1323
1320
// 必要に応じて再初期化されるので、ここでは仮の値でも問題はない
1324
- av_get_sample_fmt_name (muxAudio->outCodecDecodeCtx ->sample_fmt ) ? muxAudio->outCodecDecodeCtx ->sample_fmt : AV_SAMPLE_FMT_S16 );
1321
+ av_get_sample_fmt_name (muxAudio->outCodecDecodeCtx ->sample_fmt ) ? muxAudio->outCodecDecodeCtx ->sample_fmt : AV_SAMPLE_FMT_FLTP );
1325
1322
if (sts != RGY_ERR_NONE) return sts;
1326
1323
} else if (muxAudio->bsfc == nullptr && muxAudio->streamIn ->codecpar ->codec_id == AV_CODEC_ID_AAC && muxAudio->streamIn ->codecpar ->extradata == NULL && m_Mux.video .streamOut ) {
1327
1324
muxAudio->bsfc = InitStreamBsf (_T (" aac_adtstoasc" ), muxAudio->streamIn );
0 commit comments