From daf8d649f2bcadddabb2293fdadee9df436e7bf1 Mon Sep 17 00:00:00 2001 From: gnattu Date: Mon, 29 Jul 2024 06:19:04 +0800 Subject: [PATCH 1/5] Add AC4 downmix Signed-off-by: gnattu --- .../MediaEncoding/DownMixAlgorithmsHelper.cs | 5 +++++ .../Entities/DownMixStereoAlgorithms.cs | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs b/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs index b90f9a4793..5d253184a7 100644 --- a/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs @@ -15,13 +15,18 @@ public static class DownMixAlgorithmsHelper public static readonly Dictionary<(DownMixStereoAlgorithms, string), string> AlgorithmFilterStrings = new() { { (DownMixStereoAlgorithms.Dave750, "5.1"), "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" }, + { (DownMixStereoAlgorithms.Dave750, "7.1"), "pan=5.1(side)|c0=c0|c1=c1|c2=c2|c3=c3|c4=0.707*c4+0.707*c6|c5=0.707*c5+0.707*c7,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" }, { (DownMixStereoAlgorithms.NightmodeDialogue, "5.1"), "pan=stereo|c0=c2+0.30*c0+0.30*c4|c1=c2+0.30*c1+0.30*c5" }, + { (DownMixStereoAlgorithms.NightmodeDialogue, "7.1"), "pan=5.1(side)|c0=c0|c1=c1|c2=c2|c3=c3|c4=0.707*c4+0.707*c6|c5=0.707*c5+0.707*c7,pan=stereo|c0=c2+0.30*c0+0.30*c4|c1=c2+0.30*c1+0.30*c5" }, { (DownMixStereoAlgorithms.Rfc7845, "3.0"), "pan=stereo|c0=0.414214*c2+0.585786*c0|c1=0.414214*c2+0.585786*c1" }, { (DownMixStereoAlgorithms.Rfc7845, "quad"), "pan=stereo|c0=0.422650*c0+0.366025*c2+0.211325*c3|c1=0.422650*c1+0.366025*c3+0.211325*c2" }, { (DownMixStereoAlgorithms.Rfc7845, "5.0"), "pan=stereo|c0=0.460186*c2+0.650802*c0+0.563611*c3+0.325401*c4|c1=0.460186*c2+0.650802*c1+0.563611*c4+0.325401*c3" }, { (DownMixStereoAlgorithms.Rfc7845, "5.1"), "pan=stereo|c0=0.374107*c2+0.529067*c0+0.458186*c4+0.264534*c5+0.374107*c3|c1=0.374107*c2+0.529067*c1+0.458186*c5+0.264534*c4+0.374107*c3" }, { (DownMixStereoAlgorithms.Rfc7845, "6.1"), "pan=stereo|c0=0.321953*c2+0.455310*c0+0.394310*c5+0.227655*c6+0.278819*c4+0.321953*c3|c1=0.321953*c2+0.455310*c1+0.394310*c6+0.227655*c5+0.278819*c4+0.321953*c3" }, { (DownMixStereoAlgorithms.Rfc7845, "7.1"), "pan=stereo|c0=0.274804*c2+0.388631*c0+0.336565*c6+0.194316*c7+0.336565*c4+0.194316*c5+0.274804*c3|c1=0.274804*c2+0.388631*c1+0.336565*c7+0.194316*c6+0.336565*c5+0.194316*c4+0.274804*c3" }, + { (DownMixStereoAlgorithms.Ac4, "3.0"), "pan=stereo|c0=c0+0.707*c2|c1=c1+0.707*c2"}, + { (DownMixStereoAlgorithms.Ac4, "5.1"), "pan=stereo|c0=c0+0.707*c2+0.707*c4|c1=c1+0.707*c2+0.707*c5"}, + { (DownMixStereoAlgorithms.Ac4, "7.1"), "pan=5.1(side)|c0=c0|c1=c1|c2=c2|c3=c3|c4=0.707*c4+0.707*c6|c5=0.707*c5+0.707*c7,pan=stereo|c0=c0+0.707*c2+0.707*c4|c1=c1+0.707*c2+0.707*c5"}, }; /// diff --git a/MediaBrowser.Model/Entities/DownMixStereoAlgorithms.cs b/MediaBrowser.Model/Entities/DownMixStereoAlgorithms.cs index be43ef32d3..dcb2c802d9 100644 --- a/MediaBrowser.Model/Entities/DownMixStereoAlgorithms.cs +++ b/MediaBrowser.Model/Entities/DownMixStereoAlgorithms.cs @@ -1,8 +1,7 @@ namespace MediaBrowser.Model.Entities; /// -/// An enum representing an algorithm to downmix 6ch+ to stereo. -/// Algorithms sourced from https://superuser.com/questions/852400/properly-downmix-5-1-to-stereo-using-ffmpeg/1410620#1410620. +/// An enum representing an algorithm to downmix surround sound to stereo. /// public enum DownMixStereoAlgorithms { @@ -13,16 +12,24 @@ public enum DownMixStereoAlgorithms /// /// Algorithm by Dave_750. + /// Sourced from https://superuser.com/questions/852400/properly-downmix-5-1-to-stereo-using-ffmpeg/1410620#1410620. /// Dave750 = 1, /// /// Nightmode Dialogue algorithm. + /// Sourced from https://superuser.com/questions/852400/properly-downmix-5-1-to-stereo-using-ffmpeg/1410620#1410620. /// NightmodeDialogue = 2, /// /// RFC7845 Section 5.1.1.5 defined algorithm. /// - Rfc7845 = 3 + Rfc7845 = 3, + + /// + /// AC-4 standard algorithm with its default gain values. + /// Defined in ETSI TS 103 190 Section 6.2.17 + /// + Ac4 = 4 } From 31dccaca0f8d3d924756286af54c70101155cffb Mon Sep 17 00:00:00 2001 From: gnattu Date: Mon, 29 Jul 2024 10:04:44 +0800 Subject: [PATCH 2/5] Add 5.0 and 7.0 support to ac4 downmix Signed-off-by: gnattu --- .../MediaEncoding/DownMixAlgorithmsHelper.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs b/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs index 5d253184a7..7583961e96 100644 --- a/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs @@ -25,7 +25,9 @@ public static class DownMixAlgorithmsHelper { (DownMixStereoAlgorithms.Rfc7845, "6.1"), "pan=stereo|c0=0.321953*c2+0.455310*c0+0.394310*c5+0.227655*c6+0.278819*c4+0.321953*c3|c1=0.321953*c2+0.455310*c1+0.394310*c6+0.227655*c5+0.278819*c4+0.321953*c3" }, { (DownMixStereoAlgorithms.Rfc7845, "7.1"), "pan=stereo|c0=0.274804*c2+0.388631*c0+0.336565*c6+0.194316*c7+0.336565*c4+0.194316*c5+0.274804*c3|c1=0.274804*c2+0.388631*c1+0.336565*c7+0.194316*c6+0.336565*c5+0.194316*c4+0.274804*c3" }, { (DownMixStereoAlgorithms.Ac4, "3.0"), "pan=stereo|c0=c0+0.707*c2|c1=c1+0.707*c2"}, + { (DownMixStereoAlgorithms.Ac4, "5.0"), "pan=stereo|c0=c0+0.707*c2+0.707*c3|c1=c1+0.707*c2+0.707*c4"}, { (DownMixStereoAlgorithms.Ac4, "5.1"), "pan=stereo|c0=c0+0.707*c2+0.707*c4|c1=c1+0.707*c2+0.707*c5"}, + { (DownMixStereoAlgorithms.Ac4, "7.0"), "pan=5.0(side)|c0=c0|c1=c1|c2=c2|c3=0.707*c3+0.707*c5|c4=0.707*c4+0.707*c6,pan=stereo|c0=c0+0.707*c2+0.707*c3|c1=c1+0.707*c2+0.707*c4"}, { (DownMixStereoAlgorithms.Ac4, "7.1"), "pan=5.1(side)|c0=c0|c1=c1|c2=c2|c3=c3|c4=0.707*c4+0.707*c6|c5=0.707*c5+0.707*c7,pan=stereo|c0=c0+0.707*c2+0.707*c4|c1=c1+0.707*c2+0.707*c5"}, }; From 8f28c3a0fbdd285288de76b5213b1462005eb7dc Mon Sep 17 00:00:00 2001 From: gnattu Date: Mon, 29 Jul 2024 10:22:51 +0800 Subject: [PATCH 3/5] fix doc Signed-off-by: gnattu --- MediaBrowser.Model/Entities/DownMixStereoAlgorithms.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.Model/Entities/DownMixStereoAlgorithms.cs b/MediaBrowser.Model/Entities/DownMixStereoAlgorithms.cs index dcb2c802d9..0c03d430dc 100644 --- a/MediaBrowser.Model/Entities/DownMixStereoAlgorithms.cs +++ b/MediaBrowser.Model/Entities/DownMixStereoAlgorithms.cs @@ -29,7 +29,7 @@ public enum DownMixStereoAlgorithms /// /// AC-4 standard algorithm with its default gain values. - /// Defined in ETSI TS 103 190 Section 6.2.17 + /// Defined in ETSI TS 103 190 Section 6.2.17. /// Ac4 = 4 } From c171b6def22b32740654d7830f4ef6440854c404 Mon Sep 17 00:00:00 2001 From: gnattu Date: Mon, 29 Jul 2024 10:28:22 +0800 Subject: [PATCH 4/5] fix space Signed-off-by: gnattu --- .../MediaEncoding/DownMixAlgorithmsHelper.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs b/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs index 7583961e96..64a0f59920 100644 --- a/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs @@ -24,11 +24,11 @@ public static class DownMixAlgorithmsHelper { (DownMixStereoAlgorithms.Rfc7845, "5.1"), "pan=stereo|c0=0.374107*c2+0.529067*c0+0.458186*c4+0.264534*c5+0.374107*c3|c1=0.374107*c2+0.529067*c1+0.458186*c5+0.264534*c4+0.374107*c3" }, { (DownMixStereoAlgorithms.Rfc7845, "6.1"), "pan=stereo|c0=0.321953*c2+0.455310*c0+0.394310*c5+0.227655*c6+0.278819*c4+0.321953*c3|c1=0.321953*c2+0.455310*c1+0.394310*c6+0.227655*c5+0.278819*c4+0.321953*c3" }, { (DownMixStereoAlgorithms.Rfc7845, "7.1"), "pan=stereo|c0=0.274804*c2+0.388631*c0+0.336565*c6+0.194316*c7+0.336565*c4+0.194316*c5+0.274804*c3|c1=0.274804*c2+0.388631*c1+0.336565*c7+0.194316*c6+0.336565*c5+0.194316*c4+0.274804*c3" }, - { (DownMixStereoAlgorithms.Ac4, "3.0"), "pan=stereo|c0=c0+0.707*c2|c1=c1+0.707*c2"}, - { (DownMixStereoAlgorithms.Ac4, "5.0"), "pan=stereo|c0=c0+0.707*c2+0.707*c3|c1=c1+0.707*c2+0.707*c4"}, - { (DownMixStereoAlgorithms.Ac4, "5.1"), "pan=stereo|c0=c0+0.707*c2+0.707*c4|c1=c1+0.707*c2+0.707*c5"}, - { (DownMixStereoAlgorithms.Ac4, "7.0"), "pan=5.0(side)|c0=c0|c1=c1|c2=c2|c3=0.707*c3+0.707*c5|c4=0.707*c4+0.707*c6,pan=stereo|c0=c0+0.707*c2+0.707*c3|c1=c1+0.707*c2+0.707*c4"}, - { (DownMixStereoAlgorithms.Ac4, "7.1"), "pan=5.1(side)|c0=c0|c1=c1|c2=c2|c3=c3|c4=0.707*c4+0.707*c6|c5=0.707*c5+0.707*c7,pan=stereo|c0=c0+0.707*c2+0.707*c4|c1=c1+0.707*c2+0.707*c5"}, + { (DownMixStereoAlgorithms.Ac4, "3.0"), "pan=stereo|c0=c0+0.707*c2|c1=c1+0.707*c2" }, + { (DownMixStereoAlgorithms.Ac4, "5.0"), "pan=stereo|c0=c0+0.707*c2+0.707*c3|c1=c1+0.707*c2+0.707*c4" }, + { (DownMixStereoAlgorithms.Ac4, "5.1"), "pan=stereo|c0=c0+0.707*c2+0.707*c4|c1=c1+0.707*c2+0.707*c5" }, + { (DownMixStereoAlgorithms.Ac4, "7.0"), "pan=5.0(side)|c0=c0|c1=c1|c2=c2|c3=0.707*c3+0.707*c5|c4=0.707*c4+0.707*c6,pan=stereo|c0=c0+0.707*c2+0.707*c3|c1=c1+0.707*c2+0.707*c4" }, + { (DownMixStereoAlgorithms.Ac4, "7.1"), "pan=5.1(side)|c0=c0|c1=c1|c2=c2|c3=c3|c4=0.707*c4+0.707*c6|c5=0.707*c5+0.707*c7,pan=stereo|c0=c0+0.707*c2+0.707*c4|c1=c1+0.707*c2+0.707*c5" }, }; /// From 3788ccd447ffaa4638f3fe5d235c5bb92b809692 Mon Sep 17 00:00:00 2001 From: gnattu Date: Thu, 1 Aug 2024 07:45:16 +0800 Subject: [PATCH 5/5] Add comments for Dave750/NightmodeDialogue 7.1 downmix Signed-off-by: gnattu --- .../MediaEncoding/DownMixAlgorithmsHelper.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs b/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs index 64a0f59920..749f872710 100644 --- a/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/DownMixAlgorithmsHelper.cs @@ -15,8 +15,10 @@ public static class DownMixAlgorithmsHelper public static readonly Dictionary<(DownMixStereoAlgorithms, string), string> AlgorithmFilterStrings = new() { { (DownMixStereoAlgorithms.Dave750, "5.1"), "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" }, + // Use AC-4 algorithm to downmix 7.1 inputs to 5.1 first { (DownMixStereoAlgorithms.Dave750, "7.1"), "pan=5.1(side)|c0=c0|c1=c1|c2=c2|c3=c3|c4=0.707*c4+0.707*c6|c5=0.707*c5+0.707*c7,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" }, { (DownMixStereoAlgorithms.NightmodeDialogue, "5.1"), "pan=stereo|c0=c2+0.30*c0+0.30*c4|c1=c2+0.30*c1+0.30*c5" }, + // Use AC-4 algorithm to downmix 7.1 inputs to 5.1 first { (DownMixStereoAlgorithms.NightmodeDialogue, "7.1"), "pan=5.1(side)|c0=c0|c1=c1|c2=c2|c3=c3|c4=0.707*c4+0.707*c6|c5=0.707*c5+0.707*c7,pan=stereo|c0=c2+0.30*c0+0.30*c4|c1=c2+0.30*c1+0.30*c5" }, { (DownMixStereoAlgorithms.Rfc7845, "3.0"), "pan=stereo|c0=0.414214*c2+0.585786*c0|c1=0.414214*c2+0.585786*c1" }, { (DownMixStereoAlgorithms.Rfc7845, "quad"), "pan=stereo|c0=0.422650*c0+0.366025*c2+0.211325*c3|c1=0.422650*c1+0.366025*c3+0.211325*c2" },