diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 81ab7c4ebb..30700ad4c9 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -348,9 +348,7 @@ namespace MediaBrowser.Api.Playback /// System.String. private string GetConvertedAssPath(Video video, MediaStream subtitleStream, long? startTimeTicks, bool performConversion) { - var offset = startTimeTicks.HasValue - ? TimeSpan.FromTicks(startTimeTicks.Value) - : TimeSpan.FromTicks(0); + var offset = TimeSpan.FromTicks(startTimeTicks ?? 0); var path = Kernel.Instance.FFMpegManager.GetSubtitleCachePath(video, subtitleStream.Index, offset, ".ass"); diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs index 1312d49ced..3d4da1e15f 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/MediaEncoder.cs @@ -554,6 +554,8 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder throw new ArgumentNullException("outputPath"); } + var offsetParam = offset.Ticks > 0 ? "-ss " + offset.TotalSeconds + " " : string.Empty; + var process = new Process { StartInfo = new ProcessStartInfo @@ -564,7 +566,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder CreateNoWindow = true, UseShellExecute = false, FileName = FFMpegPath, - Arguments = string.Format("-i \"{0}\" \"{1}\"", inputPath, outputPath), + Arguments = string.Format("{0}-i \"{1}\" \"{2}\"", offsetParam, inputPath, outputPath), WindowStyle = ProcessWindowStyle.Hidden, ErrorDialog = false } @@ -593,7 +595,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder throw; } - process.StandardError.BaseStream.CopyToAsync(logFileStream); + var logTask = process.StandardError.BaseStream.CopyToAsync(logFileStream); var ranToCompletion = process.WaitForExit(60000); @@ -606,6 +608,8 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder process.Kill(); process.WaitForExit(1000); + + await logTask.ConfigureAwait(false); } catch (Win32Exception ex) { @@ -621,6 +625,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder } finally { + logFileStream.Dispose(); _subtitleExtractionResourcePool.Release(); }