fix qsv device creation on Comet Lake
reddit: https://www.reddit.com/r/jellyfin/comments/huct4x/jellyfin_1060_released/fyn30ds
This commit is contained in:
parent
8f11e057a2
commit
5f89e81306
|
@ -495,13 +495,13 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
arg.Append("-hwaccel qsv -init_hw_device qsv=hw ");
|
arg.Append("-hwaccel qsv ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isWindows)
|
if (isWindows)
|
||||||
{
|
{
|
||||||
arg.Append("-hwaccel qsv -init_hw_device qsv=hw ");
|
arg.Append("-hwaccel qsv ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// While using SW decoder
|
// While using SW decoder
|
||||||
|
@ -1606,25 +1606,41 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
index = outputSizeParam.IndexOf("format", StringComparison.OrdinalIgnoreCase);
|
index = outputSizeParam.IndexOf("hwupload=extra_hw_frames", StringComparison.OrdinalIgnoreCase);
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
outputSizeParam = outputSizeParam.Substring(index);
|
outputSizeParam = outputSizeParam.Substring(index);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
index = outputSizeParam.IndexOf("yadif", StringComparison.OrdinalIgnoreCase);
|
index = outputSizeParam.IndexOf("format", StringComparison.OrdinalIgnoreCase);
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
outputSizeParam = outputSizeParam.Substring(index);
|
outputSizeParam = outputSizeParam.Substring(index);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
index = outputSizeParam.IndexOf("scale", StringComparison.OrdinalIgnoreCase);
|
index = outputSizeParam.IndexOf("yadif", StringComparison.OrdinalIgnoreCase);
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
outputSizeParam = outputSizeParam.Substring(index);
|
outputSizeParam = outputSizeParam.Substring(index);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index = outputSizeParam.IndexOf("scale", StringComparison.OrdinalIgnoreCase);
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
outputSizeParam = outputSizeParam.Substring(index);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index = outputSizeParam.IndexOf("vpp", StringComparison.OrdinalIgnoreCase);
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
outputSizeParam = outputSizeParam.Substring(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1790,6 +1806,10 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
var outputWidth = width.Value;
|
var outputWidth = width.Value;
|
||||||
var outputHeight = height.Value;
|
var outputHeight = height.Value;
|
||||||
var qsv_or_vaapi = string.Equals(videoEncoder, "h264_qsv", StringComparison.OrdinalIgnoreCase);
|
var qsv_or_vaapi = string.Equals(videoEncoder, "h264_qsv", StringComparison.OrdinalIgnoreCase);
|
||||||
|
var isDeintEnabled = state.DeInterlace("h264", true)
|
||||||
|
|| state.DeInterlace("avc", true)
|
||||||
|
|| state.DeInterlace("h265", true)
|
||||||
|
|| state.DeInterlace("hevc", true);
|
||||||
|
|
||||||
if (!videoWidth.HasValue
|
if (!videoWidth.HasValue
|
||||||
|| outputWidth != videoWidth.Value
|
|| outputWidth != videoWidth.Value
|
||||||
|
@ -1805,7 +1825,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
qsv_or_vaapi ? "vpp_qsv" : "scale_vaapi",
|
qsv_or_vaapi ? "vpp_qsv" : "scale_vaapi",
|
||||||
outputWidth,
|
outputWidth,
|
||||||
outputHeight,
|
outputHeight,
|
||||||
(qsv_or_vaapi && state.DeInterlace("h264", true)) ? ":deinterlace=1" : string.Empty));
|
(qsv_or_vaapi && isDeintEnabled) ? ":deinterlace=1" : string.Empty));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1814,7 +1834,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
CultureInfo.InvariantCulture,
|
CultureInfo.InvariantCulture,
|
||||||
"{0}=format=nv12{1}",
|
"{0}=format=nv12{1}",
|
||||||
qsv_or_vaapi ? "vpp_qsv" : "scale_vaapi",
|
qsv_or_vaapi ? "vpp_qsv" : "scale_vaapi",
|
||||||
(qsv_or_vaapi && state.DeInterlace("h264", true)) ? ":deinterlace=1" : string.Empty));
|
(qsv_or_vaapi && isDeintEnabled) ? ":deinterlace=1" : string.Empty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((videoDecoder ?? string.Empty).IndexOf("cuvid", StringComparison.OrdinalIgnoreCase) != -1
|
else if ((videoDecoder ?? string.Empty).IndexOf("cuvid", StringComparison.OrdinalIgnoreCase) != -1
|
||||||
|
@ -2026,7 +2046,6 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
// http://sonnati.wordpress.com/2012/10/19/ffmpeg-the-swiss-army-knife-of-internet-streaming-part-vi/
|
// http://sonnati.wordpress.com/2012/10/19/ffmpeg-the-swiss-army-knife-of-internet-streaming-part-vi/
|
||||||
|
|
||||||
var request = state.BaseRequest;
|
var request = state.BaseRequest;
|
||||||
|
|
||||||
var videoStream = state.VideoStream;
|
var videoStream = state.VideoStream;
|
||||||
var filters = new List<string>();
|
var filters = new List<string>();
|
||||||
|
|
||||||
|
@ -2035,23 +2054,31 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
var inputHeight = videoStream?.Height;
|
var inputHeight = videoStream?.Height;
|
||||||
var threeDFormat = state.MediaSource.Video3DFormat;
|
var threeDFormat = state.MediaSource.Video3DFormat;
|
||||||
|
|
||||||
|
var isVaapiDecoder = videoDecoder.IndexOf("vaapi", StringComparison.OrdinalIgnoreCase) != -1;
|
||||||
|
var isVaapiH264Encoder = outputVideoCodec.IndexOf("h264_vaapi", StringComparison.OrdinalIgnoreCase) != -1;
|
||||||
|
var isQsvH264Encoder = outputVideoCodec.IndexOf("h264_qsv", StringComparison.OrdinalIgnoreCase) != -1;
|
||||||
|
var isNvdecH264Decoder = videoDecoder.IndexOf("h264_cuvid", StringComparison.OrdinalIgnoreCase) != -1;
|
||||||
|
var isLibX264Encoder = outputVideoCodec.IndexOf("libx264", StringComparison.OrdinalIgnoreCase) != -1;
|
||||||
|
var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
|
||||||
|
|
||||||
|
var hasTextSubs = state.SubtitleStream != null && state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode;
|
||||||
|
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream && state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode;
|
||||||
|
|
||||||
// When the input may or may not be hardware VAAPI decodable
|
// When the input may or may not be hardware VAAPI decodable
|
||||||
if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
if (isVaapiH264Encoder)
|
||||||
{
|
{
|
||||||
filters.Add("format=nv12|vaapi");
|
filters.Add("format=nv12|vaapi");
|
||||||
filters.Add("hwupload");
|
filters.Add("hwupload");
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the input may or may not be hardware QSV decodable
|
// When burning in graphical subtitles using overlay_qsv, upload videostream to the same qsv context
|
||||||
else if (string.Equals(outputVideoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase))
|
else if (isLinux && hasGraphicalSubs && isQsvH264Encoder)
|
||||||
{
|
{
|
||||||
filters.Add("format=nv12|qsv");
|
|
||||||
filters.Add("hwupload=extra_hw_frames=64");
|
filters.Add("hwupload=extra_hw_frames=64");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 (IsVaapiSupported(state) && videoDecoder.IndexOf("vaapi", StringComparison.OrdinalIgnoreCase) != -1
|
else if (IsVaapiSupported(state) && isVaapiDecoder && isLibX264Encoder)
|
||||||
&& string.Equals(outputVideoCodec, "libx264", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
{
|
||||||
var codec = videoStream.Codec.ToLowerInvariant();
|
var codec = videoStream.Codec.ToLowerInvariant();
|
||||||
var isColorDepth10 = IsColorDepth10(state);
|
var isColorDepth10 = IsColorDepth10(state);
|
||||||
|
@ -2079,16 +2106,19 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add hardware deinterlace filter before scaling filter
|
// Add hardware deinterlace filter before scaling filter
|
||||||
if (state.DeInterlace("h264", true))
|
if (state.DeInterlace("h264", true) || state.DeInterlace("avc", true))
|
||||||
{
|
{
|
||||||
if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
if (isVaapiH264Encoder)
|
||||||
{
|
{
|
||||||
filters.Add(string.Format(CultureInfo.InvariantCulture, "deinterlace_vaapi"));
|
filters.Add(string.Format(CultureInfo.InvariantCulture, "deinterlace_vaapi"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add software deinterlace filter before scaling filter
|
// Add software deinterlace filter before scaling filter
|
||||||
if (state.DeInterlace("h264", true) || state.DeInterlace("h265", true) || state.DeInterlace("hevc", true))
|
if (state.DeInterlace("h264", true)
|
||||||
|
|| state.DeInterlace("avc", true)
|
||||||
|
|| state.DeInterlace("h265", true)
|
||||||
|
|| state.DeInterlace("hevc", true))
|
||||||
{
|
{
|
||||||
var deintParam = string.Empty;
|
var deintParam = string.Empty;
|
||||||
var inputFramerate = videoStream?.RealFrameRate;
|
var inputFramerate = videoStream?.RealFrameRate;
|
||||||
|
@ -2105,9 +2135,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(deintParam))
|
if (!string.IsNullOrEmpty(deintParam))
|
||||||
{
|
{
|
||||||
if (!string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase)
|
if (!isVaapiH264Encoder && !isQsvH264Encoder && !isNvdecH264Decoder)
|
||||||
&& !string.Equals(outputVideoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase)
|
|
||||||
&& videoDecoder.IndexOf("h264_cuvid", StringComparison.OrdinalIgnoreCase) == -1)
|
|
||||||
{
|
{
|
||||||
filters.Add(deintParam);
|
filters.Add(deintParam);
|
||||||
}
|
}
|
||||||
|
@ -2117,12 +2145,10 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
// Add scaling filter: scale_*=format=nv12 or scale_*=w=*:h=*:format=nv12 or scale=expr
|
// Add scaling filter: scale_*=format=nv12 or scale_*=w=*:h=*:format=nv12 or scale=expr
|
||||||
filters.AddRange(GetScalingFilters(state, inputWidth, inputHeight, threeDFormat, videoDecoder, outputVideoCodec, request.Width, request.Height, request.MaxWidth, request.MaxHeight));
|
filters.AddRange(GetScalingFilters(state, inputWidth, inputHeight, threeDFormat, videoDecoder, outputVideoCodec, request.Width, request.Height, request.MaxWidth, request.MaxHeight));
|
||||||
|
|
||||||
// Add parameters to use VAAPI with burn-in text subttiles (GH issue #642)
|
// Add parameters to use VAAPI with burn-in text subtitles (GH issue #642)
|
||||||
if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
if (isVaapiH264Encoder)
|
||||||
{
|
{
|
||||||
if (state.SubtitleStream != null
|
if (hasTextSubs)
|
||||||
&& state.SubtitleStream.IsTextSubtitleStream
|
|
||||||
&& state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode)
|
|
||||||
{
|
{
|
||||||
// Test passed on Intel and AMD gfx
|
// Test passed on Intel and AMD gfx
|
||||||
filters.Add("hwmap=mode=read+write");
|
filters.Add("hwmap=mode=read+write");
|
||||||
|
@ -2132,9 +2158,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
|
|
||||||
var output = string.Empty;
|
var output = string.Empty;
|
||||||
|
|
||||||
if (state.SubtitleStream != null
|
if (hasTextSubs)
|
||||||
&& state.SubtitleStream.IsTextSubtitleStream
|
|
||||||
&& state.SubtitleDeliveryMethod == SubtitleDeliveryMethod.Encode)
|
|
||||||
{
|
{
|
||||||
var subParam = GetTextSubtitleParam(state);
|
var subParam = GetTextSubtitleParam(state);
|
||||||
|
|
||||||
|
@ -2142,7 +2166,7 @@ namespace MediaBrowser.Controller.MediaEncoding
|
||||||
|
|
||||||
// Ensure proper filters are passed to ffmpeg in case of hardware acceleration via VA-API
|
// Ensure proper filters are passed to ffmpeg in case of hardware acceleration via VA-API
|
||||||
// Reference: https://trac.ffmpeg.org/wiki/Hardware/VAAPI
|
// Reference: https://trac.ffmpeg.org/wiki/Hardware/VAAPI
|
||||||
if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
if (isVaapiH264Encoder)
|
||||||
{
|
{
|
||||||
filters.Add("hwmap");
|
filters.Add("hwmap");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user