From 1e7aca8a3dae9c9b4a37d99a7575ce8cd966da85 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sat, 20 Jul 2024 17:32:09 +0200 Subject: [PATCH 1/4] Fix BDMV stream indexes Also fixes the subtitle codec for PGS subtitles from PGS to PGSSUB --- .../BdInfo/BdInfoExaminer.cs | 55 +++++++++---------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs index 5bae4fbd5a..0b17cffb5b 100644 --- a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs +++ b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs @@ -60,21 +60,20 @@ public class BdInfoExaminer : IBlurayExaminer var sortedStreams = playlist.SortedStreams; var mediaStreams = new List(sortedStreams.Count); - foreach (var stream in sortedStreams) + for (int i = 0; i < sortedStreams.Count; i++) { + var stream = sortedStreams[i]; switch (stream) { case TSVideoStream videoStream: - AddVideoStream(mediaStreams, videoStream); + AddVideoStream(mediaStreams, i, videoStream); break; case TSAudioStream audioStream: - AddAudioStream(mediaStreams, audioStream); + AddAudioStream(mediaStreams, i, audioStream); break; - case TSTextStream textStream: - AddSubtitleStream(mediaStreams, textStream); - break; - case TSGraphicsStream graphicStream: - AddSubtitleStream(mediaStreams, graphicStream); + case TSTextStream: + case TSGraphicsStream: + AddSubtitleStream(mediaStreams, i, stream); break; } } @@ -96,8 +95,9 @@ public class BdInfoExaminer : IBlurayExaminer /// Adds the video stream. /// /// The streams. + /// The stream index. /// The video stream. - private void AddVideoStream(List streams, TSVideoStream videoStream) + private void AddVideoStream(List streams, int index, TSVideoStream videoStream) { var mediaStream = new MediaStream { @@ -107,7 +107,7 @@ public class BdInfoExaminer : IBlurayExaminer Codec = videoStream.CodecShortName, IsInterlaced = videoStream.IsInterlaced, Type = MediaStreamType.Video, - Index = streams.Count + Index = index }; if (videoStream.FrameRateDenominator > 0) @@ -125,8 +125,9 @@ public class BdInfoExaminer : IBlurayExaminer /// Adds the audio stream. /// /// The streams. + /// The stream index. /// The audio stream. - private void AddAudioStream(List streams, TSAudioStream audioStream) + private void AddAudioStream(List streams, int index, TSAudioStream audioStream) { var stream = new MediaStream { @@ -135,7 +136,7 @@ public class BdInfoExaminer : IBlurayExaminer Channels = audioStream.ChannelCount, SampleRate = audioStream.SampleRate, Type = MediaStreamType.Audio, - Index = streams.Count + Index = index }; var bitrate = Convert.ToInt32(audioStream.BitRate); @@ -157,31 +158,25 @@ public class BdInfoExaminer : IBlurayExaminer /// Adds the subtitle stream. /// /// The streams. - /// The text stream. - private void AddSubtitleStream(List streams, TSTextStream textStream) + /// The stream index. + /// The stream. + private void AddSubtitleStream(List streams, int index, TSStream textStream) { streams.Add(new MediaStream { Language = textStream.LanguageCode, - Codec = textStream.CodecShortName, + Codec = NormalizeSubtitleCodec(textStream.StreamType), Type = MediaStreamType.Subtitle, - Index = streams.Count + Index = index }); } - /// - /// Adds the subtitle stream. - /// - /// The streams. - /// The text stream. - private void AddSubtitleStream(List streams, TSGraphicsStream textStream) - { - streams.Add(new MediaStream + private string NormalizeSubtitleCodec(TSStreamType codec) + => codec switch { - Language = textStream.LanguageCode, - Codec = textStream.CodecShortName, - Type = MediaStreamType.Subtitle, - Index = streams.Count - }); - } + TSStreamType.INTERACTIVE_GRAPHICS => "igs", + TSStreamType.PRESENTATION_GRAPHICS => "pgssub", + TSStreamType.SUBTITLE => "sub", + _ => throw new ArgumentOutOfRangeException(nameof(codec), $"Invalid stream type for subtitle: {codec}") + }; } From 406320cb9807f401764ef786058b33fb1484a9ee Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sat, 20 Jul 2024 19:50:14 +0200 Subject: [PATCH 2/4] Fix more codec names --- .../BdInfo/BdInfoExaminer.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs index 0b17cffb5b..e1a5d1d2bd 100644 --- a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs +++ b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using BDInfo; +using Jellyfin.Extensions; using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; using MediaBrowser.Model.MediaInfo; @@ -104,7 +106,7 @@ public class BdInfoExaminer : IBlurayExaminer BitRate = Convert.ToInt32(videoStream.BitRate), Width = videoStream.Width, Height = videoStream.Height, - Codec = videoStream.CodecShortName, + Codec = GetNormalizedCodec(videoStream), IsInterlaced = videoStream.IsInterlaced, Type = MediaStreamType.Video, Index = index @@ -131,9 +133,10 @@ public class BdInfoExaminer : IBlurayExaminer { var stream = new MediaStream { - Codec = audioStream.CodecShortName, + Codec = GetNormalizedCodec(audioStream), Language = audioStream.LanguageCode, - Channels = audioStream.ChannelCount, + ChannelLayout = string.Format(CultureInfo.InvariantCulture, "{0:D}.{1:D}", audioStream.ChannelCount, audioStream.LFE), + Channels = audioStream.ChannelCount + audioStream.LFE, SampleRate = audioStream.SampleRate, Type = MediaStreamType.Audio, Index = index @@ -146,11 +149,6 @@ public class BdInfoExaminer : IBlurayExaminer stream.BitRate = bitrate; } - if (audioStream.LFE > 0) - { - stream.Channels = audioStream.ChannelCount + 1; - } - streams.Add(stream); } @@ -159,24 +157,26 @@ public class BdInfoExaminer : IBlurayExaminer /// /// The streams. /// The stream index. - /// The stream. - private void AddSubtitleStream(List streams, int index, TSStream textStream) + /// The stream. + private void AddSubtitleStream(List streams, int index, TSStream stream) { streams.Add(new MediaStream { - Language = textStream.LanguageCode, - Codec = NormalizeSubtitleCodec(textStream.StreamType), + Language = stream.LanguageCode, + Codec = GetNormalizedCodec(stream), Type = MediaStreamType.Subtitle, Index = index }); } - private string NormalizeSubtitleCodec(TSStreamType codec) - => codec switch + private string GetNormalizedCodec(TSStream stream) + => stream.StreamType switch { - TSStreamType.INTERACTIVE_GRAPHICS => "igs", + TSStreamType.MPEG1_VIDEO => "mpeg1video", + TSStreamType.MPEG2_VIDEO => "mpeg2video", + TSStreamType.VC1_VIDEO => "vc1", + TSStreamType.AC3_PLUS_AUDIO | TSStreamType.AC3_PLUS_SECONDARY_AUDIO => "eac3", TSStreamType.PRESENTATION_GRAPHICS => "pgssub", - TSStreamType.SUBTITLE => "sub", - _ => throw new ArgumentOutOfRangeException(nameof(codec), $"Invalid stream type for subtitle: {codec}") + _ => stream.CodecShortName }; } From f308a01e5930625692932585a35703f8a9e5fa4c Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sat, 20 Jul 2024 20:22:51 +0200 Subject: [PATCH 3/4] Fix DTS codec name --- MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs index e1a5d1d2bd..d9e266e5ca 100644 --- a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs +++ b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs @@ -176,6 +176,7 @@ public class BdInfoExaminer : IBlurayExaminer TSStreamType.MPEG2_VIDEO => "mpeg2video", TSStreamType.VC1_VIDEO => "vc1", TSStreamType.AC3_PLUS_AUDIO | TSStreamType.AC3_PLUS_SECONDARY_AUDIO => "eac3", + TSStreamType.DTS_AUDIO | TSStreamType.DTS_HD_AUDIO | TSStreamType.DTS_HD_MASTER_AUDIO | TSStreamType.DTS_HD_MASTER_AUDIO => "dts", TSStreamType.PRESENTATION_GRAPHICS => "pgssub", _ => stream.CodecShortName }; From 99bba2971535e6c21f568e25cf5f8e3ba36be7d1 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sat, 20 Jul 2024 20:37:44 +0200 Subject: [PATCH 4/4] Fix switch expression --- MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs index d9e266e5ca..6ca994fb7e 100644 --- a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs +++ b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs @@ -175,8 +175,8 @@ public class BdInfoExaminer : IBlurayExaminer TSStreamType.MPEG1_VIDEO => "mpeg1video", TSStreamType.MPEG2_VIDEO => "mpeg2video", TSStreamType.VC1_VIDEO => "vc1", - TSStreamType.AC3_PLUS_AUDIO | TSStreamType.AC3_PLUS_SECONDARY_AUDIO => "eac3", - TSStreamType.DTS_AUDIO | TSStreamType.DTS_HD_AUDIO | TSStreamType.DTS_HD_MASTER_AUDIO | TSStreamType.DTS_HD_MASTER_AUDIO => "dts", + TSStreamType.AC3_PLUS_AUDIO or TSStreamType.AC3_PLUS_SECONDARY_AUDIO => "eac3", + TSStreamType.DTS_AUDIO or TSStreamType.DTS_HD_AUDIO or TSStreamType.DTS_HD_MASTER_AUDIO or TSStreamType.DTS_HD_SECONDARY_AUDIO => "dts", TSStreamType.PRESENTATION_GRAPHICS => "pgssub", _ => stream.CodecShortName };