Re-enable the legacy NVIDIA CUVID decoder in full HWA pipeline (#7413)

This commit is contained in:
Nyanmisaka 2022-03-08 23:36:30 +08:00 committed by GitHub
parent c5ca29d2e2
commit 4f1efb3996
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2797,16 +2797,15 @@ namespace MediaBrowser.Controller.MediaEncoding
var isSwDecoder = string.IsNullOrEmpty(vidDecoder); var isSwDecoder = string.IsNullOrEmpty(vidDecoder);
var isSwEncoder = !vidEncoder.Contains("nvenc", StringComparison.OrdinalIgnoreCase); var isSwEncoder = !vidEncoder.Contains("nvenc", StringComparison.OrdinalIgnoreCase);
// legacy cuvid(resize/deint/sw) pipeline(copy-back) // legacy cuvid pipeline(copy-back)
if ((isSwDecoder && isSwEncoder) if ((isSwDecoder && isSwEncoder)
|| !IsCudaFullSupported() || !IsCudaFullSupported()
|| !options.EnableEnhancedNvdecDecoder
|| !_mediaEncoder.SupportsFilter("alphasrc")) || !_mediaEncoder.SupportsFilter("alphasrc"))
{ {
return GetSwVidFilterChain(state, options, vidEncoder); return GetSwVidFilterChain(state, options, vidEncoder);
} }
// prefered nvdec + cuda filters + nvenc pipeline // prefered nvdec/cuvid + cuda filters + nvenc pipeline
return GetNvidiaVidFiltersPrefered(state, options, vidDecoder, vidEncoder); return GetNvidiaVidFiltersPrefered(state, options, vidDecoder, vidEncoder);
} }
@ -2824,11 +2823,11 @@ namespace MediaBrowser.Controller.MediaEncoding
var reqMaxH = state.BaseRequest.MaxHeight; var reqMaxH = state.BaseRequest.MaxHeight;
var threeDFormat = state.MediaSource.Video3DFormat; var threeDFormat = state.MediaSource.Video3DFormat;
var isNvdecDecoder = vidDecoder.Contains("cuda", StringComparison.OrdinalIgnoreCase); var isNvDecoder = vidDecoder.Contains("cuda", StringComparison.OrdinalIgnoreCase);
var isNvencEncoder = vidEncoder.Contains("nvenc", StringComparison.OrdinalIgnoreCase); var isNvencEncoder = vidEncoder.Contains("nvenc", StringComparison.OrdinalIgnoreCase);
var isSwDecoder = string.IsNullOrEmpty(vidDecoder); var isSwDecoder = string.IsNullOrEmpty(vidDecoder);
var isSwEncoder = !isNvencEncoder; var isSwEncoder = !isNvencEncoder;
var isCuInCuOut = isNvdecDecoder && isNvencEncoder; var isCuInCuOut = isNvDecoder && isNvencEncoder;
var doubleRateDeint = options.DeinterlaceDoubleRate && (state.VideoStream?.AverageFrameRate ?? 60) <= 30; var doubleRateDeint = options.DeinterlaceDoubleRate && (state.VideoStream?.AverageFrameRate ?? 60) <= 30;
var doDeintH264 = state.DeInterlace("h264", true) || state.DeInterlace("avc", true); var doDeintH264 = state.DeInterlace("h264", true) || state.DeInterlace("avc", true);
@ -2871,7 +2870,7 @@ namespace MediaBrowser.Controller.MediaEncoding
} }
} }
if (isNvdecDecoder) if (isNvDecoder)
{ {
// INPUT cuda surface(vram) // INPUT cuda surface(vram)
// hw deint // hw deint
@ -2896,7 +2895,7 @@ namespace MediaBrowser.Controller.MediaEncoding
var memoryOutput = false; var memoryOutput = false;
var isUploadForOclTonemap = isSwDecoder && doCuTonemap; var isUploadForOclTonemap = isSwDecoder && doCuTonemap;
if ((isNvdecDecoder && isSwEncoder) || isUploadForOclTonemap) if ((isNvDecoder && isSwEncoder) || isUploadForOclTonemap)
{ {
memoryOutput = true; memoryOutput = true;
@ -4428,11 +4427,19 @@ namespace MediaBrowser.Controller.MediaEncoding
// Nvidia cuda // Nvidia cuda
if (string.Equals(options.HardwareAccelerationType, "nvenc", StringComparison.OrdinalIgnoreCase)) if (string.Equals(options.HardwareAccelerationType, "nvenc", StringComparison.OrdinalIgnoreCase))
{ {
if (options.EnableEnhancedNvdecDecoder && isCudaSupported && isCodecAvailable) if (isCudaSupported && isCodecAvailable)
{
if (options.EnableEnhancedNvdecDecoder)
{ {
// set -threads 1 to nvdec decoder explicitly since it doesn't implement threading support. // set -threads 1 to nvdec decoder explicitly since it doesn't implement threading support.
return " -hwaccel cuda" + (outputHwSurface ? " -hwaccel_output_format cuda" : string.Empty) + " -threads 1" + (isAv1 ? " -c:v av1" : string.Empty); return " -hwaccel cuda" + (outputHwSurface ? " -hwaccel_output_format cuda" : string.Empty) + " -threads 1" + (isAv1 ? " -c:v av1" : string.Empty);
} }
else
{
// cuvid decoder doesn't have threading issue.
return " -hwaccel cuda" + (outputHwSurface ? " -hwaccel_output_format cuda" : string.Empty);
}
}
} }
// Amd d3d11va // Amd d3d11va
@ -4541,9 +4548,7 @@ namespace MediaBrowser.Controller.MediaEncoding
return null; return null;
} }
var hwSurface = IsCudaFullSupported() var hwSurface = IsCudaFullSupported() && _mediaEncoder.SupportsFilter("alphasrc");
&& options.EnableEnhancedNvdecDecoder
&& _mediaEncoder.SupportsFilter("alphasrc");
var is8bitSwFormatsNvdec = string.Equals("yuv420p", videoStream.PixelFormat, StringComparison.OrdinalIgnoreCase); var is8bitSwFormatsNvdec = string.Equals("yuv420p", videoStream.PixelFormat, StringComparison.OrdinalIgnoreCase);
var is8_10bitSwFormatsNvdec = is8bitSwFormatsNvdec || string.Equals("yuv420p10le", videoStream.PixelFormat, StringComparison.OrdinalIgnoreCase); var is8_10bitSwFormatsNvdec = is8bitSwFormatsNvdec || string.Equals("yuv420p10le", videoStream.PixelFormat, StringComparison.OrdinalIgnoreCase);
// TODO: add more 8/10/12bit and 4:4:4 formats for Nvdec after finishing the ffcheck tool // TODO: add more 8/10/12bit and 4:4:4 formats for Nvdec after finishing the ffcheck tool