fix bitrate issues

This commit is contained in:
wrapper 2025-08-17 23:17:41 +07:00
parent eb6bb062f7
commit 7ab9e56401

View file

@ -697,7 +697,6 @@ static int64_t mf_enca_output_score(AVCodecContext *avctx, IMFMediaType *type)
UINT32 t;
GUID tg;
int64_t score = 0;
int bitrate_now = avctx->bit_rate;
hr = IMFAttributes_GetUINT32(type, &MF_MT_AUDIO_SAMPLES_PER_SECOND, &t);
if (!FAILED(hr) && t == avctx->sample_rate)
@ -715,9 +714,6 @@ static int64_t mf_enca_output_score(AVCodecContext *avctx, IMFMediaType *type)
if (avctx->codec_id == AV_CODEC_ID_AAC) {
hr = IMFAttributes_GetUINT32(type, &MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION, &t);
if (((t >= 0x2c && t < 0x34) || t == 0x52 || t == 0x53) && (avctx->profile != AV_PROFILE_UNKNOWN || bitrate_now <= 64000))
bitrate_now /= 2; // 24H2: bitrate of HE-AAC is core bitrate times 2
switch (avctx->profile) {
case AV_PROFILE_AAC_LOW:
if (!FAILED(hr) && !(t >= 0x28 && t < 0x2c) && t != 0x50 && t != 0x51)
@ -739,7 +735,7 @@ static int64_t mf_enca_output_score(AVCodecContext *avctx, IMFMediaType *type)
// Select the bitrate (lowest priority).
hr = IMFAttributes_GetUINT32(type, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, &t);
if (!FAILED(hr)) {
int diff = (int)t - bitrate_now / 8;
int diff = (int)t - avctx->bit_rate / 8;
if (diff >= 0) {
score |= (1LL << 31) - diff; // prefer lower bitrate
} else {
@ -1021,12 +1017,10 @@ static int mf_choose_output_type(AVCodecContext *avctx)
hr = IMFTransform_SetOutputType(c->mft, c->out_stream_id, out_type, 0);
if (!FAILED(hr)) {
unsigned int bitrate;
IMFAttributes_GetUINT32(out_type, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, &bitrate);
if (avctx->codec_id == AV_CODEC_ID_AAC) {
IMFAttributes_GetUINT32(out_type, &MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION, &profile_negotiated);
IMFAttributes_GetUINT32(out_type, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, &bitrate);
if ((profile_set >= 0x2c && profile_set < 0x34) || profile_set == 0x52 || profile_set == 0x53)
bitrate *= 2;
if (profile_set != profile_negotiated) { // Setting PROFILE_LEVEL_INDICATION in AAC Encoder is only supported starting from Win11 24H2, fail if reported a mismatch in profile level indication.
av_log(avctx, AV_LOG_ERROR, "profile level indication mismatch: (out_type profile_level) %d != (out_type_negotiated profile_level) %d\n", profile_set, profile_negotiated);
@ -1036,7 +1030,7 @@ static int mf_choose_output_type(AVCodecContext *avctx)
ret = 1;
}
} else {
if (bitrate) av_log(avctx, AV_LOG_INFO, "using bitrate %dkbps\n", bitrate / 125);
av_log(avctx, AV_LOG_INFO, "using bitrate %dkbps\n", bitrate / 125);
ret = 1;
}
} else if (hr == MF_E_TRANSFORM_TYPE_NOT_SET) {