Merge pull request #10049 from Shadowghost/fix-format-normalizer

Fix format normalizer for multiple input formats
This commit is contained in:
Bond-009 2023-07-29 14:16:04 +02:00 committed by GitHub
commit 2d14b065a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 38 additions and 17 deletions

View File

@ -1,5 +1,4 @@
#nullable disable #nullable disable
#pragma warning disable CS1591
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -20,6 +19,9 @@ using Microsoft.Extensions.Logging;
namespace MediaBrowser.MediaEncoding.Probing namespace MediaBrowser.MediaEncoding.Probing
{ {
/// <summary>
/// Class responsible for normalizing FFprobe output.
/// </summary>
public class ProbeResultNormalizer public class ProbeResultNormalizer
{ {
// When extracting subtitles, the maximum length to consider (to avoid invalid filenames) // When extracting subtitles, the maximum length to consider (to avoid invalid filenames)
@ -36,6 +38,11 @@ namespace MediaBrowser.MediaEncoding.Probing
private string[] _splitWhiteList; private string[] _splitWhiteList;
/// <summary>
/// Initializes a new instance of the <see cref="ProbeResultNormalizer"/> class.
/// </summary>
/// <param name="logger">The <see cref="ILogger{ProbeResultNormalizer}"/> for use with the <see cref="ProbeResultNormalizer"/> instance.</param>
/// <param name="localization">The <see cref="ILocalizationManager"/> for use with the <see cref="ProbeResultNormalizer"/> instance.</param>
public ProbeResultNormalizer(ILogger logger, ILocalizationManager localization) public ProbeResultNormalizer(ILogger logger, ILocalizationManager localization)
{ {
_logger = logger; _logger = logger;
@ -73,6 +80,15 @@ namespace MediaBrowser.MediaEncoding.Probing
"Smith/Kotzen", "Smith/Kotzen",
}; };
/// <summary>
/// Transforms a FFprobe response into its <see cref="MediaInfo"/> equivalent.
/// </summary>
/// <param name="data">The <see cref="InternalMediaInfoResult"/>.</param>
/// <param name="videoType">The <see cref="VideoType"/>.</param>
/// <param name="isAudio">A boolean indicating whether the media is audio.</param>
/// <param name="path">Path to media file.</param>
/// <param name="protocol">Path media protocol.</param>
/// <returns>The <see cref="MediaInfo"/>.</returns>
public MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType? videoType, bool isAudio, string path, MediaProtocol protocol) public MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType? videoType, bool isAudio, string path, MediaProtocol protocol)
{ {
var info = new MediaInfo var info = new MediaInfo
@ -252,25 +268,30 @@ namespace MediaBrowser.MediaEncoding.Probing
return null; return null;
} }
// Handle MPEG-1 container // Input can be a list of multiple, comma-delimited formats - each of them needs to be checked
if (string.Equals(format, "mpegvideo", StringComparison.OrdinalIgnoreCase)) var splitFormat = format.Split(',');
for (var i = 0; i < splitFormat.Length; i++)
{ {
return "mpeg"; // Handle MPEG-1 container
if (string.Equals(splitFormat[i], "mpegvideo", StringComparison.OrdinalIgnoreCase))
{
splitFormat[i] = "mpeg";
} }
// Handle MPEG-2 container // Handle MPEG-2 container
if (string.Equals(format, "mpeg", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(splitFormat[i], "mpeg", StringComparison.OrdinalIgnoreCase))
{ {
return "ts"; splitFormat[i] = "ts";
} }
// Handle matroska container // Handle matroska container
if (string.Equals(format, "matroska", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(splitFormat[i], "matroska", StringComparison.OrdinalIgnoreCase))
{ {
return "mkv"; splitFormat[i] = "mkv";
}
} }
return format; return string.Join(',', splitFormat);
} }
private int? GetEstimatedAudioBitrate(string codec, int? channels) private int? GetEstimatedAudioBitrate(string codec, int? channels)