Browse Source

added subtitle seek on extract

Luke Pulverenti 12 years ago
parent
commit
7839a90c1a

+ 9 - 6
MediaBrowser.Api/Playback/BaseStreamingService.cs

@@ -290,7 +290,7 @@ namespace MediaBrowser.Api.Playback
         /// <returns>System.String.</returns>
         protected string GetTextSubtitleParam(Video video, MediaStream subtitleStream, long? startTimeTicks)
         {
-            var path = subtitleStream.IsExternal ? GetConvertedAssPath(video, subtitleStream) : GetExtractedAssPath(video, subtitleStream);
+            var path = subtitleStream.IsExternal ? GetConvertedAssPath(video, subtitleStream) : GetExtractedAssPath(video, subtitleStream, startTimeTicks);
 
             if (string.IsNullOrEmpty(path))
             {
@@ -299,7 +299,7 @@ namespace MediaBrowser.Api.Playback
 
             var param = string.Format(",ass='{0}'", path.Replace('\\', '/').Replace(":/", "\\:/"));
 
-            if (startTimeTicks.HasValue)
+            if (startTimeTicks.HasValue && subtitleStream.IsExternal)
             {
                 var seconds = Convert.ToInt32(TimeSpan.FromTicks(startTimeTicks.Value).TotalSeconds);
                 param += string.Format(",setpts=PTS-{0}/TB", seconds);
@@ -313,10 +313,13 @@ namespace MediaBrowser.Api.Playback
         /// </summary>
         /// <param name="video">The video.</param>
         /// <param name="subtitleStream">The subtitle stream.</param>
+        /// <param name="startTimeTicks">The start time ticks.</param>
         /// <returns>System.String.</returns>
-        private string GetExtractedAssPath(Video video, MediaStream subtitleStream)
+        private string GetExtractedAssPath(Video video, MediaStream subtitleStream, long? startTimeTicks)
         {
-            var path = Kernel.Instance.FFMpegManager.GetSubtitleCachePath(video, subtitleStream.Index, ".ass");
+            var offset = TimeSpan.FromTicks(startTimeTicks ?? 0);
+
+            var path = Kernel.Instance.FFMpegManager.GetSubtitleCachePath(video, subtitleStream.Index, offset, ".ass");
 
             if (!File.Exists(path))
             {
@@ -326,7 +329,7 @@ namespace MediaBrowser.Api.Playback
 
                 try
                 {
-                    var task = MediaEncoder.ExtractTextSubtitle(inputPath, type, subtitleStream.Index, path, CancellationToken.None);
+                    var task = MediaEncoder.ExtractTextSubtitle(inputPath, type, subtitleStream.Index, offset, path, CancellationToken.None);
 
                     Task.WaitAll(task);
                 }
@@ -347,7 +350,7 @@ namespace MediaBrowser.Api.Playback
         /// <returns>System.String.</returns>
         private string GetConvertedAssPath(Video video, MediaStream subtitleStream)
         {
-            var path = Kernel.Instance.FFMpegManager.GetSubtitleCachePath(video, subtitleStream.Index, ".ass");
+            var path = Kernel.Instance.FFMpegManager.GetSubtitleCachePath(video, subtitleStream.Index, null, ".ass");
 
             if (!File.Exists(path))
             {

+ 2 - 1
MediaBrowser.Common/MediaInfo/IMediaEncoder.cs

@@ -38,10 +38,11 @@ namespace MediaBrowser.Common.MediaInfo
         /// <param name="inputFiles">The input files.</param>
         /// <param name="type">The type.</param>
         /// <param name="subtitleStreamIndex">Index of the subtitle stream.</param>
+        /// <param name="offset">The offset.</param>
         /// <param name="outputPath">The output path.</param>
         /// <param name="cancellationToken">The cancellation token.</param>
         /// <returns>Task.</returns>
-        Task ExtractTextSubtitle(string[] inputFiles, InputType type, int subtitleStreamIndex, string outputPath, CancellationToken cancellationToken);
+        Task ExtractTextSubtitle(string[] inputFiles, InputType type, int subtitleStreamIndex, TimeSpan offset, string outputPath, CancellationToken cancellationToken);
 
         /// <summary>
         /// Converts the text subtitle to ass.

+ 6 - 3
MediaBrowser.Controller/MediaInfo/FFMpegManager.cs

@@ -30,7 +30,7 @@ namespace MediaBrowser.Controller.MediaInfo
         internal FileSystemRepository SubtitleCache { get; set; }
 
         private readonly ILibraryManager _libraryManager;
-        
+
         private readonly IServerApplicationPaths _appPaths;
         private readonly IMediaEncoder _encoder;
 
@@ -219,11 +219,14 @@ namespace MediaBrowser.Controller.MediaInfo
         /// </summary>
         /// <param name="input">The input.</param>
         /// <param name="subtitleStreamIndex">Index of the subtitle stream.</param>
+        /// <param name="offset">The offset.</param>
         /// <param name="outputExtension">The output extension.</param>
         /// <returns>System.String.</returns>
-        public string GetSubtitleCachePath(Video input, int subtitleStreamIndex, string outputExtension)
+        public string GetSubtitleCachePath(Video input, int subtitleStreamIndex, TimeSpan? offset, string outputExtension)
         {
-            return SubtitleCache.GetResourcePath(input.Id + "_" + subtitleStreamIndex + "_" + input.DateModified.Ticks, outputExtension);
+            var ticksParam = offset.HasValue ? "_" + offset.Value.Ticks : "";
+
+            return SubtitleCache.GetResourcePath(input.Id + "_" + subtitleStreamIndex + "_" + input.DateModified.Ticks + ticksParam, outputExtension);
         }
     }
 }

+ 9 - 9
MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs

@@ -24,15 +24,15 @@ namespace MediaBrowser.Server.Implementations.Library
     {
         public LuceneSearchEngine(IServerApplicationPaths serverPaths, ILogManager logManager)
         {
-            string luceneDbPath = serverPaths.DataPath + "\\SearchIndexDB";
-            if (!System.IO.Directory.Exists(luceneDbPath))
-                System.IO.Directory.CreateDirectory(luceneDbPath);
-            else if(File.Exists(luceneDbPath + "\\write.lock"))
-                    File.Delete(luceneDbPath + "\\write.lock");
+            //string luceneDbPath = serverPaths.DataPath + "\\SearchIndexDB";
+            //if (!System.IO.Directory.Exists(luceneDbPath))
+            //    System.IO.Directory.CreateDirectory(luceneDbPath);
+            //else if(File.Exists(luceneDbPath + "\\write.lock"))
+            //        File.Delete(luceneDbPath + "\\write.lock");
 
-            LuceneSearch.Init(luceneDbPath, logManager.GetLogger("Lucene"));
+            //LuceneSearch.Init(luceneDbPath, logManager.GetLogger("Lucene"));
 
-            BaseItem.LibraryManager.LibraryChanged += LibraryChanged;
+            //BaseItem.LibraryManager.LibraryChanged += LibraryChanged;
         }
 
         public void LibraryChanged(object source, ChildrenChangedEventArgs changeInformation)
@@ -75,9 +75,9 @@ namespace MediaBrowser.Server.Implementations.Library
 
         public void Dispose()
         {
-            BaseItem.LibraryManager.LibraryChanged -= LibraryChanged;
+            //BaseItem.LibraryManager.LibraryChanged -= LibraryChanged;
 
-            LuceneSearch.CloseAll();
+            //LuceneSearch.CloseAll();
         }
     }