external subtitle fixes

pull/702/head
Luke Pulverenti 11 years ago
parent 5416be3cd0
commit e8bb5c4b9a

@ -390,7 +390,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
{ {
if (!File.Exists(outputPath)) if (!File.Exists(outputPath))
{ {
await ConvertTextSubtitleToAssInternal(inputPath, outputPath, language, offset, cancellationToken).ConfigureAwait(false); await ConvertTextSubtitleToAssInternal(inputPath, outputPath, language, offset).ConfigureAwait(false);
} }
} }
finally finally
@ -399,6 +399,8 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
} }
} }
private const int FastSeekOffsetSeconds = 1;
/// <summary> /// <summary>
/// Converts the text subtitle to ass. /// Converts the text subtitle to ass.
/// </summary> /// </summary>
@ -406,14 +408,12 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
/// <param name="outputPath">The output path.</param> /// <param name="outputPath">The output path.</param>
/// <param name="language">The language.</param> /// <param name="language">The language.</param>
/// <param name="offset">The offset.</param> /// <param name="offset">The offset.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">inputPath /// <exception cref="System.ArgumentNullException">inputPath
/// or /// or
/// outputPath</exception> /// outputPath</exception>
/// <exception cref="System.ApplicationException"></exception> /// <exception cref="System.ApplicationException"></exception>
private async Task ConvertTextSubtitleToAssInternal(string inputPath, string outputPath, string language, TimeSpan offset, private async Task ConvertTextSubtitleToAssInternal(string inputPath, string outputPath, string language, TimeSpan offset)
CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(inputPath)) if (string.IsNullOrEmpty(inputPath))
{ {
@ -425,7 +425,8 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
throw new ArgumentNullException("outputPath"); throw new ArgumentNullException("outputPath");
} }
var slowSeekParam = offset.TotalSeconds > 0 ? " -ss " + offset.TotalSeconds.ToString(UsCulture) : string.Empty; var slowSeekParam = GetSlowSeekCommandLineParameter(offset);
var fastSeekParam = GetFastSeekCommandLineParameter(offset);
var encodingParam = string.IsNullOrEmpty(language) ? string.Empty : var encodingParam = string.IsNullOrEmpty(language) ? string.Empty :
GetSubtitleLanguageEncodingParam(language) + " "; GetSubtitleLanguageEncodingParam(language) + " ";
@ -441,8 +442,13 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
UseShellExecute = false, UseShellExecute = false,
FileName = FFMpegPath, FileName = FFMpegPath,
Arguments = Arguments =
string.Format("{0}-i \"{1}\"{2} \"{3}\"", encodingParam, inputPath, slowSeekParam, string.Format("{0}{1}-i \"{2}\"{3} \"{4}\"",
fastSeekParam,
encodingParam,
inputPath,
slowSeekParam,
outputPath), outputPath),
WindowStyle = ProcessWindowStyle.Hidden, WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false ErrorDialog = false
} }
@ -533,6 +539,28 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
await SetAssFont(outputPath).ConfigureAwait(false); await SetAssFont(outputPath).ConfigureAwait(false);
} }
protected string GetFastSeekCommandLineParameter(TimeSpan offset)
{
var seconds = offset.TotalSeconds - FastSeekOffsetSeconds;
if (seconds > 0)
{
return string.Format("-ss {0} ", seconds.ToString(UsCulture));
}
return string.Empty;
}
protected string GetSlowSeekCommandLineParameter(TimeSpan offset)
{
if (offset.TotalSeconds - FastSeekOffsetSeconds > 0)
{
return string.Format(" -ss {0}", FastSeekOffsetSeconds.ToString(UsCulture));
}
return string.Empty;
}
/// <summary> /// <summary>
/// Gets the subtitle language encoding param. /// Gets the subtitle language encoding param.
/// </summary> /// </summary>

Loading…
Cancel
Save