fixed subtitle offsets

pull/702/head
Luke Pulverenti 12 years ago
parent 921e4528ff
commit 40c2b73d63

@ -290,22 +290,14 @@ 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, startTimeTicks);
var path = subtitleStream.IsExternal ? GetConvertedAssPath(video, subtitleStream, startTimeTicks) : GetExtractedAssPath(video, subtitleStream, startTimeTicks);
if (string.IsNullOrEmpty(path))
{
return string.Empty;
}
var param = string.Format(",ass='{0}'", path.Replace('\\', '/').Replace(":/", "\\:/"));
if (startTimeTicks.HasValue && subtitleStream.IsExternal)
{
var seconds = Convert.ToInt32(TimeSpan.FromTicks(startTimeTicks.Value).TotalSeconds);
param += string.Format(",setpts=PTS-{0}/TB", seconds);
}
return param;
return string.Format(",ass='{0}'", path.Replace('\\', '/').Replace(":/", "\\:/"));
}
/// <summary>
@ -347,16 +339,21 @@ 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 GetConvertedAssPath(Video video, MediaStream subtitleStream)
private string GetConvertedAssPath(Video video, MediaStream subtitleStream, long? startTimeTicks)
{
var path = Kernel.Instance.FFMpegManager.GetSubtitleCachePath(video, subtitleStream.Index, null, ".ass");
var offset = startTimeTicks.HasValue
? TimeSpan.FromTicks(startTimeTicks.Value)
: TimeSpan.FromTicks(0);
var path = Kernel.Instance.FFMpegManager.GetSubtitleCachePath(video, subtitleStream.Index, offset, ".ass");
if (!File.Exists(path))
{
try
{
var task = MediaEncoder.ConvertTextSubtitleToAss(subtitleStream.Path, path, CancellationToken.None);
var task = MediaEncoder.ConvertTextSubtitleToAss(subtitleStream.Path, path, offset, CancellationToken.None);
Task.WaitAll(task);
}

@ -49,9 +49,10 @@ namespace MediaBrowser.Common.MediaInfo
/// </summary>
/// <param name="inputPath">The input path.</param>
/// <param name="outputPath">The output path.</param>
/// <param name="offset">The offset.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
Task ConvertTextSubtitleToAss(string inputPath, string outputPath, CancellationToken cancellationToken);
Task ConvertTextSubtitleToAss(string inputPath, string outputPath, TimeSpan offset, CancellationToken cancellationToken);
/// <summary>
/// Gets the media info.

@ -535,13 +535,14 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
/// </summary>
/// <param name="inputPath">The input path.</param>
/// <param name="outputPath">The output path.</param>
/// <param name="offset">The offset.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">inputPath
/// or
/// outputPath</exception>
/// <exception cref="System.ApplicationException"></exception>
public async Task ConvertTextSubtitleToAss(string inputPath, string outputPath, CancellationToken cancellationToken)
public async Task ConvertTextSubtitleToAss(string inputPath, string outputPath, TimeSpan offset, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(inputPath))
{

Loading…
Cancel
Save