add more separate hw decoding toggles

This commit is contained in:
nyanmisaka
2020-04-09 00:15:01 +08:00
committed by Vasily
parent 976ae36bea
commit b4b93995f7
6 changed files with 332 additions and 48 deletions

View File

@@ -14,23 +14,38 @@ namespace MediaBrowser.MediaEncoding.Encoder
private static readonly string[] requiredDecoders = new[]
{
"h264",
"hevc",
"mpeg2video",
"h264_qsv",
"hevc_qsv",
"mpeg2_qsv",
"mpeg2_mmal",
"mpeg4_mmal",
"vc1_qsv",
"vc1_mmal",
"h264_cuvid",
"hevc_cuvid",
"mpeg4",
"msmpeg4",
"dts",
"ac3",
"aac",
"mp3",
"h264",
"h264_qsv",
"hevc_qsv",
"mpeg2_qsv",
"vc1_qsv",
"vp8_qsv",
"vp9_qsv",
"h264_cuvid",
"hevc_cuvid",
"mpeg2_cuvid",
"vc1_cuvid",
"mpeg4_cuvid",
"vp8_cuvid",
"vp9_cuvid",
"h264_mmal",
"hevc"
"mpeg2_mmal",
"mpeg4_mmal",
"vc1_mmal",
"h264_mediacodec",
"hevc_mediacodec",
"mpeg2_mediacodec",
"mpeg4_mediacodec",
"vp8_mediacodec",
"vp9_mediacodec"
};
private static readonly string[] requiredEncoders = new[]
@@ -43,22 +58,22 @@ namespace MediaBrowser.MediaEncoding.Encoder
"libvpx-vp9",
"aac",
"libfdk_aac",
"ac3",
"libmp3lame",
"libopus",
"libvorbis",
"srt",
"h264_nvenc",
"hevc_nvenc",
"h264_amf",
"hevc_amf",
"h264_qsv",
"hevc_qsv",
"h264_omx",
"hevc_omx",
"h264_nvenc",
"hevc_nvenc",
"h264_vaapi",
"hevc_vaapi",
"h264_v4l2m2m",
"ac3",
"h264_amf",
"hevc_amf"
"h264_omx",
"hevc_omx",
"h264_v4l2m2m"
};
// Try and use the individual library versions to determine a FFmpeg version
@@ -159,6 +174,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
public IEnumerable<string> GetEncoders() => GetCodecs(Codec.Encoder);
public IEnumerable<string> GetHwaccels() => GetHwaccelTypes();
/// <summary>
/// Using the output from "ffmpeg -version" work out the FFmpeg version.
/// For pre-built binaries the first line should contain a string like "ffmpeg version x.y", which is easy
@@ -218,6 +235,32 @@ namespace MediaBrowser.MediaEncoding.Encoder
Decoder
}
private IEnumerable<string> GetHwaccelTypes()
{
string output = null;
try
{
output = GetProcessOutput(_encoderPath, "-hwaccels");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error detecting available hwaccel types");
}
if (string.IsNullOrWhiteSpace(output))
{
return Enumerable.Empty<string>();
}
var found = output.Split(new char[] {'\r','\n'},StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
found.RemoveAt(0);
_logger.LogInformation("Available hwaccel types: {Types}", found);
return found;
}
private IEnumerable<string> GetCodecs(Codec codec)
{
string codecstr = codec == Codec.Encoder ? "encoders" : "decoders";

View File

@@ -111,6 +111,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
SetAvailableDecoders(validator.GetDecoders());
SetAvailableEncoders(validator.GetEncoders());
SetAvailableHwaccels(validator.GetHwaccels());
}
_logger.LogInformation("FFmpeg: {EncoderLocation}: {FfmpegPath}", EncoderLocation, _ffmpegPath ?? string.Empty);
@@ -257,6 +258,13 @@ namespace MediaBrowser.MediaEncoding.Encoder
//_logger.Info("Supported decoders: {0}", string.Join(",", list.ToArray()));
}
private List<string> _hwaccels = new List<string>();
public void SetAvailableHwaccels(IEnumerable<string> list)
{
_hwaccels = list.ToList();
//_logger.Info("Supported hwaccels: {0}", string.Join(",", list.ToArray()));
}
public bool SupportsEncoder(string encoder)
{
return _encoders.Contains(encoder, StringComparer.OrdinalIgnoreCase);
@@ -267,6 +275,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
return _decoders.Contains(decoder, StringComparer.OrdinalIgnoreCase);
}
public bool SupportsHwaccel(string hwaccel)
{
return _hwaccels.Contains(hwaccel, StringComparer.OrdinalIgnoreCase);
}
public bool CanEncodeToAudioCodec(string codec)
{
if (string.Equals(codec, "opus", StringComparison.OrdinalIgnoreCase))