From d92936187d2e0a4391dbca6ea182bdb180c3dece Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 24 Aug 2014 17:07:04 -0400 Subject: [PATCH] Extract subs to srt instead of ass --- .../Subtitles/SubtitleEncoder.cs | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs index 1e839c5a36..df22b5e1f7 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs @@ -194,15 +194,17 @@ namespace MediaBrowser.MediaEncoding.Subtitles MediaStream subtitleStream, CancellationToken cancellationToken) { + const string extractedFormat = "srt"; + if (!subtitleStream.IsExternal) { // Extract - var outputPath = GetSubtitleCachePath(mediaPath, subtitleStream.Index, ".ass"); + var outputPath = GetSubtitleCachePath(mediaPath, subtitleStream.Index, "." + extractedFormat); await ExtractTextSubtitle(inputFiles, protocol, subtitleStream.Index, false, outputPath, cancellationToken) .ConfigureAwait(false); - return new Tuple(outputPath, "ass"); + return new Tuple(outputPath, extractedFormat); } var currentFormat = (Path.GetExtension(subtitleStream.Path) ?? subtitleStream.Codec) @@ -211,12 +213,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles if (GetReader(currentFormat, false) == null) { // Convert - var outputPath = GetSubtitleCachePath(mediaPath, subtitleStream.Index, ".ass"); + var outputPath = GetSubtitleCachePath(mediaPath, subtitleStream.Index, "." + extractedFormat); - await ConvertTextSubtitleToAss(subtitleStream.Path, outputPath, subtitleStream.Language, cancellationToken) + await ConvertTextSubtitleToSrt(subtitleStream.Path, outputPath, subtitleStream.Language, cancellationToken) .ConfigureAwait(false); - return new Tuple(outputPath, "ass"); + return new Tuple(outputPath, extractedFormat); } return new Tuple(subtitleStream.Path, currentFormat); @@ -303,14 +305,14 @@ namespace MediaBrowser.MediaEncoding.Subtitles } /// - /// Converts the text subtitle to ass. + /// Converts the text subtitle to SRT. /// /// The input path. /// The output path. /// The language. /// The cancellation token. /// Task. - public async Task ConvertTextSubtitleToAss(string inputPath, string outputPath, string language, + public async Task ConvertTextSubtitleToSrt(string inputPath, string outputPath, string language, CancellationToken cancellationToken) { var semaphore = GetLock(outputPath); @@ -321,7 +323,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles { if (!File.Exists(outputPath)) { - await ConvertTextSubtitleToAssInternal(inputPath, outputPath, language).ConfigureAwait(false); + await ConvertTextSubtitleToSrtInternal(inputPath, outputPath, language).ConfigureAwait(false); } } finally @@ -331,17 +333,19 @@ namespace MediaBrowser.MediaEncoding.Subtitles } /// - /// Converts the text subtitle to ass. + /// Converts the text subtitle to SRT internal. /// /// The input path. /// The output path. /// The language. /// Task. - /// inputPath + /// + /// inputPath /// or - /// outputPath + /// outputPath + /// /// - private async Task ConvertTextSubtitleToAssInternal(string inputPath, string outputPath, string language) + private async Task ConvertTextSubtitleToSrtInternal(string inputPath, string outputPath, string language) { if (string.IsNullOrEmpty(inputPath)) { @@ -375,7 +379,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles CreateNoWindow = true, UseShellExecute = false, FileName = _mediaEncoder.EncoderPath, - Arguments = string.Format("{0} -i \"{1}\" -c:s ass \"{2}\"", encodingParam, inputPath, outputPath), + Arguments = string.Format("{0} -i \"{1}\" -c:s srt \"{2}\"", encodingParam, inputPath, outputPath), WindowStyle = ProcessWindowStyle.Hidden, ErrorDialog = false @@ -529,7 +533,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); - var processArgs = string.Format("-i {0} -map 0:{1} -an -vn -c:s ass \"{2}\"", inputPath, + var processArgs = string.Format("-i {0} -map 0:{1} -an -vn -c:s srt \"{2}\"", inputPath, subtitleStreamIndex, outputPath); if (copySubtitleStream)