mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* add LIBVA_DRIVER_NAME env var * add vaapi device name * add FFREPORT env var * fixespull/636/head
49 changed files with 310 additions and 67 deletions
@ -0,0 +1,3 @@ |
|||||||
|
namespace ErsatzTV.FFmpeg.Environment; |
||||||
|
|
||||||
|
public record EnvironmentVariable(string Key, string Value); |
||||||
@ -0,0 +1,46 @@ |
|||||||
|
using System.Runtime.InteropServices; |
||||||
|
|
||||||
|
namespace ErsatzTV.FFmpeg.Environment; |
||||||
|
|
||||||
|
public class FFReportVariable : IPipelineStep |
||||||
|
{ |
||||||
|
private readonly string _reportsFolder; |
||||||
|
private readonly IList<InputFile> _inputFiles; |
||||||
|
|
||||||
|
public FFReportVariable(string reportsFolder, IList<InputFile> inputFiles) |
||||||
|
{ |
||||||
|
_reportsFolder = reportsFolder; |
||||||
|
_inputFiles = inputFiles; |
||||||
|
} |
||||||
|
|
||||||
|
public IList<EnvironmentVariable> EnvironmentVariables |
||||||
|
{ |
||||||
|
get |
||||||
|
{ |
||||||
|
string fileName = _inputFiles.OfType<ConcatInputFile>().Any() |
||||||
|
? Path.Combine(_reportsFolder, "ffmpeg-%t-concat.log") |
||||||
|
: Path.Combine(_reportsFolder, "ffmpeg-%t-transcode.log"); |
||||||
|
|
||||||
|
// rework filename in a format that works on windows
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
||||||
|
{ |
||||||
|
// \ is escape, so use / for directory separators
|
||||||
|
fileName = fileName.Replace(@"\", @"/"); |
||||||
|
|
||||||
|
// colon after drive letter needs to be escaped
|
||||||
|
fileName = fileName.Replace(@":/", @"\:/"); |
||||||
|
} |
||||||
|
|
||||||
|
return new List<EnvironmentVariable> |
||||||
|
{ |
||||||
|
new("FFREPORT", $"file={fileName}:level=32") |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public IList<string> GlobalOptions => Array.Empty<string>(); |
||||||
|
public IList<string> InputOptions => Array.Empty<string>(); |
||||||
|
public IList<string> FilterOptions => Array.Empty<string>(); |
||||||
|
public IList<string> OutputOptions => Array.Empty<string>(); |
||||||
|
public FrameState NextState(FrameState currentState) => currentState with { SaveReport = true }; |
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
namespace ErsatzTV.FFmpeg.Environment; |
||||||
|
|
||||||
|
public class LibvaDriverNameVariable : IPipelineStep |
||||||
|
{ |
||||||
|
private readonly string _driverName; |
||||||
|
|
||||||
|
public LibvaDriverNameVariable(string driverName) |
||||||
|
{ |
||||||
|
_driverName = driverName; |
||||||
|
} |
||||||
|
|
||||||
|
public IList<EnvironmentVariable> EnvironmentVariables => new List<EnvironmentVariable> |
||||||
|
{ |
||||||
|
new("LIBVA_DRIVER_NAME", _driverName) |
||||||
|
}; |
||||||
|
|
||||||
|
public IList<string> GlobalOptions => Array.Empty<string>(); |
||||||
|
public IList<string> InputOptions => Array.Empty<string>(); |
||||||
|
public IList<string> FilterOptions => Array.Empty<string>(); |
||||||
|
public IList<string> OutputOptions => Array.Empty<string>(); |
||||||
|
public FrameState NextState(FrameState currentState) => currentState with { VaapiDriver = _driverName }; |
||||||
|
} |
||||||
@ -1,16 +1,37 @@ |
|||||||
namespace ErsatzTV.FFmpeg.Option.HardwareAcceleration; |
using LanguageExt; |
||||||
|
using Microsoft.Extensions.Logging; |
||||||
|
|
||||||
|
namespace ErsatzTV.FFmpeg.Option.HardwareAcceleration; |
||||||
|
|
||||||
public static class AvailableHardwareAccelerationOptions |
public static class AvailableHardwareAccelerationOptions |
||||||
{ |
{ |
||||||
public static IPipelineStep ForMode(HardwareAccelerationMode mode) |
public static Option<IPipelineStep> ForMode( |
||||||
{ |
HardwareAccelerationMode mode, |
||||||
return mode switch |
Option<string> vaapiDevice, |
||||||
|
ILogger logger) => |
||||||
|
mode switch |
||||||
{ |
{ |
||||||
HardwareAccelerationMode.Nvenc => new CudaHardwareAccelerationOption(), |
HardwareAccelerationMode.Nvenc => new CudaHardwareAccelerationOption(), |
||||||
HardwareAccelerationMode.Qsv => new QsvHardwareAccelerationOption(), |
HardwareAccelerationMode.Qsv => new QsvHardwareAccelerationOption(), |
||||||
HardwareAccelerationMode.Vaapi => new VaapiHardwareAccelerationOption(), |
HardwareAccelerationMode.Vaapi => GetVaapiAcceleration(vaapiDevice, logger), |
||||||
HardwareAccelerationMode.VideoToolbox => new VideoToolboxHardwareAccelerationOption(), |
HardwareAccelerationMode.VideoToolbox => new VideoToolboxHardwareAccelerationOption(), |
||||||
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null) |
_ => LogUnknownMode(mode, logger) |
||||||
}; |
}; |
||||||
|
|
||||||
|
private static Option<IPipelineStep> GetVaapiAcceleration(Option<string> vaapiDevice, ILogger logger) |
||||||
|
{ |
||||||
|
foreach (string device in vaapiDevice) |
||||||
|
{ |
||||||
|
return new VaapiHardwareAccelerationOption(device); |
||||||
|
} |
||||||
|
|
||||||
|
logger.LogWarning("VAAPI device name is missing; falling back to software mode"); |
||||||
|
return Option<IPipelineStep>.None; |
||||||
|
} |
||||||
|
|
||||||
|
private static Option<IPipelineStep> LogUnknownMode(HardwareAccelerationMode mode, ILogger logger) |
||||||
|
{ |
||||||
|
logger.LogWarning("Unexpected hardware acceleration mode {AccelMode}; may have playback issues", mode); |
||||||
|
return Option<IPipelineStep>.None; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue