mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* properly scale image-based subtitles for nvidia and software * fix vaapi image subtitle scaling * fix qsv image subtitle scaling * update changelogpull/951/head
24 changed files with 233 additions and 45 deletions
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
using ErsatzTV.FFmpeg.Filter.Cuda; |
||||
using ErsatzTV.FFmpeg.Filter.Qsv; |
||||
|
||||
namespace ErsatzTV.FFmpeg.Filter; |
||||
|
||||
public static class AvailableSubtitleScaleFilters |
||||
{ |
||||
public static IPipelineFilterStep ForAcceleration( |
||||
HardwareAccelerationMode accelMode, |
||||
FrameState currentState, |
||||
FrameSize scaledSize, |
||||
FrameSize paddedSize, |
||||
int extraHardwareFrames) => |
||||
accelMode switch |
||||
{ |
||||
HardwareAccelerationMode.Nvenc => new SubtitleScaleNppFilter(currentState, scaledSize, paddedSize), |
||||
HardwareAccelerationMode.Qsv => new SubtitleScaleQsvFilter( |
||||
currentState, |
||||
scaledSize, |
||||
paddedSize, |
||||
extraHardwareFrames), |
||||
_ => new ScaleImageFilter(paddedSize) |
||||
}; |
||||
} |
||||
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
using ErsatzTV.FFmpeg.Format; |
||||
|
||||
namespace ErsatzTV.FFmpeg.Filter.Cuda; |
||||
|
||||
public class SubtitleScaleNppFilter : BaseFilter |
||||
{ |
||||
private readonly FrameState _currentState; |
||||
private readonly FrameSize _paddedSize; |
||||
private readonly FrameSize _scaledSize; |
||||
|
||||
public SubtitleScaleNppFilter(FrameState currentState, FrameSize scaledSize, FrameSize paddedSize) |
||||
{ |
||||
_currentState = currentState; |
||||
_scaledSize = scaledSize; |
||||
_paddedSize = paddedSize; |
||||
} |
||||
|
||||
public override string Filter |
||||
{ |
||||
get |
||||
{ |
||||
string scale = string.Empty; |
||||
if (_currentState.ScaledSize != _scaledSize) |
||||
{ |
||||
string targetSize = $"{_paddedSize.Width}:{_paddedSize.Height}"; |
||||
string format = string.Empty; |
||||
foreach (IPixelFormat pixelFormat in _currentState.PixelFormat) |
||||
{ |
||||
format = $":format={pixelFormat.FFmpegName}"; |
||||
} |
||||
|
||||
scale = $"scale_npp={targetSize}{format}"; |
||||
} |
||||
|
||||
return scale; |
||||
} |
||||
} |
||||
|
||||
public override FrameState NextState(FrameState currentState) => currentState; |
||||
} |
||||
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
using ErsatzTV.FFmpeg.Format; |
||||
|
||||
namespace ErsatzTV.FFmpeg.Filter.Qsv; |
||||
|
||||
public class SubtitleScaleQsvFilter : BaseFilter |
||||
{ |
||||
private readonly FrameState _currentState; |
||||
private readonly FrameSize _scaledSize; |
||||
private readonly FrameSize _paddedSize; |
||||
private readonly int _extraHardwareFrames; |
||||
|
||||
public SubtitleScaleQsvFilter( |
||||
FrameState currentState, |
||||
FrameSize scaledSize, |
||||
FrameSize paddedSize, |
||||
int extraHardwareFrames) |
||||
{ |
||||
_currentState = currentState; |
||||
_scaledSize = scaledSize; |
||||
_paddedSize = paddedSize; |
||||
_extraHardwareFrames = extraHardwareFrames; |
||||
} |
||||
|
||||
public override string Filter |
||||
{ |
||||
get |
||||
{ |
||||
string scale = string.Empty; |
||||
if (_currentState.ScaledSize != _scaledSize) |
||||
{ |
||||
string targetSize = $"w={_paddedSize.Width}:h={_paddedSize.Height}"; |
||||
|
||||
// use software scaling
|
||||
scale = $"scale={targetSize}"; |
||||
} |
||||
|
||||
string initialPixelFormat = _currentState.PixelFormat.Match(pf => pf.FFmpegName, FFmpegFormat.NV12); |
||||
if (!string.IsNullOrWhiteSpace(scale)) |
||||
{ |
||||
return $"{scale},format={initialPixelFormat},hwupload=extra_hw_frames={_extraHardwareFrames}"; |
||||
} |
||||
|
||||
return $"format={initialPixelFormat},hwupload=extra_hw_frames={_extraHardwareFrames}"; |
||||
} |
||||
} |
||||
|
||||
public override FrameState NextState(FrameState currentState) => currentState; |
||||
} |
||||
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
namespace ErsatzTV.FFmpeg.Format; |
||||
|
||||
public class PixelFormatYuva420P : IPixelFormat |
||||
{ |
||||
public string Name => PixelFormat.YUVA420P; |
||||
public string FFmpegName => FFmpegFormat.YUVA420P; |
||||
public int BitDepth => 8; |
||||
} |
||||
Loading…
Reference in new issue