mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-26 18:54:48 +03:00
Merge branch 'jellyfin:master' into master
This commit is contained in:
@@ -102,7 +102,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
"tonemap_vaapi",
|
||||
"procamp_vaapi",
|
||||
"overlay_vaapi",
|
||||
"hwupload_vaapi"
|
||||
"hwupload_vaapi",
|
||||
// vulkan
|
||||
"libplacebo",
|
||||
"scale_vulkan",
|
||||
"overlay_vulkan"
|
||||
};
|
||||
|
||||
private static readonly IReadOnlyDictionary<int, string[]> _filterOptionsDict = new Dictionary<int, string[]>
|
||||
@@ -111,7 +115,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
{ 1, new string[] { "tonemap_cuda", "GPU accelerated HDR to SDR tonemapping" } },
|
||||
{ 2, new string[] { "tonemap_opencl", "bt2390" } },
|
||||
{ 3, new string[] { "overlay_opencl", "Action to take when encountering EOF from secondary input" } },
|
||||
{ 4, new string[] { "overlay_vaapi", "Action to take when encountering EOF from secondary input" } }
|
||||
{ 4, new string[] { "overlay_vaapi", "Action to take when encountering EOF from secondary input" } },
|
||||
{ 5, new string[] { "overlay_vulkan", "Action to take when encountering EOF from secondary input" } }
|
||||
};
|
||||
|
||||
// These are the library versions that corresponds to our minimum ffmpeg version 4.x according to the version table below
|
||||
@@ -153,7 +158,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
string output;
|
||||
try
|
||||
{
|
||||
output = GetProcessOutput(_encoderPath, "-version", false);
|
||||
output = GetProcessOutput(_encoderPath, "-version", false, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -234,7 +239,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
string output;
|
||||
try
|
||||
{
|
||||
output = GetProcessOutput(_encoderPath, "-version", false);
|
||||
output = GetProcessOutput(_encoderPath, "-version", false, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -341,7 +346,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
|
||||
try
|
||||
{
|
||||
var output = GetProcessOutput(_encoderPath, "-v verbose -hide_banner -init_hw_device vaapi=va:" + renderNodePath, true);
|
||||
var output = GetProcessOutput(_encoderPath, "-v verbose -hide_banner -init_hw_device vaapi=va:" + renderNodePath, true, null);
|
||||
return output.Contains(driverName, StringComparison.Ordinal);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -351,12 +356,45 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckVulkanDrmDeviceByExtensionName(string renderNodePath, string[] vulkanExtensions)
|
||||
{
|
||||
if (!OperatingSystem.IsLinux())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(renderNodePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var command = "-v verbose -hide_banner -init_hw_device drm=dr:" + renderNodePath + " -init_hw_device vulkan=vk@dr";
|
||||
var output = GetProcessOutput(_encoderPath, command, true, null);
|
||||
foreach (string ext in vulkanExtensions)
|
||||
{
|
||||
if (!output.Contains(ext, StringComparison.Ordinal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error detecting the given drm render node path");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetHwaccelTypes()
|
||||
{
|
||||
string? output = null;
|
||||
try
|
||||
{
|
||||
output = GetProcessOutput(_encoderPath, "-hwaccels", false);
|
||||
output = GetProcessOutput(_encoderPath, "-hwaccels", false, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -384,7 +422,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
string output;
|
||||
try
|
||||
{
|
||||
output = GetProcessOutput(_encoderPath, "-h filter=" + filter, false);
|
||||
output = GetProcessOutput(_encoderPath, "-h filter=" + filter, false, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -402,13 +440,34 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CheckSupportedRuntimeKey(string keyDesc)
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyDesc))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string output;
|
||||
try
|
||||
{
|
||||
output = GetProcessOutput(_encoderPath, "-hide_banner -f lavfi -i nullsrc=s=1x1:d=500 -f null -", true, "?");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error checking supported runtime key");
|
||||
return false;
|
||||
}
|
||||
|
||||
return output.Contains(keyDesc, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetCodecs(Codec codec)
|
||||
{
|
||||
string codecstr = codec == Codec.Encoder ? "encoders" : "decoders";
|
||||
string output;
|
||||
try
|
||||
{
|
||||
output = GetProcessOutput(_encoderPath, "-" + codecstr, false);
|
||||
output = GetProcessOutput(_encoderPath, "-" + codecstr, false, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -439,7 +498,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
string output;
|
||||
try
|
||||
{
|
||||
output = GetProcessOutput(_encoderPath, "-filters", false);
|
||||
output = GetProcessOutput(_encoderPath, "-filters", false, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -477,7 +536,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
return dict;
|
||||
}
|
||||
|
||||
private string GetProcessOutput(string path, string arguments, bool readStdErr)
|
||||
private string GetProcessOutput(string path, string arguments, bool readStdErr, string? testKey)
|
||||
{
|
||||
using (var process = new Process()
|
||||
{
|
||||
@@ -487,6 +546,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
UseShellExecute = false,
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
ErrorDialog = false,
|
||||
RedirectStandardInput = !string.IsNullOrEmpty(testKey),
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true
|
||||
}
|
||||
@@ -496,6 +556,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
|
||||
process.Start();
|
||||
|
||||
if (!string.IsNullOrEmpty(testKey))
|
||||
{
|
||||
process.StandardInput.Write(testKey);
|
||||
}
|
||||
|
||||
return readStdErr ? process.StandardError.ReadToEnd() : process.StandardOutput.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,9 +68,21 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
private List<string> _filters = new List<string>();
|
||||
private IDictionary<int, bool> _filtersWithOption = new Dictionary<int, bool>();
|
||||
|
||||
private bool _isPkeyPauseSupported = false;
|
||||
|
||||
private bool _isVaapiDeviceAmd = false;
|
||||
private bool _isVaapiDeviceInteliHD = false;
|
||||
private bool _isVaapiDeviceInteli965 = false;
|
||||
private bool _isVaapiDeviceSupportVulkanFmtModifier = false;
|
||||
|
||||
private static string[] _vulkanFmtModifierExts = {
|
||||
"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",
|
||||
"VK_EXT_external_memory_host"
|
||||
};
|
||||
|
||||
private Version _ffmpegVersion = null;
|
||||
private string _ffmpegPath = string.Empty;
|
||||
@@ -103,12 +115,16 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
|
||||
public Version EncoderVersion => _ffmpegVersion;
|
||||
|
||||
public bool IsPkeyPauseSupported => _isPkeyPauseSupported;
|
||||
|
||||
public bool IsVaapiDeviceAmd => _isVaapiDeviceAmd;
|
||||
|
||||
public bool IsVaapiDeviceInteliHD => _isVaapiDeviceInteliHD;
|
||||
|
||||
public bool IsVaapiDeviceInteli965 => _isVaapiDeviceInteli965;
|
||||
|
||||
public bool IsVaapiDeviceSupportVulkanFmtModifier => _isVaapiDeviceSupportVulkanFmtModifier;
|
||||
|
||||
/// <summary>
|
||||
/// Run at startup or if the user removes a Custom path from transcode page.
|
||||
/// Sets global variables FFmpegPath.
|
||||
@@ -157,6 +173,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
|
||||
_threads = EncodingHelper.GetNumberOfThreads(null, options, null);
|
||||
|
||||
_isPkeyPauseSupported = validator.CheckSupportedRuntimeKey("p pause transcoding");
|
||||
|
||||
// Check the Vaapi device vendor
|
||||
if (OperatingSystem.IsLinux()
|
||||
&& SupportsHwaccel("vaapi")
|
||||
@@ -166,6 +184,8 @@ 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);
|
||||
|
||||
if (_isVaapiDeviceAmd)
|
||||
{
|
||||
_logger.LogInformation("VAAPI device {RenderNodePath} is AMD GPU", options.VaapiDevice);
|
||||
@@ -178,6 +198,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
{
|
||||
_logger.LogInformation("VAAPI device {RenderNodePath} is Intel GPU (i965)", options.VaapiDevice);
|
||||
}
|
||||
|
||||
if (_isVaapiDeviceSupportVulkanFmtModifier)
|
||||
{
|
||||
_logger.LogInformation("VAAPI device {RenderNodePath} supports Vulkan DRM format modifier", options.VaapiDevice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,15 +404,15 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
string analyzeDuration = string.Empty;
|
||||
string ffmpegAnalyzeDuration = _config.GetFFmpegAnalyzeDuration() ?? string.Empty;
|
||||
|
||||
if (!string.IsNullOrEmpty(ffmpegAnalyzeDuration))
|
||||
{
|
||||
analyzeDuration = "-analyzeduration " + ffmpegAnalyzeDuration;
|
||||
}
|
||||
else if (request.MediaSource.AnalyzeDurationMs > 0)
|
||||
if (request.MediaSource.AnalyzeDurationMs > 0)
|
||||
{
|
||||
analyzeDuration = "-analyzeduration " +
|
||||
(request.MediaSource.AnalyzeDurationMs * 1000).ToString();
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ffmpegAnalyzeDuration))
|
||||
{
|
||||
analyzeDuration = "-analyzeduration " + ffmpegAnalyzeDuration;
|
||||
}
|
||||
|
||||
var forceEnableLogging = request.MediaSource.Protocol != MediaProtocol.File;
|
||||
|
||||
@@ -645,9 +670,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||
Video3DFormat.HalfSideBySide => "crop=iw/2:ih:0:0,scale=(iw*2):ih,setdar=dar=a,crop=min(iw\\,ih*dar):min(ih\\,iw/dar):(iw-min(iw\\,iw*sar))/2:(ih - min (ih\\,ih/sar))/2,setsar=sar=1",
|
||||
// fsbs crop width in half,set the display aspect,crop out any black bars we may have made
|
||||
Video3DFormat.FullSideBySide => "crop=iw/2:ih:0:0,setdar=dar=a,crop=min(iw\\,ih*dar):min(ih\\,iw/dar):(iw-min(iw\\,iw*sar))/2:(ih - min (ih\\,ih/sar))/2,setsar=sar=1",
|
||||
// htab crop heigh in half,scale to correct size, set the display aspect,crop out any black bars we may have made
|
||||
// htab crop height in half,scale to correct size, set the display aspect,crop out any black bars we may have made
|
||||
Video3DFormat.HalfTopAndBottom => "crop=iw:ih/2:0:0,scale=(iw*2):ih),setdar=dar=a,crop=min(iw\\,ih*dar):min(ih\\,iw/dar):(iw-min(iw\\,iw*sar))/2:(ih - min (ih\\,ih/sar))/2,setsar=sar=1",
|
||||
// ftab crop heigt in half, set the display aspect,crop out any black bars we may have made
|
||||
// ftab crop height in half, set the display aspect,crop out any black bars we may have made
|
||||
Video3DFormat.FullTopAndBottom => "crop=iw:ih/2:0:0,setdar=dar=a,crop=min(iw\\,ih*dar):min(ih\\,iw/dar):(iw-min(iw\\,iw*sar))/2:(ih - min (ih\\,ih/sar))/2,setsar=sar=1",
|
||||
_ => "scale=trunc(iw*sar):ih"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user