support qsv encoding

This commit is contained in:
Luke Pulverenti 2015-11-26 23:33:20 -05:00
parent b73c3f4411
commit 4415506837
10 changed files with 37 additions and 83 deletions

View File

@ -130,7 +130,6 @@ namespace MediaBrowser.Api.Playback
data += "-" + (state.Request.DeviceId ?? string.Empty); data += "-" + (state.Request.DeviceId ?? string.Empty);
data += "-" + (state.Request.PlaySessionId ?? string.Empty); data += "-" + (state.Request.PlaySessionId ?? string.Empty);
data += "-" + (state.Request.ClientTime ?? string.Empty);
var dataHash = data.GetMD5().ToString("N"); var dataHash = data.GetMD5().ToString("N");
@ -287,14 +286,20 @@ namespace MediaBrowser.Api.Playback
return threads; return threads;
} }
protected string H264Encoder protected string GetH264Encoder(StreamState state)
{ {
get if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "qsv", StringComparison.OrdinalIgnoreCase))
{ {
return "libx264"; // It's currently failing on live tv
if (state.RunTimeTicks.HasValue)
{
return "h264_qsv";
} }
} }
return "libx264";
}
/// <summary> /// <summary>
/// Gets the video bitrate to specify on the command line /// Gets the video bitrate to specify on the command line
/// </summary> /// </summary>
@ -313,7 +318,7 @@ namespace MediaBrowser.Api.Playback
{ {
param = "-preset superfast"; param = "-preset superfast";
param += " -crf 23"; param += " -crf 23 -rc-lookahead 0 -muxdelay 0 -refs 1";
} }
else if (string.Equals(videoCodec, "libx265", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(videoCodec, "libx265", StringComparison.OrdinalIgnoreCase))
@ -326,7 +331,7 @@ namespace MediaBrowser.Api.Playback
// h264 (h264_qsv) // h264 (h264_qsv)
else if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase)) else if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase))
{ {
param = "-preset 7"; param = "-preset 7 -look_ahead 0";
} }
@ -400,8 +405,10 @@ namespace MediaBrowser.Api.Playback
if (!string.IsNullOrEmpty(state.VideoRequest.Level)) if (!string.IsNullOrEmpty(state.VideoRequest.Level))
{ {
var h264Encoder = GetH264Encoder(state);
// h264_qsv and libnvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format // h264_qsv and libnvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format
if (String.Equals(H264Encoder, "h264_qsv", StringComparison.OrdinalIgnoreCase) || String.Equals(H264Encoder, "libnvenc", StringComparison.OrdinalIgnoreCase)) if (String.Equals(h264Encoder, "h264_qsv", StringComparison.OrdinalIgnoreCase) || String.Equals(h264Encoder, "libnvenc", StringComparison.OrdinalIgnoreCase))
{ {
switch (state.VideoRequest.Level) switch (state.VideoRequest.Level)
{ {
@ -561,7 +568,10 @@ namespace MediaBrowser.Api.Playback
if (string.Equals(outputVideoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase)) if (string.Equals(outputVideoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase))
{ {
filters[filters.Count - 1] += ":flags=fast_bilinear"; if (filters.Count > 1)
{
//filters[filters.Count - 1] += ":flags=fast_bilinear";
}
} }
var output = string.Empty; var output = string.Empty;
@ -782,7 +792,7 @@ namespace MediaBrowser.Api.Playback
{ {
if (string.Equals(codec, "h264", StringComparison.OrdinalIgnoreCase)) if (string.Equals(codec, "h264", StringComparison.OrdinalIgnoreCase))
{ {
return H264Encoder; return GetH264Encoder(state);
} }
if (string.Equals(codec, "vpx", StringComparison.OrdinalIgnoreCase)) if (string.Equals(codec, "vpx", StringComparison.OrdinalIgnoreCase))
{ {
@ -810,7 +820,7 @@ namespace MediaBrowser.Api.Playback
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
protected string GetVideoDecoder(StreamState state) protected string GetVideoDecoder(StreamState state)
{ {
if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareVideoDecoder, "qsv", StringComparison.OrdinalIgnoreCase)) if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "qsv", StringComparison.OrdinalIgnoreCase))
{ {
if (state.VideoStream != null && !string.IsNullOrWhiteSpace(state.VideoStream.Codec)) if (state.VideoStream != null && !string.IsNullOrWhiteSpace(state.VideoStream.Codec))
{ {
@ -1415,50 +1425,46 @@ namespace MediaBrowser.Api.Playback
} }
} }
else if (i == 16) else if (i == 16)
{
request.ClientTime = val;
}
else if (i == 17)
{ {
if (videoRequest != null) if (videoRequest != null)
{ {
videoRequest.MaxRefFrames = int.Parse(val, UsCulture); videoRequest.MaxRefFrames = int.Parse(val, UsCulture);
} }
} }
else if (i == 18) else if (i == 17)
{ {
if (videoRequest != null) if (videoRequest != null)
{ {
videoRequest.MaxVideoBitDepth = int.Parse(val, UsCulture); videoRequest.MaxVideoBitDepth = int.Parse(val, UsCulture);
} }
} }
else if (i == 19) else if (i == 18)
{ {
if (videoRequest != null) if (videoRequest != null)
{ {
videoRequest.Profile = val; videoRequest.Profile = val;
} }
} }
else if (i == 20) else if (i == 19)
{ {
if (videoRequest != null) if (videoRequest != null)
{ {
videoRequest.Cabac = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); videoRequest.Cabac = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
} }
} }
else if (i == 21) else if (i == 20)
{ {
request.PlaySessionId = val; request.PlaySessionId = val;
} }
else if (i == 22) else if (i == 21)
{ {
// api_key // api_key
} }
else if (i == 23) else if (i == 22)
{ {
request.LiveStreamId = val; request.LiveStreamId = val;
} }
else if (i == 24) else if (i == 23)
{ {
// Duplicating ItemId because of MediaMonkey // Duplicating ItemId because of MediaMonkey
} }
@ -1662,7 +1668,6 @@ namespace MediaBrowser.Api.Playback
state.InputContainer = mediaSource.Container; state.InputContainer = mediaSource.Container;
state.InputFileSize = mediaSource.Size; state.InputFileSize = mediaSource.Size;
state.InputBitrate = mediaSource.Bitrate; state.InputBitrate = mediaSource.Bitrate;
state.ReadInputAtNativeFramerate = mediaSource.ReadAtNativeFramerate;
state.RunTimeTicks = mediaSource.RunTimeTicks; state.RunTimeTicks = mediaSource.RunTimeTicks;
state.RemoteHttpHeaders = mediaSource.RequiredHttpHeaders; state.RemoteHttpHeaders = mediaSource.RequiredHttpHeaders;

View File

@ -430,7 +430,7 @@ namespace MediaBrowser.Api.Playback.Dash
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream; var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream;
args += " " + GetVideoQualityParam(state, H264Encoder, true) + keyFrameArg; args += " " + GetVideoQualityParam(state, GetH264Encoder(state), true) + keyFrameArg;
// Add resolution params, if specified // Add resolution params, if specified
if (!hasGraphicalSubs) if (!hasGraphicalSubs)

View File

@ -1,5 +1,4 @@
using MediaBrowser.Common.IO; using MediaBrowser.Common.Net;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Dlna; using MediaBrowser.Controller.Dlna;
@ -475,41 +474,6 @@ namespace MediaBrowser.Api.Playback.Hls
await Task.Delay(100, cancellationToken).ConfigureAwait(false); await Task.Delay(100, cancellationToken).ConfigureAwait(false);
} }
// if a different file is encoding, it's done
//var currentTranscodingIndex = GetCurrentTranscodingIndex(playlistPath);
//if (currentTranscodingIndex > segmentIndex)
//{
//return GetSegmentResult(segmentPath, segmentIndex);
//}
//// Wait for the file to stop being written to, then stream it
//var length = new FileInfo(segmentPath).Length;
//var eofCount = 0;
//while (eofCount < 10)
//{
// var info = new FileInfo(segmentPath);
// if (!info.Exists)
// {
// break;
// }
// var newLength = info.Length;
// if (newLength == length)
// {
// eofCount++;
// }
// else
// {
// eofCount = 0;
// }
// length = newLength;
// await Task.Delay(100, cancellationToken).ConfigureAwait(false);
//}
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
return GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob); return GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob);
} }
@ -871,7 +835,7 @@ namespace MediaBrowser.Api.Playback.Hls
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream; var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream;
args += " " + GetVideoQualityParam(state, H264Encoder, true) + keyFrameArg; args += " " + GetVideoQualityParam(state, GetH264Encoder(state), true) + keyFrameArg;
//args += " -mixed-refs 0 -refs 3 -x264opts b_pyramid=0:weightb=0:weightp=0"; //args += " -mixed-refs 0 -refs 3 -x264opts b_pyramid=0:weightb=0:weightp=0";

View File

@ -106,7 +106,7 @@ namespace MediaBrowser.Api.Playback.Hls
var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream; var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream;
args += " " + GetVideoQualityParam(state, H264Encoder, true) + keyFrameArg; args += " " + GetVideoQualityParam(state, GetH264Encoder(state), true) + keyFrameArg;
// Add resolution params, if specified // Add resolution params, if specified
if (!hasGraphicalSubs) if (!hasGraphicalSubs)

View File

@ -70,7 +70,6 @@ namespace MediaBrowser.Api.Playback
public string DeviceProfileId { get; set; } public string DeviceProfileId { get; set; }
public string Params { get; set; } public string Params { get; set; }
public string ClientTime { get; set; }
public string PlaySessionId { get; set; } public string PlaySessionId { get; set; }
public string LiveStreamId { get; set; } public string LiveStreamId { get; set; }
} }

