aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.MediaEncoding
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.MediaEncoding')
-rw-r--r--MediaBrowser.MediaEncoding/BdInfo/BdInfoDirectoryInfo.cs83
-rw-r--r--MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs194
-rw-r--r--MediaBrowser.MediaEncoding/BdInfo/BdInfoFileInfo.cs41
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs79
-rw-r--r--MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj1
-rw-r--r--MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs26
6 files changed, 1 insertions, 423 deletions
diff --git a/MediaBrowser.MediaEncoding/BdInfo/BdInfoDirectoryInfo.cs b/MediaBrowser.MediaEncoding/BdInfo/BdInfoDirectoryInfo.cs
deleted file mode 100644
index 7e026b42e..000000000
--- a/MediaBrowser.MediaEncoding/BdInfo/BdInfoDirectoryInfo.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-#pragma warning disable CS1591
-
-using System;
-using System.Linq;
-using BDInfo.IO;
-using MediaBrowser.Model.IO;
-
-namespace MediaBrowser.MediaEncoding.BdInfo
-{
- public class BdInfoDirectoryInfo : IDirectoryInfo
- {
- private readonly IFileSystem _fileSystem;
-
- private readonly FileSystemMetadata _impl;
-
- public BdInfoDirectoryInfo(IFileSystem fileSystem, string path)
- {
- _fileSystem = fileSystem;
- _impl = _fileSystem.GetDirectoryInfo(path);
- }
-
- private BdInfoDirectoryInfo(IFileSystem fileSystem, FileSystemMetadata impl)
- {
- _fileSystem = fileSystem;
- _impl = impl;
- }
-
- public string Name => _impl.Name;
-
- public string FullName => _impl.FullName;
-
- public IDirectoryInfo? Parent
- {
- get
- {
- var parentFolder = System.IO.Path.GetDirectoryName(_impl.FullName);
- if (parentFolder is not null)
- {
- return new BdInfoDirectoryInfo(_fileSystem, parentFolder);
- }
-
- return null;
- }
- }
-
- public IDirectoryInfo[] GetDirectories()
- {
- return Array.ConvertAll(
- _fileSystem.GetDirectories(_impl.FullName).ToArray(),
- x => new BdInfoDirectoryInfo(_fileSystem, x));
- }
-
- public IFileInfo[] GetFiles()
- {
- return Array.ConvertAll(
- _fileSystem.GetFiles(_impl.FullName).ToArray(),
- x => new BdInfoFileInfo(x));
- }
-
- public IFileInfo[] GetFiles(string searchPattern)
- {
- return Array.ConvertAll(
- _fileSystem.GetFiles(_impl.FullName, new[] { searchPattern }, false, false).ToArray(),
- x => new BdInfoFileInfo(x));
- }
-
- public IFileInfo[] GetFiles(string searchPattern, System.IO.SearchOption searchOption)
- {
- return Array.ConvertAll(
- _fileSystem.GetFiles(
- _impl.FullName,
- new[] { searchPattern },
- false,
- (searchOption & System.IO.SearchOption.AllDirectories) == System.IO.SearchOption.AllDirectories).ToArray(),
- x => new BdInfoFileInfo(x));
- }
-
- public static IDirectoryInfo FromFileSystemPath(IFileSystem fs, string path)
- {
- return new BdInfoDirectoryInfo(fs, path);
- }
- }
-}
diff --git a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs b/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs
deleted file mode 100644
index 3e53cbf29..000000000
--- a/MediaBrowser.MediaEncoding/BdInfo/BdInfoExaminer.cs
+++ /dev/null
@@ -1,194 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using BDInfo;
-using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.MediaInfo;
-
-namespace MediaBrowser.MediaEncoding.BdInfo
-{
- /// <summary>
- /// Class BdInfoExaminer.
- /// </summary>
- public class BdInfoExaminer : IBlurayExaminer
- {
- private readonly IFileSystem _fileSystem;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="BdInfoExaminer" /> class.
- /// </summary>
- /// <param name="fileSystem">The filesystem.</param>
- public BdInfoExaminer(IFileSystem fileSystem)
- {
- _fileSystem = fileSystem;
- }
-
- /// <summary>
- /// Gets the disc info.
- /// </summary>
- /// <param name="path">The path.</param>
- /// <returns>BlurayDiscInfo.</returns>
- public BlurayDiscInfo GetDiscInfo(string path)
- {
- if (string.IsNullOrWhiteSpace(path))
- {
- throw new ArgumentNullException(nameof(path));
- }
-
- var bdrom = new BDROM(BdInfoDirectoryInfo.FromFileSystemPath(_fileSystem, path));
-
- bdrom.Scan();
-
- // Get the longest playlist
- var playlist = bdrom.PlaylistFiles.Values.OrderByDescending(p => p.TotalLength).FirstOrDefault(p => p.IsValid);
-
- var outputStream = new BlurayDiscInfo
- {
- MediaStreams = Array.Empty<MediaStream>()
- };
-
- if (playlist is null)
- {
- return outputStream;
- }
-
- outputStream.Chapters = playlist.Chapters.ToArray();
-
- outputStream.RunTimeTicks = TimeSpan.FromSeconds(playlist.TotalLength).Ticks;
-
- var mediaStreams = new List<MediaStream>();
-
- foreach (var stream in playlist.SortedStreams)
- {
- if (stream is TSVideoStream videoStream)
- {
- AddVideoStream(mediaStreams, videoStream);
- continue;
- }
-
- if (stream is TSAudioStream audioStream)
- {
- AddAudioStream(mediaStreams, audioStream);
- continue;
- }
-
- if (stream is TSTextStream textStream)
- {
- AddSubtitleStream(mediaStreams, textStream);
- continue;
- }
-
- if (stream is TSGraphicsStream graphicsStream)
- {
- AddSubtitleStream(mediaStreams, graphicsStream);
- }
- }
-
- outputStream.MediaStreams = mediaStreams.ToArray();
-
- outputStream.PlaylistName = playlist.Name;
-
- if (playlist.StreamClips is not null && playlist.StreamClips.Any())
- {
- // Get the files in the playlist
- outputStream.Files = playlist.StreamClips.Select(i => i.StreamFile.Name).ToArray();
- }
-
- return outputStream;
- }
-
- /// <summary>
- /// Adds the video stream.
- /// </summary>
- /// <param name="streams">The streams.</param>
- /// <param name="videoStream">The video stream.</param>
- private void AddVideoStream(List<MediaStream> streams, TSVideoStream videoStream)
- {
- var mediaStream = new MediaStream
- {
- BitRate = Convert.ToInt32(videoStream.BitRate),
- Width = videoStream.Width,
- Height = videoStream.Height,
- Codec = videoStream.CodecShortName,
- IsInterlaced = videoStream.IsInterlaced,
- Type = MediaStreamType.Video,
- Index = streams.Count
- };
-
- if (videoStream.FrameRateDenominator > 0)
- {
- float frameRateEnumerator = videoStream.FrameRateEnumerator;
- float frameRateDenominator = videoStream.FrameRateDenominator;
-
- mediaStream.AverageFrameRate = mediaStream.RealFrameRate = frameRateEnumerator / frameRateDenominator;
- }
-
- streams.Add(mediaStream);
- }
-
- /// <summary>
- /// Adds the audio stream.
- /// </summary>
- /// <param name="streams">The streams.</param>
- /// <param name="audioStream">The audio stream.</param>
- private void AddAudioStream(List<MediaStream> streams, TSAudioStream audioStream)
- {
- var stream = new MediaStream
- {
- Codec = audioStream.CodecShortName,
- Language = audioStream.LanguageCode,
- Channels = audioStream.ChannelCount,
- SampleRate = audioStream.SampleRate,
- Type = MediaStreamType.Audio,
- Index = streams.Count
- };
-
- var bitrate = Convert.ToInt32(audioStream.BitRate);
-
- if (bitrate > 0)
- {
- stream.BitRate = bitrate;
- }
-
- if (audioStream.LFE > 0)
- {
- stream.Channels = audioStream.ChannelCount + 1;
- }
-
- streams.Add(stream);
- }
-
- /// <summary>
- /// Adds the subtitle stream.
- /// </summary>
- /// <param name="streams">The streams.</param>
- /// <param name="textStream">The text stream.</param>
- private void AddSubtitleStream(List<MediaStream> streams, TSTextStream textStream)
- {
- streams.Add(new MediaStream
- {
- Language = textStream.LanguageCode,
- Codec = textStream.CodecShortName,
- Type = MediaStreamType.Subtitle,
- Index = streams.Count
- });
- }
-
- /// <summary>
- /// Adds the subtitle stream.
- /// </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,
- Codec = textStream.CodecShortName,
- Type = MediaStreamType.Subtitle,
- Index = streams.Count
- });
- }
- }
-}
diff --git a/MediaBrowser.MediaEncoding/BdInfo/BdInfoFileInfo.cs b/MediaBrowser.MediaEncoding/BdInfo/BdInfoFileInfo.cs
deleted file mode 100644
index d55688e3d..000000000
--- a/MediaBrowser.MediaEncoding/BdInfo/BdInfoFileInfo.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-#pragma warning disable CS1591
-
-using System.IO;
-using MediaBrowser.Model.IO;
-
-namespace MediaBrowser.MediaEncoding.BdInfo
-{
- public class BdInfoFileInfo : BDInfo.IO.IFileInfo
- {
- private FileSystemMetadata _impl;
-
- public BdInfoFileInfo(FileSystemMetadata impl)
- {
- _impl = impl;
- }
-
- public string Name => _impl.Name;
-
- public string FullName => _impl.FullName;
-
- public string Extension => _impl.Extension;
-
- public long Length => _impl.Length;
-
- public bool IsDir => _impl.IsDirectory;
-
- public Stream OpenRead()
- {
- return new FileStream(
- FullName,
- FileMode.Open,
- FileAccess.Read,
- FileShare.Read);
- }
-
- public StreamReader OpenText()
- {
- return new StreamReader(OpenRead());
- }
- }
-}
diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
index d95f894c5..d2240b5af 100644
--- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
@@ -862,85 +862,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
throw new NotImplementedException();
}
- /// <inheritdoc />
- public IEnumerable<string> GetPrimaryPlaylistVobFiles(string path, uint? titleNumber)
- {
- // min size 300 mb
- const long MinPlayableSize = 314572800;
-
- // Try to eliminate menus and intros by skipping all files at the front of the list that are less than the minimum size
- // Once we reach a file that is at least the minimum, return all subsequent ones
- var allVobs = _fileSystem.GetFiles(path, true)
- .Where(file => string.Equals(file.Extension, ".vob", StringComparison.OrdinalIgnoreCase))
- .OrderBy(i => i.FullName)
- .ToList();
-
- // If we didn't find any satisfying the min length, just take them all
- if (allVobs.Count == 0)
- {
- _logger.LogWarning("No vobs found in dvd structure.");
- return Enumerable.Empty<string>();
- }
-
- if (titleNumber.HasValue)
- {
- var prefix = string.Format(
- CultureInfo.InvariantCulture,
- titleNumber.Value >= 10 ? "VTS_{0}_" : "VTS_0{0}_",
- titleNumber.Value);
- var vobs = allVobs.Where(i => i.Name.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)).ToList();
-
- if (vobs.Count > 0)
- {
- var minSizeVobs = vobs
- .SkipWhile(f => f.Length < MinPlayableSize)
- .ToList();
-
- return minSizeVobs.Count == 0 ? vobs.Select(i => i.FullName) : minSizeVobs.Select(i => i.FullName);
- }
-
- _logger.LogWarning("Could not determine vob file list for {Path} using DvdLib. Will scan using file sizes.", path);
- }
-
- var files = allVobs
- .SkipWhile(f => f.Length < MinPlayableSize)
- .ToList();
-
- // If we didn't find any satisfying the min length, just take them all
- if (files.Count == 0)
- {
- _logger.LogWarning("Vob size filter resulted in zero matches. Taking all vobs.");
- files = allVobs;
- }
-
- // Assuming they're named "vts_05_01", take all files whose second part matches that of the first file
- if (files.Count > 0)
- {
- var parts = _fileSystem.GetFileNameWithoutExtension(files[0]).Split('_');
-
- if (parts.Length == 3)
- {
- var title = parts[1];
-
- files = files.TakeWhile(f =>
- {
- var fileParts = _fileSystem.GetFileNameWithoutExtension(f).Split('_');
-
- return fileParts.Length == 3 && string.Equals(title, fileParts[1], StringComparison.OrdinalIgnoreCase);
- }).ToList();
-
- // If this resulted in not getting any vobs, just take them all
- if (files.Count == 0)
- {
- _logger.LogWarning("Vob filename filter resulted in zero matches. Taking all vobs.");
- files = allVobs;
- }
- }
- }
-
- return files.Select(i => i.FullName);
- }
-
public bool CanExtractSubtitles(string codec)
{
// TODO is there ever a case when a subtitle can't be extracted??
diff --git a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj
index 1233fb110..93177298f 100644
--- a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj
+++ b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj
@@ -22,7 +22,6 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="BDInfo" Version="0.7.6.2" />
<PackageReference Include="libse" Version="3.6.10" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs
index 18e248a1b..04bdbdf59 100644
--- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs
+++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs
@@ -626,17 +626,6 @@ namespace MediaBrowser.MediaEncoding.Probing
}
/// <summary>
- /// Determines whether a stream code time base is double the frame rate.
- /// </summary>
- /// <param name="averageFrameRate">average frame rate.</param>
- /// <param name="codecTimeBase">codec time base string.</param>
- /// <returns>true if the codec time base is double the frame rate.</returns>
- internal static bool IsCodecTimeBaseDoubleTheFrameRate(float? averageFrameRate, string codecTimeBase)
- {
- return MathF.Abs(((averageFrameRate ?? 0) * (GetFrameRate(codecTimeBase) ?? 0)) - 0.5f) <= float.Epsilon;
- }
-
- /// <summary>
/// Converts ffprobe stream info to our MediaStream class.
/// </summary>
/// <param name="isAudio">if set to <c>true</c> [is info].</param>
@@ -748,22 +737,9 @@ namespace MediaBrowser.MediaEncoding.Probing
stream.AverageFrameRate = GetFrameRate(streamInfo.AverageFrameRate);
stream.RealFrameRate = GetFrameRate(streamInfo.RFrameRate);
- bool videoInterlaced = !string.IsNullOrWhiteSpace(streamInfo.FieldOrder)
+ stream.IsInterlaced = !string.IsNullOrWhiteSpace(streamInfo.FieldOrder)
&& !string.Equals(streamInfo.FieldOrder, "progressive", StringComparison.OrdinalIgnoreCase);
- // Some interlaced H.264 files in mp4 containers using MBAFF coding aren't flagged as being interlaced by FFprobe,
- // so for H.264 files we also calculate the frame rate from the codec time base and check if it is double the reported
- // frame rate to determine if the file is interlaced
-
- bool h264MbaffCoded = string.Equals(stream.Codec, "h264", StringComparison.OrdinalIgnoreCase)
- && string.IsNullOrWhiteSpace(streamInfo.FieldOrder)
- && IsCodecTimeBaseDoubleTheFrameRate(stream.AverageFrameRate, stream.CodecTimeBase);
-
- if (videoInterlaced || h264MbaffCoded)
- {
- stream.IsInterlaced = true;
- }
-
if (isAudio
|| string.Equals(stream.Codec, "mjpeg", StringComparison.OrdinalIgnoreCase)
|| string.Equals(stream.Codec, "gif", StringComparison.OrdinalIgnoreCase)