Extract subs to srt instead of ass

This commit is contained in:
Luke Pulverenti 2014-08-24 17:07:04 -04:00
parent 58a38d0d1d
commit d92936187d
1 changed files with 18 additions and 14 deletions

View File

@ -194,15 +194,17 @@ namespace MediaBrowser.MediaEncoding.Subtitles
MediaStream subtitleStream, MediaStream subtitleStream,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
const string extractedFormat = "srt";
if (!subtitleStream.IsExternal) if (!subtitleStream.IsExternal)
{ {
// Extract // Extract
var outputPath = GetSubtitleCachePath(mediaPath, subtitleStream.Index, ".ass"); var outputPath = GetSubtitleCachePath(mediaPath, subtitleStream.Index, "." + extractedFormat);
await ExtractTextSubtitle(inputFiles, protocol, subtitleStream.Index, false, outputPath, cancellationToken) await ExtractTextSubtitle(inputFiles, protocol, subtitleStream.Index, false, outputPath, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
return new Tuple<string, string>(outputPath, "ass"); return new Tuple<string, string>(outputPath, extractedFormat);
} }
var currentFormat = (Path.GetExtension(subtitleStream.Path) ?? subtitleStream.Codec) var currentFormat = (Path.GetExtension(subtitleStream.Path) ?? subtitleStream.Codec)
@ -211,12 +213,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles
if (GetReader(currentFormat, false) == null) if (GetReader(currentFormat, false) == null)
{ {
// Convert // Convert
var outputPath = GetSubtitleCachePath(mediaPath, subtitleStream.Index, ".ass"); var outputPath = GetSubtitleCachePath(mediaPath, subtitleStream.Index, "." + extractedFormat);
await ConvertTextSubtitleToAss(subtitleStream.Path, outputPath, subtitleStream.Language, cancellationToken) await ConvertTextSubtitleToSrt(subtitleStream.Path, outputPath, subtitleStream.Language, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
return new Tuple<string, string>(outputPath, "ass"); return new Tuple<string, string>(outputPath, extractedFormat);
} }
return new Tuple<string, string>(subtitleStream.Path, currentFormat); return new Tuple<string, string>(subtitleStream.Path, currentFormat);
@ -303,14 +305,14 @@ namespace MediaBrowser.MediaEncoding.Subtitles
} }
/// <summary> /// <summary>
/// Converts the text subtitle to ass. /// Converts the text subtitle to SRT.
/// </summary> /// </summary>
/// <param name="inputPath">The input path.</param> /// <param name="inputPath">The input path.</param>
/// <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="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
public async Task ConvertTextSubtitleToAss(string inputPath, string outputPath, string language, public async Task ConvertTextSubtitleToSrt(string inputPath, string outputPath, string language,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var semaphore = GetLock(outputPath); var semaphore = GetLock(outputPath);
@ -321,7 +323,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{ {
if (!File.Exists(outputPath)) if (!File.Exists(outputPath))
{ {
await ConvertTextSubtitleToAssInternal(inputPath, outputPath, language).ConfigureAwait(false); await ConvertTextSubtitleToSrtInternal(inputPath, outputPath, language).ConfigureAwait(false);
} }
} }
finally finally
@ -331,17 +333,19 @@ namespace MediaBrowser.MediaEncoding.Subtitles
} }
/// <summary> /// <summary>
/// Converts the text subtitle to ass. /// Converts the text subtitle to SRT internal.
/// </summary> /// </summary>
/// <param name="inputPath">The input path.</param> /// <param name="inputPath">The input path.</param>
/// <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>
/// <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) private async Task ConvertTextSubtitleToSrtInternal(string inputPath, string outputPath, string language)
{ {
if (string.IsNullOrEmpty(inputPath)) if (string.IsNullOrEmpty(inputPath))
{ {
@ -375,7 +379,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
CreateNoWindow = true, CreateNoWindow = true,
UseShellExecute = false, UseShellExecute = false,
FileName = _mediaEncoder.EncoderPath, FileName = _mediaEncoder.EncoderPath,
Arguments = string.Format("{0} -i \"{1}\" -c:s ass \"{2}\"", encodingParam, inputPath, outputPath), Arguments = string.Format("{0} -i \"{1}\" -c:s srt \"{2}\"", encodingParam, inputPath, outputPath),
WindowStyle = ProcessWindowStyle.Hidden, WindowStyle = ProcessWindowStyle.Hidden,
ErrorDialog = false ErrorDialog = false
@ -529,7 +533,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
var processArgs = string.Format("-i {0} -map 0:{1} -an -vn -c:s ass \"{2}\"", inputPath, var processArgs = string.Format("-i {0} -map 0:{1} -an -vn -c:s srt \"{2}\"", inputPath,
subtitleStreamIndex, outputPath); subtitleStreamIndex, outputPath);
if (copySubtitleStream) if (copySubtitleStream)