View File

@ -42,7 +42,7 @@ namespace MediaBrowser.Api.Playback
var options = GetOptions(); var options = GetOptions();
if (options.EnableThrottling && IsThrottleAllowed(_job, options.ThrottleThresholdInSeconds)) if (options.EnableThrottling && IsThrottleAllowed(_job, options.ThrottleThresholdSeconds))
{ {
PauseTranscoding(); PauseTranscoding();
} }

View File

@ -79,20 +79,6 @@ namespace MediaBrowser.LocalMetadata.Savers
builder.Append("<GameSystem>" + SecurityElement.Escape(game.GameSystem) + "</GameSystem>"); builder.Append("<GameSystem>" + SecurityElement.Escape(game.GameSystem) + "</GameSystem>");
} }
var val = game.GetProviderId(MetadataProviders.NesBox);
if (!string.IsNullOrEmpty(val))
{
builder.Append("<NesBox>" + SecurityElement.Escape(val) + "</NesBox>");
}
val = game.GetProviderId(MetadataProviders.NesBoxRom);
if (!string.IsNullOrEmpty(val))
{
builder.Append("<NesBoxRom>" + SecurityElement.Escape(val) + "</NesBoxRom>");
}
XmlSaverHelpers.AddCommonNodes(game, _libraryManager, builder); XmlSaverHelpers.AddCommonNodes(game, _libraryManager, builder);
builder.Append("</Item>"); builder.Append("</Item>");

