fix mpeg4 failed on vaapi

This commit is contained in:
Nyanmisaka 2020-04-10 22:12:26 +08:00 committed by GitHub
parent 79e3de1568
commit e0ee61d114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,8 +78,7 @@ namespace MediaBrowser.Controller.MediaEncoding
if (!string.IsNullOrEmpty(hwType) if (!string.IsNullOrEmpty(hwType)
&& encodingOptions.EnableHardwareEncoding && encodingOptions.EnableHardwareEncoding
&& codecMap.ContainsKey(hwType) && codecMap.ContainsKey(hwType))
&& CheckVaapi(state, hwType, encodingOptions))
{ {
var preferredEncoder = codecMap[hwType]; var preferredEncoder = codecMap[hwType];
@ -93,23 +92,6 @@ namespace MediaBrowser.Controller.MediaEncoding
return defaultEncoder; return defaultEncoder;
} }
private bool CheckVaapi(EncodingJobInfo state, string hwType, EncodingOptions encodingOptions)
{
if (!string.Equals(hwType, "vaapi", StringComparison.OrdinalIgnoreCase))
{
// No vaapi requested, return OK.
return true;
}
if (string.IsNullOrEmpty(encodingOptions.VaapiDevice))
{
// No device specified, return OK.
return true;
}
return IsVaapiSupported(state);
}
private bool IsVaapiSupported(EncodingJobInfo state) private bool IsVaapiSupported(EncodingJobInfo state)
{ {
var videoStream = state.VideoStream; var videoStream = state.VideoStream;
@ -1648,7 +1630,7 @@ namespace MediaBrowser.Controller.MediaEncoding
} }
// If we're hardware VAAPI decoding and software encoding, download frames from the decoder first // If we're hardware VAAPI decoding and software encoding, download frames from the decoder first
else if (string.Equals(options.HardwareAccelerationType, "vaapi", StringComparison.OrdinalIgnoreCase) else if (IsVaapiSupported(state) && string.Equals(options.HardwareAccelerationType, "vaapi", StringComparison.OrdinalIgnoreCase)
&& string.Equals(outputVideoCodec, "libx264", StringComparison.OrdinalIgnoreCase)) && string.Equals(outputVideoCodec, "libx264", StringComparison.OrdinalIgnoreCase))
{ {
/* /*
@ -2014,19 +1996,28 @@ namespace MediaBrowser.Controller.MediaEncoding
} }
// If we're hardware VAAPI decoding and software encoding, download frames from the decoder first // If we're hardware VAAPI decoding and software encoding, download frames from the decoder first
else if (string.Equals(options.HardwareAccelerationType, "vaapi", StringComparison.OrdinalIgnoreCase) else if (IsVaapiSupported(state) && (videoDecoder ?? string.Empty).IndexOf("vaapi", StringComparison.OrdinalIgnoreCase) != -1
&& string.Equals(outputVideoCodec, "libx264", StringComparison.OrdinalIgnoreCase)) && string.Equals(outputVideoCodec, "libx264", StringComparison.OrdinalIgnoreCase))
{ {
var codec = videoStream.Codec.ToLowerInvariant(); var codec = videoStream.Codec.ToLowerInvariant();
var pixelFormat = videoStream.PixelFormat.ToLowerInvariant(); var IsColorDepth10 = (videoStream.Profile ?? string.Empty).IndexOf("10", StringComparison.OrdinalIgnoreCase) != -1;
// Assert hardware VAAPI decodable (Except h264 10-bit and higher color depth) // Assert 10-bit hardware VAAPI decodable
// TODO: a propery way to detect hardware capabilities and falling back when transcoding is failed if (IsColorDepth10 && (string.Equals(codec, "hevc", StringComparison.OrdinalIgnoreCase)
if ((pixelFormat ?? string.Empty).IndexOf("p10", StringComparison.OrdinalIgnoreCase) == -1 || string.Equals(codec, "h265", StringComparison.OrdinalIgnoreCase)
|| ((pixelFormat ?? string.Empty).IndexOf("p10", StringComparison.OrdinalIgnoreCase) != -1 || string.Equals(codec, "vp9", StringComparison.OrdinalIgnoreCase)))
&& (string.Equals(codec, "hevc", StringComparison.OrdinalIgnoreCase) {
|| string.Equals(codec, "h265", StringComparison.OrdinalIgnoreCase) /*
|| string.Equals(codec, "vp9", StringComparison.OrdinalIgnoreCase)))) Download data from GPU to CPU as p010le format.
Colorspace conversion is unnecessary here as libx264 will handle it.
If this step is missing, it will fail on AMD but not on intel.
*/
filters.Add("hwdownload");
filters.Add("format=p010le");
}
// Assert 8-bit hardware VAAPI decodable
else if (!IsColorDepth10)
{ {
filters.Add("hwdownload"); filters.Add("hwdownload");
filters.Add("format=nv12"); filters.Add("format=nv12");