mirror of https://github.com/jellyfin/jellyfin.git
add vaapi support
This commit is contained in:
parent
f57a0e6b81
commit
2e65c32ede
|
@ -314,6 +314,10 @@ namespace MediaBrowser.Api.Playback
|
||||||
{
|
{
|
||||||
return GetAvailableEncoder("h264_omx", defaultEncoder);
|
return GetAvailableEncoder("h264_omx", defaultEncoder);
|
||||||
}
|
}
|
||||||
|
if (string.Equals(hwType, "vaapi", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return GetAvailableEncoder("h264_vaapi", defaultEncoder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultEncoder;
|
return defaultEncoder;
|
||||||
|
@ -427,7 +431,8 @@ namespace MediaBrowser.Api.Playback
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(state.VideoRequest.Profile))
|
if (!string.IsNullOrEmpty(state.VideoRequest.Profile))
|
||||||
{
|
{
|
||||||
if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase))
|
if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
!string.Equals(videoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
// not supported by h264_omx
|
// not supported by h264_omx
|
||||||
param += " -profile:v " + state.VideoRequest.Profile;
|
param += " -profile:v " + state.VideoRequest.Profile;
|
||||||
|
@ -482,7 +487,8 @@ namespace MediaBrowser.Api.Playback
|
||||||
|
|
||||||
if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) &&
|
if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) &&
|
||||||
!string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) &&
|
!string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) &&
|
||||||
!string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase))
|
!string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
!string.Equals(videoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
param = "-pix_fmt yuv420p " + param;
|
param = "-pix_fmt yuv420p " + param;
|
||||||
}
|
}
|
||||||
|
@ -548,11 +554,48 @@ namespace MediaBrowser.Api.Playback
|
||||||
|
|
||||||
var filters = new List<string>();
|
var filters = new List<string>();
|
||||||
|
|
||||||
if (state.DeInterlace)
|
if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
filters.Add("format=nv12|vaapi");
|
||||||
|
filters.Add("hwupload");
|
||||||
|
}
|
||||||
|
else if (state.DeInterlace && !string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
filters.Add("yadif=0:-1:0");
|
filters.Add("yadif=0:-1:0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
// Work around vaapi's reduced scaling features
|
||||||
|
var scaler = "scale_vaapi";
|
||||||
|
|
||||||
|
// Given the input dimensions (inputWidth, inputHeight), determine the output dimensions
|
||||||
|
// (outputWidth, outputHeight). The user may request precise output dimensions or maximum
|
||||||
|
// output dimensions. Output dimensions are guaranteed to be even.
|
||||||
|
decimal inputWidth = Convert.ToDecimal(state.VideoStream.Width);
|
||||||
|
decimal inputHeight = Convert.ToDecimal(state.VideoStream.Height);
|
||||||
|
decimal outputWidth = request.Width.HasValue ? Convert.ToDecimal(request.Width.Value) : inputWidth;
|
||||||
|
decimal outputHeight = request.Height.HasValue ? Convert.ToDecimal(request.Height.Value) : inputHeight;
|
||||||
|
decimal maximumWidth = request.MaxWidth.HasValue ? Convert.ToDecimal(request.MaxWidth.Value) : outputWidth;
|
||||||
|
decimal maximumHeight = request.MaxHeight.HasValue ? Convert.ToDecimal(request.MaxHeight.Value) : outputHeight;
|
||||||
|
|
||||||
|
if (outputWidth > maximumWidth || outputHeight > maximumHeight)
|
||||||
|
{
|
||||||
|
var scale = Math.Min(maximumWidth / outputWidth, maximumHeight / outputHeight);
|
||||||
|
outputWidth = Math.Min(maximumWidth, Math.Truncate(outputWidth * scale));
|
||||||
|
outputHeight = Math.Min(maximumHeight, Math.Truncate(outputHeight * scale));
|
||||||
|
}
|
||||||
|
|
||||||
|
outputWidth = 2 * Math.Truncate(outputWidth / 2);
|
||||||
|
outputHeight = 2 * Math.Truncate(outputHeight / 2);
|
||||||
|
|
||||||
|
if (outputWidth != inputWidth || outputHeight != inputHeight)
|
||||||
|
{
|
||||||
|
filters.Add(string.Format("{0}=w={1}:h={2}", scaler, outputWidth.ToString(UsCulture), outputHeight.ToString(UsCulture)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// If fixed dimensions were supplied
|
// If fixed dimensions were supplied
|
||||||
if (request.Width.HasValue && request.Height.HasValue)
|
if (request.Width.HasValue && request.Height.HasValue)
|
||||||
{
|
{
|
||||||
|
@ -602,6 +645,7 @@ namespace MediaBrowser.Api.Playback
|
||||||
|
|
||||||
filters.Add(string.Format("scale=trunc(oh*a/2)*2:min(ih\\,{0})", maxHeightParam));
|
filters.Add(string.Format("scale=trunc(oh*a/2)*2:min(ih\\,{0})", maxHeightParam));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var output = string.Empty;
|
var output = string.Empty;
|
||||||
|
|
||||||
|
@ -935,6 +979,15 @@ namespace MediaBrowser.Api.Playback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state.VideoRequest != null)
|
||||||
|
{
|
||||||
|
var encodingOptions = ApiEntryPoint.Instance.GetEncodingOptions();
|
||||||
|
if (GetVideoEncoder(state).IndexOf("vaapi", StringComparison.OrdinalIgnoreCase) != -1)
|
||||||
|
{
|
||||||
|
arg = "-hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device " + encodingOptions.VaapiDevice + " " + arg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return arg.Trim();
|
return arg.Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -680,7 +680,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(state.Options.Profile))
|
if (!string.IsNullOrEmpty(state.Options.Profile))
|
||||||
{
|
{
|
||||||
if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase))
|
if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
!string.Equals(videoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
// not supported by h264_omx
|
// not supported by h264_omx
|
||||||
param += " -profile:v " + state.Options.Profile;
|
param += " -profile:v " + state.Options.Profile;
|
||||||
|
@ -737,7 +738,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
|
|
||||||
if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) &&
|
if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) &&
|
||||||
!string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) &&
|
!string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) &&
|
||||||
!string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase))
|
!string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
!string.Equals(videoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
param = "-pix_fmt yuv420p " + param;
|
param = "-pix_fmt yuv420p " + param;
|
||||||
}
|
}
|
||||||
|
@ -887,11 +889,48 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
|
|
||||||
var filters = new List<string>();
|
var filters = new List<string>();
|
||||||
|
|
||||||
if (state.DeInterlace)
|
if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
filters.Add("format=nv12|vaapi");
|
||||||
|
filters.Add("hwupload");
|
||||||
|
}
|
||||||
|
else if (state.DeInterlace && !string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
filters.Add("yadif=0:-1:0");
|
filters.Add("yadif=0:-1:0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (string.Equals(outputVideoCodec, "h264_vaapi", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
// Work around vaapi's reduced scaling features
|
||||||
|
var scaler = "scale_vaapi";
|
||||||
|
|
||||||
|
// Given the input dimensions (inputWidth, inputHeight), determine the output dimensions
|
||||||
|
// (outputWidth, outputHeight). The user may request precise output dimensions or maximum
|
||||||
|
// output dimensions. Output dimensions are guaranteed to be even.
|
||||||
|
decimal inputWidth = Convert.ToDecimal(state.VideoStream.Width);
|
||||||
|
decimal inputHeight = Convert.ToDecimal(state.VideoStream.Height);
|
||||||
|
decimal outputWidth = request.Width.HasValue ? Convert.ToDecimal(request.Width.Value) : inputWidth;
|
||||||
|
decimal outputHeight = request.Height.HasValue ? Convert.ToDecimal(request.Height.Value) : inputHeight;
|
||||||
|
decimal maximumWidth = request.MaxWidth.HasValue ? Convert.ToDecimal(request.MaxWidth.Value) : outputWidth;
|
||||||
|
decimal maximumHeight = request.MaxHeight.HasValue ? Convert.ToDecimal(request.MaxHeight.Value) : outputHeight;
|
||||||
|
|
||||||
|
if (outputWidth > maximumWidth || outputHeight > maximumHeight)
|
||||||
|
{
|
||||||
|
var scale = Math.Min(maximumWidth / outputWidth, maximumHeight / outputHeight);
|
||||||
|
outputWidth = Math.Min(maximumWidth, Math.Truncate(outputWidth * scale));
|
||||||
|
outputHeight = Math.Min(maximumHeight, Math.Truncate(outputHeight * scale));
|
||||||
|
}
|
||||||
|
|
||||||
|
outputWidth = 2 * Math.Truncate(outputWidth / 2);
|
||||||
|
outputHeight = 2 * Math.Truncate(outputHeight / 2);
|
||||||
|
|
||||||
|
if (outputWidth != inputWidth || outputHeight != inputHeight)
|
||||||
|
{
|
||||||
|
filters.Add(string.Format("{0}=w={1}:h={2}", scaler, outputWidth.ToString(UsCulture), outputHeight.ToString(UsCulture)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// If fixed dimensions were supplied
|
// If fixed dimensions were supplied
|
||||||
if (request.Width.HasValue && request.Height.HasValue)
|
if (request.Width.HasValue && request.Height.HasValue)
|
||||||
{
|
{
|
||||||
|
@ -941,13 +980,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
|
|
||||||
filters.Add(string.Format("scale=trunc(oh*a/2)*2:min(ih\\,{0})", maxHeightParam));
|
filters.Add(string.Format("scale=trunc(oh*a/2)*2:min(ih\\,{0})", maxHeightParam));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.Equals(outputVideoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
if (filters.Count > 1)
|
|
||||||
{
|
|
||||||
//filters[filters.Count - 1] += ":flags=fast_bilinear";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var output = string.Empty;
|
var output = string.Empty;
|
||||||
|
|
|
@ -586,6 +586,10 @@ namespace MediaBrowser.MediaEncoding.Encoder
|
||||||
{
|
{
|
||||||
return GetAvailableEncoder(mediaEncoder, "h264_omx", defaultEncoder);
|
return GetAvailableEncoder(mediaEncoder, "h264_omx", defaultEncoder);
|
||||||
}
|
}
|
||||||
|
if (string.Equals(hwType, "vaapi", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return GetAvailableEncoder(mediaEncoder, "h264_vaapi", defaultEncoder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultEncoder;
|
return defaultEncoder;
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace MediaBrowser.Model.Configuration
|
||||||
public int ThrottleDelaySeconds { get; set; }
|
public int ThrottleDelaySeconds { get; set; }
|
||||||
public string HardwareAccelerationType { get; set; }
|
public string HardwareAccelerationType { get; set; }
|
||||||
public string EncoderAppPath { get; set; }
|
public string EncoderAppPath { get; set; }
|
||||||
|
public string VaapiDevice { get; set; }
|
||||||
|
|
||||||
public EncodingOptions()
|
public EncodingOptions()
|
||||||
{
|
{
|
||||||
|
|
|
@ -273,32 +273,11 @@ namespace MediaBrowser.Server.Mono.Native
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
info.DownloadUrls = GetDownloadUrls(environment);
|
// No version available - user requirement
|
||||||
|
info.DownloadUrls = new string[] { };
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string[] GetDownloadUrls(NativeEnvironment environment)
|
|
||||||
{
|
|
||||||
switch (environment.OperatingSystem)
|
|
||||||
{
|
|
||||||
case OperatingSystem.Linux:
|
|
||||||
|
|
||||||
switch (environment.SystemArchitecture)
|
|
||||||
{
|
|
||||||
case Architecture.X64:
|
|
||||||
return new[]
|
|
||||||
{
|
|
||||||
"https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/linux/ffmpeg-git-20160215-64bit-static.7z"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No version available
|
|
||||||
return new string[] { };
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NullPowerManagement : IPowerManagement
|
public class NullPowerManagement : IPowerManagement
|
||||||
|
|
Loading…
Reference in New Issue