aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.MediaEncoding/Encoder
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.MediaEncoding/Encoder')
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs33
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs47
2 files changed, 54 insertions, 26 deletions
diff --git a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
index d3843796f..db119ce5c 100644
--- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
@@ -10,7 +10,7 @@ using Microsoft.Extensions.Logging;
namespace MediaBrowser.MediaEncoding.Encoder
{
- public class EncoderValidator
+ public partial class EncoderValidator
{
private static readonly string[] _requiredDecoders = new[]
{
@@ -52,6 +52,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
"libx264",
"libx265",
+ "libsvtav1",
"mpeg4",
"msmpeg4",
"libvpx",
@@ -69,12 +70,16 @@ namespace MediaBrowser.MediaEncoding.Encoder
"srt",
"h264_amf",
"hevc_amf",
+ "av1_amf",
"h264_qsv",
"hevc_qsv",
+ "av1_qsv",
"h264_nvenc",
"hevc_nvenc",
+ "av1_nvenc",
"h264_vaapi",
"hevc_vaapi",
+ "av1_vaapi",
"h264_v4l2m2m",
"h264_videotoolbox",
"hevc_videotoolbox"
@@ -160,6 +165,12 @@ namespace MediaBrowser.MediaEncoding.Encoder
public static Version? MaxVersion { get; } = null;
+ [GeneratedRegex(@"^ffmpeg version n?((?:[0-9]+\.?)+)")]
+ private static partial Regex FfmpegVersionRegex();
+
+ [GeneratedRegex(@"((?<name>lib\w+)\s+(?<major>[0-9]+)\.\s*(?<minor>[0-9]+))", RegexOptions.Multiline)]
+ private static partial Regex LibraryRegex();
+
public bool ValidateVersion()
{
string output;
@@ -278,7 +289,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
internal Version? GetFFmpegVersionInternal(string output)
{
// For pre-built binaries the FFmpeg version should be mentioned at the very start of the output
- var match = Regex.Match(output, @"^ffmpeg version n?((?:[0-9]+\.?)+)");
+ var match = FfmpegVersionRegex().Match(output);
if (match.Success)
{
@@ -326,10 +337,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
var map = new Dictionary<string, Version>();
- foreach (Match match in Regex.Matches(
- output,
- @"((?<name>lib\w+)\s+(?<major>[0-9]+)\.\s*(?<minor>[0-9]+))",
- RegexOptions.Multiline))
+ foreach (Match match in LibraryRegex().Matches(output))
{
var version = new Version(
int.Parse(match.Groups["major"].ValueSpan, CultureInfo.InvariantCulture),
@@ -545,7 +553,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
private string GetProcessOutput(string path, string arguments, bool readStdErr, string? testKey)
{
- using (var process = new Process()
+ var redirectStandardIn = !string.IsNullOrEmpty(testKey);
+ using (var process = new Process
{
StartInfo = new ProcessStartInfo(path, arguments)
{
@@ -553,7 +562,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false,
- RedirectStandardInput = !string.IsNullOrEmpty(testKey),
+ RedirectStandardInput = redirectStandardIn,
RedirectStandardOutput = true,
RedirectStandardError = true
}
@@ -563,12 +572,14 @@ namespace MediaBrowser.MediaEncoding.Encoder
process.Start();
- if (!string.IsNullOrEmpty(testKey))
+ if (redirectStandardIn)
{
- process.StandardInput.Write(testKey);
+ using var writer = process.StandardInput;
+ writer.Write(testKey);
}
- return readStdErr ? process.StandardError.ReadToEnd() : process.StandardOutput.ReadToEnd();
+ using var reader = readStdErr ? process.StandardError : process.StandardOutput;
+ return reader.ReadToEnd();
}
}
}
diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
index d2112e5dc..90ef93720 100644
--- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
@@ -36,7 +36,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
/// <summary>
/// Class MediaEncoder.
/// </summary>
- public class MediaEncoder : IMediaEncoder, IDisposable
+ public partial class MediaEncoder : IMediaEncoder, IDisposable
{
/// <summary>
/// The default SDR image extraction timeout in milliseconds.
@@ -57,7 +57,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
private readonly IServerConfigurationManager _serverConfig;
private readonly string _startupOptionFFmpegPath;
- private readonly SemaphoreSlim _thumbnailResourcePool = new SemaphoreSlim(2, 2);
+ private readonly SemaphoreSlim _thumbnailResourcePool;
private readonly object _runningProcessesLock = new object();
private readonly List<ProcessWrapper> _runningProcesses = new List<ProcessWrapper>();
@@ -76,12 +76,10 @@ namespace MediaBrowser.MediaEncoding.Encoder
private bool _isVaapiDeviceAmd = false;
private bool _isVaapiDeviceInteliHD = false;
private bool _isVaapiDeviceInteli965 = false;
- private bool _isVaapiDeviceSupportVulkanFmtModifier = false;
+ private bool _isVaapiDeviceSupportVulkanDrmInterop = false;
- private static string[] _vulkanFmtModifierExts =
+ private static string[] _vulkanExternalMemoryDmaBufExts =
{
- "VK_KHR_sampler_ycbcr_conversion",
- "VK_EXT_image_drm_format_modifier",
"VK_KHR_external_memory_fd",
"VK_EXT_external_memory_dma_buf",
"VK_KHR_external_semaphore_fd",
@@ -113,6 +111,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
_jsonSerializerOptions = new JsonSerializerOptions(JsonDefaults.Options);
_jsonSerializerOptions.Converters.Add(new JsonBoolStringConverter());
+
+ var semaphoreCount = 2 * Environment.ProcessorCount;
+ _thumbnailResourcePool = new SemaphoreSlim(semaphoreCount, semaphoreCount);
}
/// <inheritdoc />
@@ -137,7 +138,10 @@ namespace MediaBrowser.MediaEncoding.Encoder
public bool IsVaapiDeviceInteli965 => _isVaapiDeviceInteli965;
/// <inheritdoc />
- public bool IsVaapiDeviceSupportVulkanFmtModifier => _isVaapiDeviceSupportVulkanFmtModifier;
+ public bool IsVaapiDeviceSupportVulkanDrmInterop => _isVaapiDeviceSupportVulkanDrmInterop;
+
+ [GeneratedRegex(@"[^\/\\]+?(\.[^\/\\\n.]+)?$")]
+ private static partial Regex FfprobePathRegex();
/// <summary>
/// Run at startup or if the user removes a Custom path from transcode page.
@@ -173,7 +177,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
if (_ffmpegPath is not null)
{
// Determine a probe path from the mpeg path
- _ffprobePath = Regex.Replace(_ffmpegPath, @"[^\/\\]+?(\.[^\/\\\n.]+)?$", @"ffprobe$1");
+ _ffprobePath = FfprobePathRegex().Replace(_ffmpegPath, @"ffprobe$1");
// Interrogate to understand what coders are supported
var validator = new EncoderValidator(_logger, _ffmpegPath);
@@ -198,7 +202,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
_isVaapiDeviceAmd = validator.CheckVaapiDeviceByDriverName("Mesa Gallium driver", options.VaapiDevice);
_isVaapiDeviceInteliHD = validator.CheckVaapiDeviceByDriverName("Intel iHD driver", options.VaapiDevice);
_isVaapiDeviceInteli965 = validator.CheckVaapiDeviceByDriverName("Intel i965 driver", options.VaapiDevice);
- _isVaapiDeviceSupportVulkanFmtModifier = validator.CheckVulkanDrmDeviceByExtensionName(options.VaapiDevice, _vulkanFmtModifierExts);
+ _isVaapiDeviceSupportVulkanDrmInterop = validator.CheckVulkanDrmDeviceByExtensionName(options.VaapiDevice, _vulkanExternalMemoryDmaBufExts);
if (_isVaapiDeviceAmd)
{
@@ -213,9 +217,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
_logger.LogInformation("VAAPI device {RenderNodePath} is Intel GPU (i965)", options.VaapiDevice);
}
- if (_isVaapiDeviceSupportVulkanFmtModifier)
+ if (_isVaapiDeviceSupportVulkanDrmInterop)
{
- _logger.LogInformation("VAAPI device {RenderNodePath} supports Vulkan DRM format modifier", options.VaapiDevice);
+ _logger.LogInformation("VAAPI device {RenderNodePath} supports Vulkan DRM interop", options.VaapiDevice);
}
}
}
@@ -413,8 +417,10 @@ namespace MediaBrowser.MediaEncoding.Encoder
public Task<MediaInfo> GetMediaInfo(MediaInfoRequest request, CancellationToken cancellationToken)
{
var extractChapters = request.MediaType == DlnaProfileType.Video && request.ExtractChapters;
- string analyzeDuration = string.Empty;
- string ffmpegAnalyzeDuration = _config.GetFFmpegAnalyzeDuration() ?? string.Empty;
+ var analyzeDuration = string.Empty;
+ var ffmpegAnalyzeDuration = _config.GetFFmpegAnalyzeDuration() ?? string.Empty;
+ var ffmpegProbeSize = _config.GetFFmpegProbeSize() ?? string.Empty;
+ var extraArgs = string.Empty;
if (request.MediaSource.AnalyzeDurationMs > 0)
{
@@ -425,12 +431,22 @@ namespace MediaBrowser.MediaEncoding.Encoder
analyzeDuration = "-analyzeduration " + ffmpegAnalyzeDuration;
}
+ if (!string.IsNullOrEmpty(analyzeDuration))
+ {
+ extraArgs = analyzeDuration;
+ }
+
+ if (!string.IsNullOrEmpty(ffmpegProbeSize))
+ {
+ extraArgs += " -probesize " + ffmpegProbeSize;
+ }
+
return GetMediaInfoInternal(
GetInputArgument(request.MediaSource.Path, request.MediaSource),
request.MediaSource.Path,
request.MediaSource.Protocol,
extractChapters,
- analyzeDuration,
+ extraArgs,
request.MediaType == DlnaProfileType.Audio,
request.MediaSource.VideoType,
cancellationToken);
@@ -507,7 +523,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
using (var processWrapper = new ProcessWrapper(process, this))
{
StartProcess(processWrapper);
- await process.StandardOutput.BaseStream.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false);
+ using var reader = process.StandardOutput;
+ await reader.BaseStream.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false);
memoryStream.Seek(0, SeekOrigin.Begin);
InternalMediaInfoResult result;
try