|
|
|
@ -194,15 +194,17 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
|
|
|
MediaStream subtitleStream,
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
const string extractedFormat = "srt";
|
|
|
|
|
|
|
|
|
|
if (!subtitleStream.IsExternal)
|
|
|
|
|
{
|
|
|
|
|
// Extract
|
|
|
|
|
var outputPath = GetSubtitleCachePath(mediaPath, subtitleStream.Index, ".ass");
|
|
|
|
|
var outputPath = GetSubtitleCachePath(mediaPath, subtitleStream.Index, "." + extractedFormat);
|
|
|
|
|
|
|
|
|
|
await ExtractTextSubtitle(inputFiles, protocol, subtitleStream.Index, false, outputPath, cancellationToken)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return new Tuple<string, string>(outputPath, "ass");
|
|
|
|
|
return new Tuple<string, string>(outputPath, extractedFormat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var currentFormat = (Path.GetExtension(subtitleStream.Path) ?? subtitleStream.Codec)
|
|
|
|
@ -211,12 +213,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
|
|
|
if (GetReader(currentFormat, false) == null)
|
|
|
|
|
{
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
|
return new Tuple<string, string>(outputPath, "ass");
|
|
|
|
|
return new Tuple<string, string>(outputPath, extractedFormat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Tuple<string, string>(subtitleStream.Path, currentFormat);
|
|
|
|
@ -303,14 +305,14 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converts the text subtitle to ass.
|
|
|
|
|
/// Converts the text subtitle to SRT.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="inputPath">The input path.</param>
|
|
|
|
|
/// <param name="outputPath">The output path.</param>
|
|
|
|
|
/// <param name="language">The language.</param>
|
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
|
|
|
|
var semaphore = GetLock(outputPath);
|
|
|
|
@ -321,7 +323,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(outputPath))
|
|
|
|
|
{
|
|
|
|
|
await ConvertTextSubtitleToAssInternal(inputPath, outputPath, language).ConfigureAwait(false);
|
|
|
|
|
await ConvertTextSubtitleToSrtInternal(inputPath, outputPath, language).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
@ -331,17 +333,19 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converts the text subtitle to ass.
|
|
|
|
|
/// Converts the text subtitle to SRT internal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="inputPath">The input path.</param>
|
|
|
|
|
/// <param name="outputPath">The output path.</param>
|
|
|
|
|
/// <param name="language">The language.</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException">inputPath
|
|
|
|
|
/// <exception cref="System.ArgumentNullException">
|
|
|
|
|
/// inputPath
|
|
|
|
|
/// or
|
|
|
|
|
/// outputPath</exception>
|
|
|
|
|
/// outputPath
|
|
|
|
|
/// </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))
|
|
|
|
|
{
|
|
|
|
@ -375,7 +379,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
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,
|
|
|
|
|
ErrorDialog = false
|
|
|
|
@ -529,7 +533,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if (copySubtitleStream)
|
|
|
|
|