1
0
Fork 0

Add option to downmix FFMS audio

When enabled, restore FFMS to old behavior, downmixing auduo to S16 mono. This can reduce cache usage.

Fix wangqr/Aegisub#31
This commit is contained in:
wangqr 2019-12-26 17:31:59 -05:00
parent 80ef2fbf35
commit cb77c0b395
4 changed files with 17 additions and 12 deletions

View File

@ -167,18 +167,20 @@ void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) {
throw agi::AudioProviderError("unknown or unsupported sample format");
}
#if defined(FFMS_MONO_OUTPUT) && FFMS_VERSION >= ((2 << 24) | (17 << 16) | (4 << 8) | 0)
if (channels > 1 || bytes_per_sample != 2) {
std::unique_ptr<FFMS_ResampleOptions, decltype(&FFMS_DestroyResampleOptions)>
opt(FFMS_CreateResampleOptions(AudioSource), FFMS_DestroyResampleOptions);
opt->ChannelLayout = FFMS_CH_FRONT_CENTER;
opt->SampleFormat = FFMS_FMT_S16;
#if FFMS_VERSION >= ((2 << 24) | (17 << 16) | (4 << 8) | 0)
if (OPT_GET("Provider/Audio/FFmpegSource/Downmix")->GetBool()) {
if (channels > 1 || bytes_per_sample != 2 || float_samples) {
std::unique_ptr<FFMS_ResampleOptions, decltype(&FFMS_DestroyResampleOptions)>
opt(FFMS_CreateResampleOptions(AudioSource), FFMS_DestroyResampleOptions);
opt->ChannelLayout = FFMS_CH_FRONT_CENTER;
opt->SampleFormat = FFMS_FMT_S16;
// Might fail if FFMS2 wasn't built with libavresample
if (!FFMS_SetOutputFormatA(AudioSource, opt.get(), nullptr)) {
channels = 1;
bytes_per_sample = 2;
float_samples = false;
// Might fail if FFMS2 wasn't built with libavresample
if (!FFMS_SetOutputFormatA(AudioSource, opt.get(), nullptr)) {
channels = 1;
bytes_per_sample = 2;
float_samples = false;
}
}
}
#endif

View File

@ -331,7 +331,8 @@
"Sample Rate" : 0
},
"FFmpegSource" : {
"Decode Error Handling" : "ignore"
"Decode Error Handling" : "ignore",
"Downmix" : false
}
},
"Avisynth" : {

View File

@ -401,6 +401,7 @@ void Advanced_Audio(wxTreebook *book, Preferences *parent) {
p->OptionChoice(ffms, _("Audio indexing error handling mode"), error_modes_choice, "Provider/Audio/FFmpegSource/Decode Error Handling");
p->OptionAdd(ffms, _("Always index all audio tracks"), "Provider/FFmpegSource/Index All Tracks");
p->OptionAdd(ffms, _("Downmix to 16bit mono audio"), "Provider/Audio/FFmpegSource/Downmix");
#endif
#ifdef WITH_PORTAUDIO

View File

@ -53,6 +53,7 @@ Project::Project(agi::Context *c) : context(c) {
OPT_SUB("Audio/Cache/Type", &Project::ReloadAudio, this);
OPT_SUB("Audio/Provider", &Project::ReloadAudio, this);
OPT_SUB("Provider/Audio/FFmpegSource/Decode Error Handling", &Project::ReloadAudio, this);
OPT_SUB("Provider/Audio/FFmpegSource/Downmix", &Project::ReloadAudio, this);
OPT_SUB("Provider/Avisynth/Allow Ancient", &Project::ReloadVideo, this);
OPT_SUB("Provider/Avisynth/Memory Max", &Project::ReloadVideo, this);
OPT_SUB("Provider/Video/FFmpegSource/Decoding Threads", &Project::ReloadVideo, this);