maintain cuda pixel format throughout nvidia pipeline (#2042)
This commit is contained in:
@@ -1,14 +1,27 @@
|
||||
namespace ErsatzTV.FFmpeg.Decoder.Cuvid;
|
||||
using ErsatzTV.FFmpeg.Format;
|
||||
|
||||
namespace ErsatzTV.FFmpeg.Decoder.Cuvid;
|
||||
|
||||
public class DecoderImplicitCuda : DecoderBase
|
||||
{
|
||||
protected override FrameDataLocation OutputFrameDataLocation => FrameDataLocation.Hardware;
|
||||
public override string Name => string.Empty;
|
||||
|
||||
public override string Name => "implicit_cuda";
|
||||
|
||||
public override string[] InputOptions(InputFile inputFile) =>
|
||||
new[]
|
||||
{
|
||||
"-hwaccel_output_format",
|
||||
"cuda"
|
||||
};
|
||||
[
|
||||
"-hwaccel_output_format",
|
||||
"cuda"
|
||||
];
|
||||
|
||||
public override FrameState NextState(FrameState currentState)
|
||||
{
|
||||
FrameState nextState = base.NextState(currentState);
|
||||
|
||||
return currentState.PixelFormat.Match(
|
||||
pixelFormat => pixelFormat.BitDepth == 8
|
||||
? nextState with { PixelFormat = new PixelFormatNv12(pixelFormat.Name) }
|
||||
: nextState with { PixelFormat = new PixelFormatCuda(pixelFormat.Name, 10) },
|
||||
() => nextState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,15 @@ public class ColorspaceFilter : BaseFilter
|
||||
}
|
||||
}
|
||||
|
||||
// cuda is not a target software format
|
||||
if (pixelFormat is PixelFormatCuda cuda)
|
||||
{
|
||||
foreach (IPixelFormat pf in AvailablePixelFormats.ForPixelFormat(cuda.Name, null))
|
||||
{
|
||||
name = pf.FFmpegName;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
hwdownload = $"hwdownload,format={name},";
|
||||
|
||||
@@ -31,6 +31,14 @@ public class CropFilter : BaseFilter
|
||||
}
|
||||
}
|
||||
|
||||
if (pixelFormat is PixelFormatCuda)
|
||||
{
|
||||
foreach (IPixelFormat pf in AvailablePixelFormats.ForPixelFormat(pixelFormat.Name, null))
|
||||
{
|
||||
return $"hwdownload,format={pf.FFmpegName},{crop}";
|
||||
}
|
||||
}
|
||||
|
||||
return $"hwdownload,format={pixelFormat.FFmpegName},{crop}";
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,20 @@ public class CudaHardwareDownloadFilter : BaseFilter
|
||||
var hwdownload = "hwdownload";
|
||||
foreach (IPixelFormat pixelFormat in _maybeCurrentPixelFormat)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(pixelFormat.FFmpegName))
|
||||
IPixelFormat currentPixelFormat = pixelFormat;
|
||||
if (pixelFormat is PixelFormatCuda cuda)
|
||||
{
|
||||
hwdownload += $",format={pixelFormat.FFmpegName}";
|
||||
foreach (IPixelFormat pf in AvailablePixelFormats.ForPixelFormat(cuda.Name, null))
|
||||
{
|
||||
currentPixelFormat = pf;
|
||||
}
|
||||
}
|
||||
|
||||
if (pixelFormat is PixelFormatNv12 nv12)
|
||||
if (!string.IsNullOrWhiteSpace(currentPixelFormat.FFmpegName))
|
||||
{
|
||||
hwdownload += $",format={currentPixelFormat.FFmpegName}";
|
||||
|
||||
if (currentPixelFormat is PixelFormatNv12 nv12)
|
||||
{
|
||||
if (_maybeTargetPixelFormat.IsNone)
|
||||
{
|
||||
|
||||
@@ -26,6 +26,14 @@ public class HardwareDownloadFilter : BaseFilter
|
||||
}
|
||||
}
|
||||
|
||||
if (pixelFormat is PixelFormatCuda)
|
||||
{
|
||||
foreach (IPixelFormat pf in AvailablePixelFormats.ForPixelFormat(pixelFormat.Name, null))
|
||||
{
|
||||
return $"hwdownload,format={pf.FFmpegName}";
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(pixelFormat.FFmpegName))
|
||||
{
|
||||
hwdownload = $"hwdownload,format={pixelFormat.FFmpegName}";
|
||||
|
||||
@@ -31,6 +31,14 @@ public class PadFilter : BaseFilter
|
||||
}
|
||||
}
|
||||
|
||||
if (pixelFormat is PixelFormatCuda)
|
||||
{
|
||||
foreach (IPixelFormat pf in AvailablePixelFormats.ForPixelFormat(pixelFormat.Name, null))
|
||||
{
|
||||
return $"hwdownload,format={pf.FFmpegName},{pad}";
|
||||
}
|
||||
}
|
||||
|
||||
return $"hwdownload,format={pixelFormat.FFmpegName},{pad}";
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace ErsatzTV.FFmpeg.Format;
|
||||
|
||||
public class PixelFormatCuda(string name, int bitDepth = 8) : IPixelFormat
|
||||
{
|
||||
public string Name { get; } = name;
|
||||
|
||||
public string FFmpegName => "cuda";
|
||||
|
||||
public int BitDepth { get; } = bitDepth;
|
||||
}
|
||||
@@ -1,16 +1,10 @@
|
||||
namespace ErsatzTV.FFmpeg.Format;
|
||||
|
||||
public class PixelFormatVaapi : IPixelFormat
|
||||
public class PixelFormatVaapi(string name, int bitDepth = 8) : IPixelFormat
|
||||
{
|
||||
public PixelFormatVaapi(string name, int bitDepth = 8)
|
||||
{
|
||||
Name = name;
|
||||
BitDepth = bitDepth;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
public string Name { get; } = name;
|
||||
|
||||
public string FFmpegName => "vaapi";
|
||||
|
||||
public int BitDepth { get; }
|
||||
public int BitDepth { get; } = bitDepth;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class TranscodingTests
|
||||
// // // //
|
||||
// new("mpeg2video", "yuv420p"),
|
||||
// //
|
||||
new InputFormat("libx265", "yuv420p"),
|
||||
//new InputFormat("libx265", "yuv420p"),
|
||||
new InputFormat("libx265", "yuv420p10le")
|
||||
//
|
||||
// new("mpeg4", "yuv420p"),
|
||||
@@ -197,8 +197,8 @@ public class TranscodingTests
|
||||
|
||||
public static HardwareAccelerationKind[] TestAccelerations =
|
||||
[
|
||||
HardwareAccelerationKind.None,
|
||||
//HardwareAccelerationKind.Nvenc,
|
||||
//HardwareAccelerationKind.None,
|
||||
HardwareAccelerationKind.Nvenc,
|
||||
//HardwareAccelerationKind.Vaapi
|
||||
//HardwareAccelerationKind.Qsv,
|
||||
// HardwareAccelerationKind.VideoToolbox,
|
||||
|
||||
Reference in New Issue
Block a user