Browse Source

maintain cuda pixel format throughout nvidia pipeline (#2042)

pull/2043/head
Jason Dove 7 days ago committed by GitHub
parent
commit
5b9601a57b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 23
      ErsatzTV.FFmpeg/Decoder/Cuvid/DecoderImplicitCuda.cs
  2. 9
      ErsatzTV.FFmpeg/Filter/ColorspaceFilter.cs
  3. 8
      ErsatzTV.FFmpeg/Filter/CropFilter.cs
  4. 15
      ErsatzTV.FFmpeg/Filter/Cuda/CudaHardwareDownloadFilter.cs
  5. 8
      ErsatzTV.FFmpeg/Filter/HardwareDownloadFilter.cs
  6. 8
      ErsatzTV.FFmpeg/Filter/PadFilter.cs
  7. 10
      ErsatzTV.FFmpeg/Format/PixelFormatCuda.cs
  8. 12
      ErsatzTV.FFmpeg/Format/PixelFormatVaapi.cs
  9. 6
      ErsatzTV.Scanner.Tests/Core/FFmpeg/TranscodingTests.cs

23
ErsatzTV.FFmpeg/Decoder/Cuvid/DecoderImplicitCuda.cs

@ -1,14 +1,27 @@ @@ -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"
};
];
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);
}
}

9
ErsatzTV.FFmpeg/Filter/ColorspaceFilter.cs

@ -42,6 +42,15 @@ public class ColorspaceFilter : BaseFilter @@ -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},";

8
ErsatzTV.FFmpeg/Filter/CropFilter.cs

@ -31,6 +31,14 @@ public class CropFilter : BaseFilter @@ -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}";
}

15
ErsatzTV.FFmpeg/Filter/Cuda/CudaHardwareDownloadFilter.cs

@ -22,11 +22,20 @@ public class CudaHardwareDownloadFilter : BaseFilter @@ -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)
{

8
ErsatzTV.FFmpeg/Filter/HardwareDownloadFilter.cs

@ -26,6 +26,14 @@ public class HardwareDownloadFilter : BaseFilter @@ -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}";

8
ErsatzTV.FFmpeg/Filter/PadFilter.cs

@ -31,6 +31,14 @@ public class PadFilter : BaseFilter @@ -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}";
}

10
ErsatzTV.FFmpeg/Format/PixelFormatCuda.cs

@ -0,0 +1,10 @@ @@ -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;
}

12
ErsatzTV.FFmpeg/Format/PixelFormatVaapi.cs

@ -1,16 +1,10 @@ @@ -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;
}

6
ErsatzTV.Scanner.Tests/Core/FFmpeg/TranscodingTests.cs

@ -158,7 +158,7 @@ public class TranscodingTests @@ -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 @@ -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,

Loading…
Cancel
Save