From ffd3101ac63d082e8086311b98db5b2ef3971c12 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 30 Jun 2016 17:04:26 -0400 Subject: [PATCH 1/2] Fixes for nvenc support marked as experimental, since more testing should be done on options --- MediaBrowser.Api/Playback/BaseStreamingService.cs | 14 +++++++------- MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs | 12 ++++++------ .../Encoder/EncoderValidator.cs | 2 +- .../Encoder/EncodingJobFactory.cs | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 01d959d70..e3eb1e4ba 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -292,9 +292,9 @@ namespace MediaBrowser.Api.Playback return "h264_qsv"; } - if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "libnvenc", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "nvenc", StringComparison.OrdinalIgnoreCase)) { - return "libnvenc"; + return "h264_nvenc"; } if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareAccelerationType, "h264_omx", StringComparison.OrdinalIgnoreCase)) { @@ -338,8 +338,8 @@ namespace MediaBrowser.Api.Playback } - // h264 (libnvenc) - else if (string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) + // h264 (h264_nvenc) + else if (string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) { param = "-preset high-performance"; } @@ -412,9 +412,9 @@ namespace MediaBrowser.Api.Playback if (!string.IsNullOrEmpty(state.VideoRequest.Level)) { - // h264_qsv and libnvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format + // h264_qsv and h264_nvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) || - string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) + string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) { switch (state.VideoRequest.Level) { @@ -458,7 +458,7 @@ namespace MediaBrowser.Api.Playback if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) && !string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) && - !string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) + !string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) { param = "-pix_fmt yuv420p " + param; } diff --git a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs index 77bd50b9b..9eb796360 100644 --- a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs @@ -607,10 +607,10 @@ namespace MediaBrowser.MediaEncoding.Encoder } - // h264 (libnvenc) - else if (string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) + // h264 (h264_nvenc) + else if (string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) { - param = "-preset high-performance"; + param = "-preset llhq"; } // webm @@ -683,9 +683,9 @@ namespace MediaBrowser.MediaEncoding.Encoder if (!string.IsNullOrEmpty(levelString)) { - // h264_qsv and libnvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format + // h264_qsv and h264_nvenc expect levels to be expressed as a decimal. libx264 supports decimal and non-decimal format if (string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) || - string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) + string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) { switch (levelString) { @@ -729,7 +729,7 @@ namespace MediaBrowser.MediaEncoding.Encoder if (!string.Equals(videoCodec, "h264_omx", StringComparison.OrdinalIgnoreCase) && !string.Equals(videoCodec, "h264_qsv", StringComparison.OrdinalIgnoreCase) && - !string.Equals(videoCodec, "libnvenc", StringComparison.OrdinalIgnoreCase)) + !string.Equals(videoCodec, "h264_nvenc", StringComparison.OrdinalIgnoreCase)) { param = "-pix_fmt yuv420p " + param; } diff --git a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs index 133cc8d70..e2348e8df 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs @@ -85,7 +85,7 @@ namespace MediaBrowser.MediaEncoding.Encoder "libopus", //"libvorbis", "srt", - "libnvenc", + "h264_nvenc", "h264_qsv" }; diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs index 177009306..7c4b7fc2f 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs @@ -562,9 +562,9 @@ namespace MediaBrowser.MediaEncoding.Encoder return "h264_qsv"; } - if (string.Equals(options.HardwareAccelerationType, "libnvenc", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(options.HardwareAccelerationType, "nvenc", StringComparison.OrdinalIgnoreCase)) { - return "libnvenc"; + return "h264_nvenc"; } if (string.Equals(options.HardwareAccelerationType, "h264_omx", StringComparison.OrdinalIgnoreCase)) { From 68df03b87292dca2a87a61fe9fac7ea3b441af74 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 30 Jun 2016 17:26:43 -0400 Subject: [PATCH 2/2] adjust segment length --- MediaBrowser.Api/Playback/BaseStreamingService.cs | 5 +++-- MediaBrowser.Api/Playback/StreamState.cs | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index e3eb1e4ba..e6ac990bc 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1645,9 +1645,10 @@ namespace MediaBrowser.Api.Playback var state = new StreamState(MediaSourceManager, Logger) { Request = request, - RequestedUrl = url + RequestedUrl = url, + UserAgent = Request.UserAgent }; - + //if ((Request.UserAgent ?? string.Empty).IndexOf("iphone", StringComparison.OrdinalIgnoreCase) != -1 || // (Request.UserAgent ?? string.Empty).IndexOf("ipad", StringComparison.OrdinalIgnoreCase) != -1 || // (Request.UserAgent ?? string.Empty).IndexOf("ipod", StringComparison.OrdinalIgnoreCase) != -1) diff --git a/MediaBrowser.Api/Playback/StreamState.cs b/MediaBrowser.Api/Playback/StreamState.cs index fbcccbaca..d0d0337c2 100644 --- a/MediaBrowser.Api/Playback/StreamState.cs +++ b/MediaBrowser.Api/Playback/StreamState.cs @@ -75,7 +75,13 @@ namespace MediaBrowser.Api.Playback { if (string.Equals(OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase)) { - return 10; + var userAgent = UserAgent ?? string.Empty; + if (userAgent.IndexOf("AppleTV", StringComparison.OrdinalIgnoreCase) != -1) + { + return 10; + } + + return 6; } return 3; @@ -99,6 +105,7 @@ namespace MediaBrowser.Api.Playback public string OutputVideoSync = "-1"; public List SupportedAudioCodecs { get; set; } + public string UserAgent { get; set; } public StreamState(IMediaSourceManager mediaSourceManager, ILogger logger) {