From 2df5ad5071bd822dad4c567e9a6b97bca6c37a54 Mon Sep 17 00:00:00 2001 From: John Andrews Date: Fri, 15 Nov 2024 08:31:41 +1300 Subject: [PATCH] FF-1851: Added special case for 8.0 and 6.0 to be 7.1 and 5.1 in set track titles --- .../FfmpegBuilderSetTrackTitles.cs | 23 +++- .../FFmpegBuilder_SetTrackTitlesTests.cs | 126 ++++++++++++++++++ 2 files changed, 146 insertions(+), 3 deletions(-) diff --git a/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderSetTrackTitles.cs b/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderSetTrackTitles.cs index a0bafeb9..19f34069 100644 --- a/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderSetTrackTitles.cs +++ b/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderSetTrackTitles.cs @@ -303,9 +303,7 @@ public class FfmpegBuilderSetTrackTitles: FfmpegBuilderNode formatter = Replace(formatter, "hearingimpared", hi ? "Hearing Impared" : string.Empty); formatter = Replace(formatter, "sdh", sdh ? "SDH" : string.Empty); formatter = Replace(formatter, "numchannels", channels.ToString("N1")); - formatter = Replace(formatter, "channels", Math.Abs(channels - 1) < 0.05f ? "Mono" : - Math.Abs(channels - 2) < 0.05f ? "Stereo" : - channels > 0 ? channels.ToString("0.0") : null); + formatter = Replace(formatter, "channels", GetChannelString(channels)); formatter = Replace(formatter, "bitrate", bitrate < 1 ? null : ((bitrate / 1000f).ToString("0.0").Replace(".0", string.Empty) + "Kbps")); formatter = Replace(formatter, "samplerate", sampleRate < 1 ? null : ((sampleRate / 1000f).ToString("0.0").Replace(".0", string.Empty) + "kHz")); @@ -413,6 +411,25 @@ public class FfmpegBuilderSetTrackTitles: FfmpegBuilderNode return input; } } + + /// + /// Gets the channel string + /// + /// the number of channels + /// the channels string + private static string GetChannelString(float channels) + { + if (Math.Abs(channels - 1) < 0.05f) + return "Mono"; + if(Math.Abs(channels - 2) < 0.05f) + return "Stereo"; + if (Math.Abs(channels - 6) < 0.05f) + return "5.1"; + if (Math.Abs(channels - 8) < 0.05f) + return "7.1"; + return channels > 0 ? channels.ToString("0.0") : null; + } + /// /// Gets the commercial name for a codec. /// diff --git a/VideoNodes/Tests/FfmpegBuilderTests/FFmpegBuilder_SetTrackTitlesTests.cs b/VideoNodes/Tests/FfmpegBuilderTests/FFmpegBuilder_SetTrackTitlesTests.cs index 563e6eef..b72619ea 100644 --- a/VideoNodes/Tests/FfmpegBuilderTests/FFmpegBuilder_SetTrackTitlesTests.cs +++ b/VideoNodes/Tests/FfmpegBuilderTests/FFmpegBuilder_SetTrackTitlesTests.cs @@ -206,6 +206,132 @@ public class FFmpegBuilder_SetTrackTitlesTests : VideoTestBase Assert.AreEqual("Track: English / Stereo / AAC", result); } + + [TestMethod] + public void FormatTitle_5dot1Channel_Success() + { + // Arrange + string formatter = "Track: lang / channels / codec"; + string separator = " / "; + string language = "English"; + string codec = "AAC"; + bool isDefault = true; + float bitrate = 128_000; + float channels = 6.0f; // 5.1 + int sampleRate = 44_100; + bool isForced = false; + + // Act + string result = FfmpegBuilderSetTrackTitles.FormatTitle(formatter, separator, language, codec, isDefault, bitrate, channels, sampleRate, isForced); + + // Assert + Assert.AreEqual("Track: English / 5.1 / AAC", result); + } + + [TestMethod] + public void FormatTitle_5dot1Channel2_Success() + { + // Arrange + string formatter = "Track: lang / channels / codec"; + string separator = " / "; + string language = "English"; + string codec = "AAC"; + bool isDefault = true; + float bitrate = 128_000; + float channels = 5.1f; // 5.1 + int sampleRate = 44_100; + bool isForced = false; + + // Act + string result = FfmpegBuilderSetTrackTitles.FormatTitle(formatter, separator, language, codec, isDefault, bitrate, channels, sampleRate, isForced); + + // Assert + Assert.AreEqual("Track: English / 5.1 / AAC", result); + } + [TestMethod] + public void FormatTitle_7dot1Channel_Success() + { + // Arrange + string formatter = "Track: lang / channels / codec"; + string separator = " / "; + string language = "English"; + string codec = "AAC"; + bool isDefault = true; + float bitrate = 128_000; + float channels = 8.0f; // 7.1 + int sampleRate = 44_100; + bool isForced = false; + + // Act + string result = FfmpegBuilderSetTrackTitles.FormatTitle(formatter, separator, language, codec, isDefault, bitrate, channels, sampleRate, isForced); + + // Assert + Assert.AreEqual("Track: English / 7.1 / AAC", result); + } + + [TestMethod] + public void FormatTitle_7dot1Channel2_Success() + { + // Arrange + string formatter = "Track: lang / channels / codec"; + string separator = " / "; + string language = "English"; + string codec = "AAC"; + bool isDefault = true; + float bitrate = 128_000; + float channels = 7.1f; // 7.1 + int sampleRate = 44_100; + bool isForced = false; + + // Act + string result = FfmpegBuilderSetTrackTitles.FormatTitle(formatter, separator, language, codec, isDefault, bitrate, channels, sampleRate, isForced); + + // Assert + Assert.AreEqual("Track: English / 7.1 / AAC", result); + } + + [TestMethod] + public void FormatTitle_7dot0Channel_Success() + { + // Arrange + string formatter = "Track: lang / channels / codec"; + string separator = " / "; + string language = "English"; + string codec = "AAC"; + bool isDefault = true; + float bitrate = 128_000; + float channels = 7.0f; + int sampleRate = 44_100; + bool isForced = false; + + // Act + string result = FfmpegBuilderSetTrackTitles.FormatTitle(formatter, separator, language, codec, isDefault, bitrate, channels, sampleRate, isForced); + + // Assert + Assert.AreEqual("Track: English / 7.0 / AAC", result); + } + + [TestMethod] + public void FormatTitle_5dot0Channel_Success() + { + // Arrange + string formatter = "Track: lang / channels / codec"; + string separator = " / "; + string language = "English"; + string codec = "AAC"; + bool isDefault = true; + float bitrate = 128_000; + float channels = 5.0f; + int sampleRate = 44_100; + bool isForced = false; + + // Act + string result = FfmpegBuilderSetTrackTitles.FormatTitle(formatter, separator, language, codec, isDefault, bitrate, channels, sampleRate, isForced); + + // Assert + Assert.AreEqual("Track: English / 5.0 / AAC", result); + } + [TestMethod] public void FormatTitle_ZeroBitrateAndSampleRate_Success() {