View File

@ -359,7 +359,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
protected string GetVideoDecoder(EncodingJob state) protected string GetVideoDecoder(EncodingJob state)
{ {
if (string.Equals(GetEncodingOptions().HardwareVideoDecoder, "qsv", StringComparison.OrdinalIgnoreCase)) if (string.Equals(GetEncodingOptions().HardwareAccelerationType, "qsv", StringComparison.OrdinalIgnoreCase))
{ {
if (state.VideoStream != null && !string.IsNullOrWhiteSpace(state.VideoStream.Codec)) if (state.VideoStream != null && !string.IsNullOrWhiteSpace(state.VideoStream.Codec))
{ {

View File

@ -8,14 +8,14 @@ namespace MediaBrowser.Model.Configuration
public double DownMixAudioBoost { get; set; } public double DownMixAudioBoost { get; set; }
public bool EnableDebugLogging { get; set; } public bool EnableDebugLogging { get; set; }
public bool EnableThrottling { get; set; } public bool EnableThrottling { get; set; }
public int ThrottleThresholdInSeconds { get; set; } public int ThrottleThresholdSeconds { get; set; }
public string HardwareVideoDecoder { get; set; } public string HardwareAccelerationType { get; set; }
public EncodingOptions() public EncodingOptions()
{ {
DownMixAudioBoost = 2; DownMixAudioBoost = 2;
EnableThrottling = true; EnableThrottling = true;
ThrottleThresholdInSeconds = 120; ThrottleThresholdSeconds = 110;
EncodingThreadCount = -1; EncodingThreadCount = -1;
} }
} }

View File

@ -234,7 +234,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
int? width = null; int? width = null;
int? height = null; int? height = null;
bool isInterlaced = true; bool isInterlaced = true;
var videoCodec = !string.IsNullOrWhiteSpace(GetEncodingOptions().HardwareVideoDecoder) ? null : "mpeg2video"; var videoCodec = !string.IsNullOrWhiteSpace(GetEncodingOptions().HardwareAccelerationType) ? null : "mpeg2video";
int? videoBitrate = null; int? videoBitrate = null;