Merge pull request #12310 from Bond-009/fixbdmvstreamindex

Fix BDMV stream indexes
pull/12322/head
Bond-009 6 months ago committed by GitHub
commit 19dca018b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,7 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using BDInfo; using BDInfo;
using Jellyfin.Extensions;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.MediaInfo;
@ -60,21 +62,20 @@ public class BdInfoExaminer : IBlurayExaminer
var sortedStreams = playlist.SortedStreams; var sortedStreams = playlist.SortedStreams;
var mediaStreams = new List<MediaStream>(sortedStreams.Count); var mediaStreams = new List<MediaStream>(sortedStreams.Count);
foreach (var stream in sortedStreams) for (int i = 0; i < sortedStreams.Count; i++)
{ {
var stream = sortedStreams[i];
switch (stream) switch (stream)
{ {
case TSVideoStream videoStream: case TSVideoStream videoStream:
AddVideoStream(mediaStreams, videoStream); AddVideoStream(mediaStreams, i, videoStream);
break; break;
case TSAudioStream audioStream: case TSAudioStream audioStream:
AddAudioStream(mediaStreams, audioStream); AddAudioStream(mediaStreams, i, audioStream);
break; break;
case TSTextStream textStream: case TSTextStream:
AddSubtitleStream(mediaStreams, textStream); case TSGraphicsStream:
break; AddSubtitleStream(mediaStreams, i, stream);
case TSGraphicsStream graphicStream:
AddSubtitleStream(mediaStreams, graphicStream);
break; break;
} }
} }
@ -96,18 +97,19 @@ public class BdInfoExaminer : IBlurayExaminer
/// Adds the video stream. /// Adds the video stream.
/// </summary> /// </summary>
/// <param name="streams">The streams.</param> /// <param name="streams">The streams.</param>
/// <param name="index">The stream index.</param>
/// <param name="videoStream">The video stream.</param> /// <param name="videoStream">The video stream.</param>
private void AddVideoStream(List<MediaStream> streams, TSVideoStream videoStream) private void AddVideoStream(List<MediaStream> streams, int index, TSVideoStream videoStream)
{ {
var mediaStream = new MediaStream var mediaStream = new MediaStream
{ {
BitRate = Convert.ToInt32(videoStream.BitRate), BitRate = Convert.ToInt32(videoStream.BitRate),
Width = videoStream.Width, Width = videoStream.Width,
Height = videoStream.Height, Height = videoStream.Height,
Codec = videoStream.CodecShortName, Codec = GetNormalizedCodec(videoStream),
IsInterlaced = videoStream.IsInterlaced, IsInterlaced = videoStream.IsInterlaced,
Type = MediaStreamType.Video, Type = MediaStreamType.Video,
Index = streams.Count Index = index
}; };
if (videoStream.FrameRateDenominator > 0) if (videoStream.FrameRateDenominator > 0)
@ -125,17 +127,19 @@ public class BdInfoExaminer : IBlurayExaminer
/// Adds the audio stream. /// Adds the audio stream.
/// </summary> /// </summary>
/// <param name="streams">The streams.</param> /// <param name="streams">The streams.</param>
/// <param name="index">The stream index.</param>
/// <param name="audioStream">The audio stream.</param> /// <param name="audioStream">The audio stream.</param>
private void AddAudioStream(List<MediaStream> streams, TSAudioStream audioStream) private void AddAudioStream(List<MediaStream> streams, int index, TSAudioStream audioStream)
{ {
var stream = new MediaStream var stream = new MediaStream
{ {
Codec = audioStream.CodecShortName, Codec = GetNormalizedCodec(audioStream),
Language = audioStream.LanguageCode, 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, SampleRate = audioStream.SampleRate,
Type = MediaStreamType.Audio, Type = MediaStreamType.Audio,
Index = streams.Count Index = index
}; };
var bitrate = Convert.ToInt32(audioStream.BitRate); var bitrate = Convert.ToInt32(audioStream.BitRate);
@ -145,11 +149,6 @@ public class BdInfoExaminer : IBlurayExaminer
stream.BitRate = bitrate; stream.BitRate = bitrate;
} }
if (audioStream.LFE > 0)
{
stream.Channels = audioStream.ChannelCount + 1;
}
streams.Add(stream); streams.Add(stream);
} }
@ -157,31 +156,28 @@ public class BdInfoExaminer : IBlurayExaminer
/// Adds the subtitle stream. /// Adds the subtitle stream.
/// </summary> /// </summary>
/// <param name="streams">The streams.</param> /// <param name="streams">The streams.</param>
/// <param name="textStream">The text stream.</param> /// <param name="index">The stream index.</param>
private void AddSubtitleStream(List<MediaStream> streams, TSTextStream textStream) /// <param name="stream">The stream.</param>
private void AddSubtitleStream(List<MediaStream> streams, int index, TSStream stream)
{ {
streams.Add(new MediaStream streams.Add(new MediaStream
{ {
Language = textStream.LanguageCode, Language = stream.LanguageCode,
Codec = textStream.CodecShortName, Codec = GetNormalizedCodec(stream),
Type = MediaStreamType.Subtitle, Type = MediaStreamType.Subtitle,
Index = streams.Count Index = index
}); });
} }
/// <summary> private string GetNormalizedCodec(TSStream stream)
/// Adds the subtitle stream. => stream.StreamType switch
/// </summary>
/// <param name="streams">The streams.</param>
/// <param name="textStream">The text stream.</param>
private void AddSubtitleStream(List<MediaStream> streams, TSGraphicsStream textStream)
{
streams.Add(new MediaStream
{ {
Language = textStream.LanguageCode, TSStreamType.MPEG1_VIDEO => "mpeg1video",
Codec = textStream.CodecShortName, TSStreamType.MPEG2_VIDEO => "mpeg2video",
Type = MediaStreamType.Subtitle, TSStreamType.VC1_VIDEO => "vc1",
Index = streams.Count 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
};
} }

Loading…
Cancel
Save