Add RFC7845 downmix algorithm (#12300)

This commit is contained in:
gnattu
2024-07-30 23:50:22 +08:00
committed by GitHub
parent f7ab17d24d
commit 0a1a109b2e
4 changed files with 83 additions and 21 deletions

View File

@@ -2666,29 +2666,18 @@ namespace MediaBrowser.Controller.MediaEncoding
var filters = new List<string>();
if (channels.HasValue
&& channels.Value == 2
&& state.AudioStream is not null
&& state.AudioStream.Channels.HasValue
&& state.AudioStream.Channels.Value == 6)
if (channels is 2 && state.AudioStream?.Channels is > 2)
{
var hasDownMixFilter = DownMixAlgorithmsHelper.AlgorithmFilterStrings.TryGetValue((encodingOptions.DownMixStereoAlgorithm, DownMixAlgorithmsHelper.InferChannelLayout(state.AudioStream)), out var downMixFilterString);
if (hasDownMixFilter)
{
filters.Add(downMixFilterString);
}
if (!encodingOptions.DownMixAudioBoost.Equals(1))
{
filters.Add("volume=" + encodingOptions.DownMixAudioBoost.ToString(CultureInfo.InvariantCulture));
}
switch (encodingOptions.DownMixStereoAlgorithm)
{
case DownMixStereoAlgorithms.Dave750:
filters.Add("pan=stereo|c0=0.5*c2+0.707*c0+0.707*c4+0.5*c3|c1=0.5*c2+0.707*c1+0.707*c5+0.5*c3");
break;
case DownMixStereoAlgorithms.NightmodeDialogue:
filters.Add("pan=stereo|c0=c2+0.30*c0+0.30*c4|c1=c2+0.30*c1+0.30*c5");
break;
case DownMixStereoAlgorithms.None:
default:
break;
}
}
var isCopyingTimestamps = state.CopyTimestamps || state.TranscodingType != TranscodingJobType.Progressive;
@@ -7008,7 +6997,10 @@ namespace MediaBrowser.Controller.MediaEncoding
var channels = state.OutputAudioChannels;
if (channels.HasValue && ((channels.Value != 2 && state.AudioStream?.Channels != 6) || encodingOptions.DownMixStereoAlgorithm == DownMixStereoAlgorithms.None))
var useDownMixAlgorithm = state.AudioStream is not null
&& DownMixAlgorithmsHelper.AlgorithmFilterStrings.ContainsKey((encodingOptions.DownMixStereoAlgorithm, DownMixAlgorithmsHelper.InferChannelLayout(state.AudioStream)));
if (channels.HasValue && !useDownMixAlgorithm)
{
args += " -ac " + channels.Value;
}