diff options
| author | Luke <luke.pulverenti@gmail.com> | 2016-07-07 12:01:35 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-07 12:01:35 -0400 |
| commit | 63ae4310f46d4c8f1215ba54f300ec41a16dc257 (patch) | |
| tree | 448afde8297982f1b8197d8f512f305488de2b02 /MediaBrowser.MediaEncoding | |
| parent | bdca2ea839b0e88934bd84a3caddb9d36031f6b0 (diff) | |
| parent | 88be568b401c358f3ab2596ed3ccf25c694e52e0 (diff) | |
Merge pull request #1925 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.MediaEncoding')
| -rw-r--r-- | MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs index 9a83aba88..a63aca11b 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs @@ -120,6 +120,15 @@ namespace MediaBrowser.MediaEncoding.Subtitles bool preserveOriginalTimestamps, CancellationToken cancellationToken) { + if (string.IsNullOrWhiteSpace(itemId)) + { + throw new ArgumentNullException("itemId"); + } + if (string.IsNullOrWhiteSpace(mediaSourceId)) + { + throw new ArgumentNullException("mediaSourceId"); + } + var subtitle = await GetSubtitleStream(itemId, mediaSourceId, subtitleStreamIndex, cancellationToken) .ConfigureAwait(false); @@ -141,10 +150,19 @@ namespace MediaBrowser.MediaEncoding.Subtitles int subtitleStreamIndex, CancellationToken cancellationToken) { + if (string.IsNullOrWhiteSpace(itemId)) + { + throw new ArgumentNullException("itemId"); + } + if (string.IsNullOrWhiteSpace(mediaSourceId)) + { + throw new ArgumentNullException("mediaSourceId"); + } + var mediaSources = await _mediaSourceManager.GetPlayackMediaSources(itemId, null, false, new[] { MediaType.Audio, MediaType.Video }, cancellationToken).ConfigureAwait(false); var mediaSource = mediaSources - .First(i => string.Equals(i.Id, mediaSourceId)); + .First(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase)); var subtitleStream = mediaSource.MediaStreams .First(i => i.Type == MediaStreamType.Subtitle && i.Index == subtitleStreamIndex); @@ -609,7 +627,8 @@ namespace MediaBrowser.MediaEncoding.Subtitles throw; } - process.StandardError.BaseStream.CopyToAsync(logFileStream); + // Important - don't await the log task or we won't be able to kill ffmpeg when the user stops playback + Task.Run(() => StartStreamingLog(process.StandardError.BaseStream, logFileStream)); var ranToCompletion = process.WaitForExit(300000); @@ -686,6 +705,33 @@ namespace MediaBrowser.MediaEncoding.Subtitles } } + private async Task StartStreamingLog(Stream source, Stream target) + { + try + { + using (var reader = new StreamReader(source)) + { + while (!reader.EndOfStream) + { + var line = await reader.ReadLineAsync().ConfigureAwait(false); + + var bytes = Encoding.UTF8.GetBytes(Environment.NewLine + line); + + await target.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false); + await target.FlushAsync().ConfigureAwait(false); + } + } + } + catch (ObjectDisposedException) + { + // Don't spam the log. This doesn't seem to throw in windows, but sometimes under linux + } + catch (Exception ex) + { + _logger.ErrorException("Error reading ffmpeg log", ex); + } + } + /// <summary> /// Sets the ass font. /// </summary> |
