From e8bb5c4b9a615c14d569c2fb925b008d1e3cd418 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 25 Oct 2013 10:41:23 -0400 Subject: [PATCH] external subtitle fixes --- .../MediaEncoder/MediaEncoder.cs | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs index 807f38ae03..785bbca7c1 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs @@ -390,7 +390,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder { if (!File.Exists(outputPath)) { - await ConvertTextSubtitleToAssInternal(inputPath, outputPath, language, offset, cancellationToken).ConfigureAwait(false); + await ConvertTextSubtitleToAssInternal(inputPath, outputPath, language, offset).ConfigureAwait(false); } } finally @@ -399,6 +399,8 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder } } + private const int FastSeekOffsetSeconds = 1; + /// /// Converts the text subtitle to ass. /// @@ -406,14 +408,12 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder /// The output path. /// The language. /// The offset. - /// The cancellation token. /// Task. /// inputPath /// or /// outputPath /// - private async Task ConvertTextSubtitleToAssInternal(string inputPath, string outputPath, string language, TimeSpan offset, - CancellationToken cancellationToken) + private async Task ConvertTextSubtitleToAssInternal(string inputPath, string outputPath, string language, TimeSpan offset) { if (string.IsNullOrEmpty(inputPath)) { @@ -425,7 +425,8 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder throw new ArgumentNullException("outputPath"); } - var slowSeekParam = offset.TotalSeconds > 0 ? " -ss " + offset.TotalSeconds.ToString(UsCulture) : string.Empty; + var slowSeekParam = GetSlowSeekCommandLineParameter(offset); + var fastSeekParam = GetFastSeekCommandLineParameter(offset); var encodingParam = string.IsNullOrEmpty(language) ? string.Empty : GetSubtitleLanguageEncodingParam(language) + " "; @@ -441,8 +442,13 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder UseShellExecute = false, FileName = FFMpegPath, Arguments = - string.Format("{0}-i \"{1}\"{2} \"{3}\"", encodingParam, inputPath, slowSeekParam, - outputPath), + string.Format("{0}{1}-i \"{2}\"{3} \"{4}\"", + fastSeekParam, + encodingParam, + inputPath, + slowSeekParam, + outputPath), + WindowStyle = ProcessWindowStyle.Hidden, ErrorDialog = false } @@ -533,6 +539,28 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder await SetAssFont(outputPath).ConfigureAwait(false); } + protected string GetFastSeekCommandLineParameter(TimeSpan offset) + { + var seconds = offset.TotalSeconds - FastSeekOffsetSeconds; + + if (seconds > 0) + { + return string.Format("-ss {0} ", seconds.ToString(UsCulture)); + } + + return string.Empty; + } + + protected string GetSlowSeekCommandLineParameter(TimeSpan offset) + { + if (offset.TotalSeconds - FastSeekOffsetSeconds > 0) + { + return string.Format(" -ss {0}", FastSeekOffsetSeconds.ToString(UsCulture)); + } + + return string.Empty; + } + /// /// Gets the subtitle language encoding param. ///