diff --git a/obs/audio-encoders.cpp b/obs/audio-encoders.cpp index b929e0604..b1b1d60a5 100644 --- a/obs/audio-encoders.cpp +++ b/obs/audio-encoders.cpp @@ -208,3 +208,30 @@ const char *GetAACEncoderForBitrate(int bitrate) return NULL; return res->second; } + +#define INVALID_BITRATE 10000 + +int FindClosestAvailableAACBitrate(int bitrate) +{ + auto &map_ = GetAACEncoderBitrateMap(); + int prev = 0; + int next = INVALID_BITRATE; + + for (auto val : map_) { + if (next > val.first) { + if (val.first == bitrate) + return bitrate; + + if (val.first < next && val.first > bitrate) + next = val.first; + if (val.first > prev && val.first < bitrate) + prev = val.first; + } + } + + if (next != INVALID_BITRATE) + return next; + if (prev != 0) + return prev; + return 192; +} diff --git a/obs/audio-encoders.hpp b/obs/audio-encoders.hpp index 34bb391ea..81c69e6da 100644 --- a/obs/audio-encoders.hpp +++ b/obs/audio-encoders.hpp @@ -4,3 +4,4 @@ const std::map &GetAACEncoderBitrateMap(); const char *GetAACEncoderForBitrate(int bitrate); +int FindClosestAvailableAACBitrate(int bitrate); diff --git a/obs/window-basic-main-outputs.cpp b/obs/window-basic-main-outputs.cpp index b84291d59..db27cf5f4 100644 --- a/obs/window-basic-main-outputs.cpp +++ b/obs/window-basic-main-outputs.cpp @@ -252,7 +252,10 @@ SimpleOutput::SimpleOutput(OBSBasic *main_) : BasicOutputHandler(main_) int SimpleOutput::GetAudioBitrate() const { - return config_get_uint(main->Config(), "SimpleOutput", "ABitrate"); + int bitrate = (int)config_get_uint(main->Config(), "SimpleOutput", + "ABitrate"); + + return FindClosestAvailableAACBitrate(bitrate); } void SimpleOutput::Update() @@ -875,7 +878,8 @@ int AdvancedOutput::GetAudioBitrate(size_t i) const "Track1Bitrate", "Track2Bitrate", "Track3Bitrate", "Track4Bitrate", }; - return config_get_uint(main->Config(), "AdvOut", names[i]); + int bitrate = (int)config_get_uint(main->Config(), "AdvOut", names[i]); + return FindClosestAvailableAACBitrate(bitrate); } bool AdvancedOutput::StartStreaming(obs_service_t *service) diff --git a/obs/window-basic-settings.cpp b/obs/window-basic-settings.cpp index 43e05e60b..45fd16965 100644 --- a/obs/window-basic-settings.cpp +++ b/obs/window-basic-settings.cpp @@ -1023,6 +1023,8 @@ void OBSBasicSettings::LoadSimpleOutputSettings() const char *recEnc = config_get_string(main->Config(), "SimpleOutput", "RecEncoder"); + audioBitrate = FindClosestAvailableAACBitrate(audioBitrate); + ui->simpleOutputPath->setText(path); ui->simpleOutputVBitrate->setValue(videoBitrate); @@ -1263,6 +1265,11 @@ void OBSBasicSettings::LoadAdvOutputAudioSettings() const char *name4 = config_get_string(main->Config(), "AdvOut", "Track4Name"); + track1Bitrate = FindClosestAvailableAACBitrate(track1Bitrate); + track2Bitrate = FindClosestAvailableAACBitrate(track2Bitrate); + track3Bitrate = FindClosestAvailableAACBitrate(track3Bitrate); + track4Bitrate = FindClosestAvailableAACBitrate(track4Bitrate); + SetComboByName(ui->advOutTrack1Bitrate, std::to_string(track1Bitrate).c_str()); SetComboByName(ui->advOutTrack2Bitrate,