From 41f7e2ab19b723a32865b868ffe489dbd36065e8 Mon Sep 17 00:00:00 2001 From: abeloin Date: Sat, 25 Jan 2014 15:27:31 -0500 Subject: [PATCH 1/2] Don't re-encode subtitle: ass/ssa -> ass. This fix Issue #630 : "ASS encoder supports only one ASS rectangle field". --- .../Playback/BaseStreamingService.cs | 6 +++++- .../MediaInfo/IMediaEncoder.cs | 3 ++- .../MediaEncoder/MediaEncoder.cs | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 76cce0d66d..67f06c7920 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -536,7 +536,11 @@ namespace MediaBrowser.Api.Playback Directory.CreateDirectory(parentPath); - var task = MediaEncoder.ExtractTextSubtitle(inputPath, type, state.SubtitleStream.Index, path, CancellationToken.None); + // Don't re-encode ass/ssa to ass because ffmpeg ass encoder fails if there's more than one ass rectangle. Affect Anime mostly. + // See https://lists.ffmpeg.org/pipermail/ffmpeg-cvslog/2013-April/063616.html + bool isAssSubtitle = string.Equals(state.SubtitleStream.Codec, "ass", StringComparison.OrdinalIgnoreCase) || string.Equals(state.SubtitleStream.Codec, "ssa", StringComparison.OrdinalIgnoreCase); + + var task = MediaEncoder.ExtractTextSubtitle(inputPath, type, state.SubtitleStream.Index, isAssSubtitle, path, CancellationToken.None); Task.WaitAll(task); } diff --git a/MediaBrowser.Controller/MediaInfo/IMediaEncoder.cs b/MediaBrowser.Controller/MediaInfo/IMediaEncoder.cs index 0564c06131..86b508012d 100644 --- a/MediaBrowser.Controller/MediaInfo/IMediaEncoder.cs +++ b/MediaBrowser.Controller/MediaInfo/IMediaEncoder.cs @@ -41,10 +41,11 @@ namespace MediaBrowser.Controller.MediaInfo /// The input files. /// The type. /// Index of the subtitle stream. + /// if set to true, copy stream instead of converting. /// The output path. /// The cancellation token. /// Task. - Task ExtractTextSubtitle(string[] inputFiles, InputType type, int subtitleStreamIndex, string outputPath, CancellationToken cancellationToken); + Task ExtractTextSubtitle(string[] inputFiles, InputType type, int subtitleStreamIndex, bool copySubtitleStream, string outputPath, CancellationToken cancellationToken); /// /// Converts the text subtitle to ass. diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs index e435b1644c..fddcbe53e7 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs @@ -601,11 +601,12 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// The input files. /// The type. /// Index of the subtitle stream. + /// if set to true, copy stream instead of converting. /// The output path. /// The cancellation token. /// Task. /// Must use inputPath list overload - public async Task ExtractTextSubtitle(string[] inputFiles, InputType type, int subtitleStreamIndex, string outputPath, CancellationToken cancellationToken) + public async Task ExtractTextSubtitle(string[] inputFiles, InputType type, int subtitleStreamIndex, bool copySubtitleStream, string outputPath, CancellationToken cancellationToken) { var semaphore = GetLock(outputPath); @@ -615,7 +616,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder { if (!File.Exists(outputPath)) { - await ExtractTextSubtitleInternal(GetInputArgument(inputFiles, type), subtitleStreamIndex, outputPath, cancellationToken).ConfigureAwait(false); + await ExtractTextSubtitleInternal(GetInputArgument(inputFiles, type), subtitleStreamIndex, copySubtitleStream, outputPath, cancellationToken).ConfigureAwait(false); } } finally @@ -629,6 +630,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// /// The input path. /// Index of the subtitle stream. + /// if set to true, copy stream instead of converting. /// The output path. /// The cancellation token. /// Task. @@ -638,7 +640,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// or /// cancellationToken /// - private async Task ExtractTextSubtitleInternal(string inputPath, int subtitleStreamIndex, string outputPath, CancellationToken cancellationToken) + private async Task ExtractTextSubtitleInternal(string inputPath, int subtitleStreamIndex, bool copySubtitleStream, string outputPath, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(inputPath)) { @@ -650,6 +652,12 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder throw new ArgumentNullException("outputPath"); } + string processArgs = string.Format("-i {0} -map 0:{1} -an -vn -c:s ass \"{2}\"", inputPath, subtitleStreamIndex, outputPath); + + if (copySubtitleStream) + { + processArgs = string.Format("-i {0} -map 0:{1} -an -vn -c:s copy \"{2}\"", inputPath, subtitleStreamIndex, outputPath); + } var process = new Process { @@ -662,7 +670,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder RedirectStandardError = true, FileName = FFMpegPath, - Arguments = string.Format("-i {0} -map 0:{1} -an -vn -c:s ass \"{2}\"", inputPath, subtitleStreamIndex, outputPath), + Arguments = processArgs, WindowStyle = ProcessWindowStyle.Hidden, ErrorDialog = false } From ac8ffb8db0a41607cba9f8d3576a9f6643ac86bb Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 25 Jan 2014 16:07:19 -0500 Subject: [PATCH 2/2] Added IAppHost.Name --- .../BaseApplicationHost.cs | 6 ++++++ MediaBrowser.Common/IApplicationHost.cs | 6 ++++++ MediaBrowser.ServerApplication/ApplicationHost.cs | 14 +++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 8e9a287b61..9d2dd08387 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -165,6 +165,12 @@ namespace MediaBrowser.Common.Implementations protected IIsoManager IsoManager { get; private set; } + /// + /// Gets the name. + /// + /// The name. + public abstract string Name { get; } + /// /// Initializes a new instance of the class. /// diff --git a/MediaBrowser.Common/IApplicationHost.cs b/MediaBrowser.Common/IApplicationHost.cs index 1c7ffe4240..8cd1252c74 100644 --- a/MediaBrowser.Common/IApplicationHost.cs +++ b/MediaBrowser.Common/IApplicationHost.cs @@ -13,6 +13,12 @@ namespace MediaBrowser.Common /// public interface IApplicationHost { + /// + /// Gets the name. + /// + /// The name. + string Name { get; } + /// /// Occurs when [application updated]. /// diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 045c9f18c6..b78a0f36d0 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -185,6 +185,18 @@ namespace MediaBrowser.ServerApplication } + /// + /// Gets the name. + /// + /// The name. + public override string Name + { + get + { + return "Media Browser Server"; + } + } + /// /// Gets a value indicating whether this instance can self restart. /// @@ -732,7 +744,7 @@ namespace MediaBrowser.ServerApplication { ServerAuthorization.AuthorizeServer( ServerConfigurationManager.Configuration.HttpServerPortNumber, - HttpServerUrlPrefixes.First(), + HttpServerUrlPrefixes.First(), ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber, UdpServerEntryPoint.PortNumber, ConfigurationManager.CommonApplicationPaths.TempDirectory);