From dacdfd272a76ea46abaff1d649c8d936896bdab3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 20 Feb 2016 01:57:17 -0500 Subject: [PATCH] fix subtitle position after seek in chrome --- .../Playback/BaseStreamingService.cs | 16 ++++++++++++++-- .../Playback/Progressive/VideoService.cs | 4 ++-- MediaBrowser.Api/Playback/StreamRequest.cs | 3 +++ .../MediaEncoding/EncodingJobOptions.cs | 1 + .../Encoder/EncodingJobFactory.cs | 2 ++ MediaBrowser.Model/Dlna/StreamBuilder.cs | 1 + MediaBrowser.Model/Dlna/StreamInfo.cs | 5 ++++- MediaBrowser.Model/Dlna/TranscodingProfile.cs | 3 +++ 8 files changed, 30 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index bae8074fd4..33995bee3d 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1462,6 +1462,13 @@ namespace MediaBrowser.Api.Playback { // Duplicating ItemId because of MediaMonkey } + else if (i == 24) + { + if (videoRequest != null) + { + videoRequest.CopyTimestamps = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); + } + } } } @@ -2021,6 +2028,11 @@ namespace MediaBrowser.Api.Playback state.EstimateContentLength = transcodingProfile.EstimateContentLength; state.EnableMpegtsM2TsMode = transcodingProfile.EnableMpegtsM2TsMode; state.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo; + + if (state.VideoRequest != null) + { + state.VideoRequest.CopyTimestamps = transcodingProfile.CopyTimestamps; + } } } } @@ -2184,9 +2196,9 @@ namespace MediaBrowser.Api.Playback if (state.VideoRequest != null) { - if (string.Equals(state.OutputContainer, "mkv", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(state.OutputContainer, "mkv", StringComparison.OrdinalIgnoreCase) && state.VideoRequest.CopyTimestamps) { - //inputModifier += " -noaccurate_seek"; + inputModifier += " -noaccurate_seek"; } } diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index eaf65bd6b6..50aa2df19c 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -137,9 +137,9 @@ namespace MediaBrowser.Api.Playback.Progressive var isOutputMkv = string.Equals(state.OutputContainer, "mkv", StringComparison.OrdinalIgnoreCase); - if (state.RunTimeTicks.HasValue) + if (state.RunTimeTicks.HasValue && state.VideoRequest.CopyTimestamps) { - //args += " -copyts -avoid_negative_ts disabled -start_at_zero"; + args += " -copyts -avoid_negative_ts disabled -start_at_zero"; } if (string.Equals(videoCodec, "copy", StringComparison.OrdinalIgnoreCase)) diff --git a/MediaBrowser.Api/Playback/StreamRequest.cs b/MediaBrowser.Api/Playback/StreamRequest.cs index 69f8e6e046..1135a3a54d 100644 --- a/MediaBrowser.Api/Playback/StreamRequest.cs +++ b/MediaBrowser.Api/Playback/StreamRequest.cs @@ -187,6 +187,9 @@ namespace MediaBrowser.Api.Playback [ApiMember(Name = "EnableAutoStreamCopy", Description = "Whether or not to allow automatic stream copy if requested values match the original source. Defaults to true.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] public bool EnableAutoStreamCopy { get; set; } + [ApiMember(Name = "CopyTimestamps", Description = "Whether or not to copy timestamps when transcoding with an offset. Defaults to false.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] + public bool CopyTimestamps { get; set; } + [ApiMember(Name = "Cabac", Description = "Enable if cabac encoding is required", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] public bool? Cabac { get; set; } diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs b/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs index bb8841222a..f8f4e9ec9f 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs @@ -44,6 +44,7 @@ namespace MediaBrowser.Controller.MediaEncoding public int? CpuCoreLimit { get; set; } public bool ReadInputAtNativeFramerate { get; set; } public SubtitleDeliveryMethod SubtitleMethod { get; set; } + public bool CopyTimestamps { get; set; } /// /// Gets a value indicating whether this instance has fixed resolution. diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs index 252386af0c..c64b574a9b 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs @@ -794,6 +794,8 @@ namespace MediaBrowser.MediaEncoding.Encoder state.EstimateContentLength = transcodingProfile.EstimateContentLength; state.EnableMpegtsM2TsMode = transcodingProfile.EnableMpegtsM2TsMode; state.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo; + + state.Options.CopyTimestamps = transcodingProfile.CopyTimestamps; } } } diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index c2713a6e7c..d4ca379c03 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -425,6 +425,7 @@ namespace MediaBrowser.Model.Dlna playlistItem.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo; playlistItem.AudioCodec = transcodingProfile.AudioCodec.Split(',')[0]; playlistItem.VideoCodec = transcodingProfile.VideoCodec; + playlistItem.CopyTimestamps = transcodingProfile.CopyTimestamps; playlistItem.SubProtocol = transcodingProfile.Protocol; playlistItem.AudioStreamIndex = audioStreamIndex; diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs index f5c54e160a..79ee1b5c58 100644 --- a/MediaBrowser.Model/Dlna/StreamInfo.cs +++ b/MediaBrowser.Model/Dlna/StreamInfo.cs @@ -32,6 +32,7 @@ namespace MediaBrowser.Model.Dlna public string VideoProfile { get; set; } public bool? Cabac { get; set; } + public bool CopyTimestamps { get; set; } public string AudioCodec { get; set; } public int? AudioStreamIndex { get; set; } @@ -231,6 +232,8 @@ namespace MediaBrowser.Model.Dlna { list.Add(new NameValuePair("ItemId", item.ItemId)); } + + list.Add(new NameValuePair("CopyTimestamps", (item.CopyTimestamps).ToString().ToLower())); return list; } @@ -269,7 +272,7 @@ namespace MediaBrowser.Model.Dlna // HLS will preserve timestamps so we can just grab the full subtitle stream long startPositionTicks = StringHelper.EqualsIgnoreCase(SubProtocol, "hls") ? 0 - : (this.PlayMethod == PlayMethod.Transcode ? StartPositionTicks : 0); + : (PlayMethod == PlayMethod.Transcode && !CopyTimestamps ? StartPositionTicks : 0); // First add the selected track if (SubtitleStreamIndex.HasValue) diff --git a/MediaBrowser.Model/Dlna/TranscodingProfile.cs b/MediaBrowser.Model/Dlna/TranscodingProfile.cs index d9963eb750..e59ee6d634 100644 --- a/MediaBrowser.Model/Dlna/TranscodingProfile.cs +++ b/MediaBrowser.Model/Dlna/TranscodingProfile.cs @@ -29,6 +29,9 @@ namespace MediaBrowser.Model.Dlna [XmlAttribute("transcodeSeekInfo")] public TranscodeSeekInfo TranscodeSeekInfo { get; set; } + [XmlAttribute("copyTimestamps")] + public bool CopyTimestamps { get; set; } + [XmlAttribute("context")] public EncodingContext Context { get; set; }