added subtitle seek on extract

This commit is contained in:
Luke Pulverenti 2013-04-23 20:25:49 -04:00
parent ebd26e59f0
commit 7839a90c1a
4 changed files with 26 additions and 19 deletions

View File

@ -290,7 +290,7 @@ namespace MediaBrowser.Api.Playback
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
protected string GetTextSubtitleParam(Video video, MediaStream subtitleStream, long? startTimeTicks) 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)) if (string.IsNullOrEmpty(path))
{ {
@ -299,7 +299,7 @@ namespace MediaBrowser.Api.Playback
var param = string.Format(",ass='{0}'", path.Replace('\\', '/').Replace(":/", "\\:/")); 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); var seconds = Convert.ToInt32(TimeSpan.FromTicks(startTimeTicks.Value).TotalSeconds);
param += string.Format(",setpts=PTS-{0}/TB", seconds); param += string.Format(",setpts=PTS-{0}/TB", seconds);
@ -313,10 +313,13 @@ namespace MediaBrowser.Api.Playback
/// </summary> /// </summary>
/// <param name="video">The video.</param> /// <param name="video">The video.</param>
/// <param name="subtitleStream">The subtitle stream.</param> /// <param name="subtitleStream">The subtitle stream.</param>
/// <param name="startTimeTicks">The start time ticks.</param>
/// <returns>System.String.</returns> /// <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)) if (!File.Exists(path))
{ {
@ -326,7 +329,7 @@ namespace MediaBrowser.Api.Playback
try 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); Task.WaitAll(task);
} }
@ -347,7 +350,7 @@ namespace MediaBrowser.Api.Playback
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
private string GetConvertedAssPath(Video video, MediaStream subtitleStream) 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)) if (!File.Exists(path))
{ {

View File

@ -38,10 +38,11 @@ namespace MediaBrowser.Common.MediaInfo
/// <param name="inputFiles">The input files.</param> /// <param name="inputFiles">The input files.</param>
/// <param name="type">The type.</param> /// <param name="type">The type.</param>
/// <param name="subtitleStreamIndex">Index of the subtitle stream.</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="outputPath">The output path.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns> /// <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> /// <summary>
/// Converts the text subtitle to ass. /// Converts the text subtitle to ass.

View File

@ -30,7 +30,7 @@ namespace MediaBrowser.Controller.MediaInfo
internal FileSystemRepository SubtitleCache { get; set; } internal FileSystemRepository SubtitleCache { get; set; }
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IServerApplicationPaths _appPaths; private readonly IServerApplicationPaths _appPaths;
private readonly IMediaEncoder _encoder; private readonly IMediaEncoder _encoder;
@ -219,11 +219,14 @@ namespace MediaBrowser.Controller.MediaInfo
/// </summary> /// </summary>
/// <param name="input">The input.</param> /// <param name="input">The input.</param>
/// <param name="subtitleStreamIndex">Index of the subtitle stream.</param> /// <param name="subtitleStreamIndex">Index of the subtitle stream.</param>
/// <param name="offset">The offset.</param>
/// <param name="outputExtension">The output extension.</param> /// <param name="outputExtension">The output extension.</param>
/// <returns>System.String.</returns> /// <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);
} }
} }
} }

View File

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