From f8c88aa632a91f3ca497fcb762f358410a490379 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 22 Dec 2016 10:58:31 -0500 Subject: add null checks --- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.MediaEncoding/Encoder') diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 23e63dad0..116a6a7cf 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -95,6 +95,11 @@ namespace MediaBrowser.MediaEncoding.Encoder int defaultImageExtractionTimeoutMs, bool enableEncoderFontFile, IEnvironmentInfo environmentInfo) { + if (jsonSerializer == null) + { + throw new ArgumentNullException("jsonSerializer"); + } + _logger = logger; _jsonSerializer = jsonSerializer; ConfigurationManager = configurationManager; @@ -632,7 +637,7 @@ namespace MediaBrowser.MediaEncoding.Encoder var result = _jsonSerializer.DeserializeFromStream(process.StandardOutput.BaseStream); - if (result.streams == null && result.format == null) + if (result == null || (result.streams == null && result.format == null)) { throw new Exception("ffprobe failed - streams and format are both null."); } -- cgit v1.2.3 From 5833aedb15c2943109389d90979712978f1b2add Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 23 Dec 2016 03:50:32 -0500 Subject: update bitrate filter --- Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs | 2 +- MediaBrowser.Api/Playback/BaseStreamingService.cs | 2 +- MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs | 2 +- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 2 ++ MediaBrowser.ServerApplication/WindowsAppHost.cs | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) (limited to 'MediaBrowser.MediaEncoding/Encoder') diff --git a/Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs b/Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs index d75815847..5f37025e2 100644 --- a/Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs @@ -62,7 +62,7 @@ namespace Emby.Server.Implementations.ScheduledTasks new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerDaily, - TimeOfDayTicks = TimeSpan.FromHours(1).Ticks, + TimeOfDayTicks = TimeSpan.FromHours(2).Ticks, MaxRuntimeMs = Convert.ToInt32(TimeSpan.FromHours(4).TotalMilliseconds) } }; diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 6545d995c..5e450567a 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1467,7 +1467,7 @@ namespace MediaBrowser.Api.Playback } // h264 - return string.Format(" -b:v {0} -maxrate {0} -bufsize {1}", + return string.Format(" -maxrate {0} -bufsize {1}", bitrate.Value.ToString(UsCulture), (bitrate.Value * 2).ToString(UsCulture)); } diff --git a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs index b8087fded..d7789a5fd 100644 --- a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs @@ -816,7 +816,7 @@ namespace MediaBrowser.MediaEncoding.Encoder } // h264 - return string.Format(" -b:v {0} -maxrate {0} -bufsize {1}", + return string.Format(" -maxrate {0} -bufsize {1}", bitrate.Value.ToString(UsCulture), (bitrate.Value * 2).ToString(UsCulture)); } diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 116a6a7cf..89730a11f 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -287,6 +287,8 @@ namespace MediaBrowser.MediaEncoding.Encoder return; } + _logger.Info("Attempting to update encoder path to {0}. pathType: {1}", path ?? string.Empty, pathType ?? string.Empty); + Tuple newPaths; if (string.Equals(pathType, "system", StringComparison.OrdinalIgnoreCase)) diff --git a/MediaBrowser.ServerApplication/WindowsAppHost.cs b/MediaBrowser.ServerApplication/WindowsAppHost.cs index 398d21f32..ec66923aa 100644 --- a/MediaBrowser.ServerApplication/WindowsAppHost.cs +++ b/MediaBrowser.ServerApplication/WindowsAppHost.cs @@ -112,7 +112,7 @@ namespace MediaBrowser.ServerApplication // save it IPersistFile file = (IPersistFile)link; - file.Save(targetPath, false); + file.Save(targetPath, true); } else { -- cgit v1.2.3 From a5ffea5752a691fcd7b65093b4cfe4be131d8625 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 26 Dec 2016 14:47:37 -0500 Subject: update video audio encoding --- MediaBrowser.Api/Playback/BaseStreamingService.cs | 42 ++++++++++++++------- .../MediaEncoding/EncodingJobOptions.cs | 2 + .../Encoder/EncodingJobFactory.cs | 44 ++++++++++++++++------ 3 files changed, 62 insertions(+), 26 deletions(-) (limited to 'MediaBrowser.MediaEncoding/Encoder') diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 5e450567a..252eadbe8 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -870,33 +870,47 @@ namespace MediaBrowser.Api.Playback inputChannels = null; } - int? resultChannels = null; + int? transcoderChannelLimit = null; var codec = outputAudioCodec ?? string.Empty; if (codec.IndexOf("wma", StringComparison.OrdinalIgnoreCase) != -1) { // wmav2 currently only supports two channel output - resultChannels = Math.Min(2, inputChannels ?? 2); + transcoderChannelLimit = 2; } - else if (request.MaxAudioChannels.HasValue) + else if (codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1) + { + // libmp3lame currently only supports two channel output + transcoderChannelLimit = 2; + } + else { - var channelLimit = codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1 - ? 2 - : 6; + // If we don't have any media info then limit it to 6 to prevent encoding errors due to asking for too many channels + transcoderChannelLimit = 6; + } - if (inputChannels.HasValue) - { - channelLimit = Math.Min(channelLimit, inputChannels.Value); - } + var isTranscodingAudio = !string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase); + + int? resultChannels = null; + if (isTranscodingAudio) + { + resultChannels = request.TranscodingMaxAudioChannels; + } + resultChannels = resultChannels ?? request.MaxAudioChannels ?? request.AudioChannels; - // If we don't have any media info then limit it to 5 to prevent encoding errors due to asking for too many channels - resultChannels = Math.Min(request.MaxAudioChannels.Value, channelLimit); + if (inputChannels.HasValue) + { + resultChannels = resultChannels.HasValue + ? Math.Min(resultChannels.Value, inputChannels.Value) + : inputChannels.Value; } - if (request.TranscodingMaxAudioChannels.HasValue && !string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase)) + if (isTranscodingAudio && transcoderChannelLimit.HasValue) { - resultChannels = Math.Min(request.TranscodingMaxAudioChannels.Value, resultChannels ?? inputChannels ?? request.TranscodingMaxAudioChannels.Value); + resultChannels = resultChannels.HasValue + ? Math.Min(resultChannels.Value, transcoderChannelLimit.Value) + : transcoderChannelLimit.Value; } return resultChannels ?? request.AudioChannels; diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs b/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs index 844fafcde..d5fe790b9 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs @@ -35,6 +35,7 @@ namespace MediaBrowser.Controller.MediaEncoding public string VideoCodec { get; set; } + public int? TranscodingMaxAudioChannels { get; set; } public int? VideoBitRate { get; set; } public int? AudioStreamIndex { get; set; } public int? VideoStreamIndex { get; set; } @@ -86,6 +87,7 @@ namespace MediaBrowser.Controller.MediaEncoding MaxVideoBitDepth = info.MaxVideoBitDepth; SubtitleMethod = info.SubtitleDeliveryMethod; Context = info.Context; + TranscodingMaxAudioChannels = info.TranscodingMaxAudioChannels; if (info.SubtitleDeliveryMethod != SubtitleDeliveryMethod.External) { diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs index e197bdb6f..d6340d4ab 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs @@ -370,30 +370,50 @@ namespace MediaBrowser.MediaEncoding.Encoder inputChannels = null; } + int? transcoderChannelLimit = null; var codec = outputAudioCodec ?? string.Empty; if (codec.IndexOf("wma", StringComparison.OrdinalIgnoreCase) != -1) { // wmav2 currently only supports two channel output - return Math.Min(2, inputChannels ?? 2); + transcoderChannelLimit = 2; } - if (request.MaxAudioChannels.HasValue) + else if (codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1) { - var channelLimit = codec.IndexOf("mp3", StringComparison.OrdinalIgnoreCase) != -1 - ? 2 - : 6; + // libmp3lame currently only supports two channel output + transcoderChannelLimit = 2; + } + else + { + // If we don't have any media info then limit it to 6 to prevent encoding errors due to asking for too many channels + transcoderChannelLimit = 6; + } - if (inputChannels.HasValue) - { - channelLimit = Math.Min(channelLimit, inputChannels.Value); - } + var isTranscodingAudio = !string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase); - // If we don't have any media info then limit it to 5 to prevent encoding errors due to asking for too many channels - return Math.Min(request.MaxAudioChannels.Value, channelLimit); + int? resultChannels = null; + if (isTranscodingAudio) + { + resultChannels = request.TranscodingMaxAudioChannels; + } + resultChannels = resultChannels ?? request.MaxAudioChannels ?? request.AudioChannels; + + if (inputChannels.HasValue) + { + resultChannels = resultChannels.HasValue + ? Math.Min(resultChannels.Value, inputChannels.Value) + : inputChannels.Value; + } + + if (isTranscodingAudio && transcoderChannelLimit.HasValue) + { + resultChannels = resultChannels.HasValue + ? Math.Min(resultChannels.Value, transcoderChannelLimit.Value) + : transcoderChannelLimit.Value; } - return request.AudioChannels; + return resultChannels ?? request.AudioChannels; } private int? GetVideoBitrateParamValue(EncodingJobOptions request, MediaStream videoStream, string outputVideoCodec) -- cgit v1.2.3 From cb8751f985739cef6eefdda83b80f5ede9cc9a80 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 26 Dec 2016 16:22:45 -0500 Subject: fixes #2365 - External bitmap subtitles are loaded incorrectly --- MediaBrowser.Api/Playback/BaseStreamingService.cs | 14 +++++++++++++- MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.MediaEncoding/Encoder') diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 252eadbe8..418ec7fcb 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1068,7 +1068,19 @@ namespace MediaBrowser.Api.Playback arg += string.Format(" -canvas_size {0}:{1}", state.VideoStream.Width.Value.ToString(CultureInfo.InvariantCulture), Convert.ToInt32(height).ToString(CultureInfo.InvariantCulture)); } - arg += " -i \"" + state.SubtitleStream.Path + "\""; + + var subtitlePath = state.SubtitleStream.Path; + + if (string.Equals(Path.GetExtension(subtitlePath), ".sub", StringComparison.OrdinalIgnoreCase)) + { + var idxFile = Path.ChangeExtension(subtitlePath, ".idx"); + if (FileSystem.FileExists(idxFile)) + { + subtitlePath = idxFile; + } + } + + arg += " -i \"" + subtitlePath + "\""; } } diff --git a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs index d7789a5fd..80bbc87e3 100644 --- a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs @@ -474,7 +474,19 @@ namespace MediaBrowser.MediaEncoding.Encoder arg += string.Format(" -canvas_size {0}:{1}", state.VideoStream.Width.Value.ToString(CultureInfo.InvariantCulture), Convert.ToInt32(height).ToString(CultureInfo.InvariantCulture)); } - arg += " -i \"" + state.SubtitleStream.Path + "\""; + + var subtitlePath = state.SubtitleStream.Path; + + if (string.Equals(Path.GetExtension(subtitlePath), ".sub", StringComparison.OrdinalIgnoreCase)) + { + var idxFile = Path.ChangeExtension(subtitlePath, ".idx"); + if (FileSystem.FileExists(idxFile)) + { + subtitlePath = idxFile; + } + } + + arg += " -i \"" + subtitlePath + "\""; } } -- cgit v1.2.3