diff --git a/src/libse/Common/Utilities.cs b/src/libse/Common/Utilities.cs index 6d757823f..c0b4b4351 100644 --- a/src/libse/Common/Utilities.cs +++ b/src/libse/Common/Utilities.cs @@ -14,6 +14,7 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Xml; +using Nikse.SubtitleEdit.Core.VobSub; namespace Nikse.SubtitleEdit.Core.Common { @@ -2799,6 +2800,30 @@ namespace Nikse.SubtitleEdit.Core.Common return format; } + public static void ParseMatroskaTextSt(MatroskaTrackInfo trackInfo, List subtitleLines, Subtitle subtitle) + { + for (var indexTextSt = 0; indexTextSt < subtitleLines.Count; indexTextSt++) + { + try + { + var matroskaSubtitle = subtitleLines[indexTextSt]; + var idx = -6; // MakeMKV starts at DialogPresentationSegment + var data = matroskaSubtitle.GetData(trackInfo); + if (VobSubParser.IsPrivateStream2(data, 0)) + { + idx = 0; // starts with MPEG2 private stream 2 (just to be sure) + } + + var dps = new TextST.DialogPresentationSegment(data, idx); + subtitle.Paragraphs[indexTextSt].Text = dps.Text; + } + catch (Exception exception) + { + subtitle.Paragraphs[indexTextSt].Text = exception.Message; + } + } + } + private static void FixShortDisplayTime(Subtitle s, int i) { Paragraph p = s.Paragraphs[i]; diff --git a/src/ui/Forms/BatchConvert.cs b/src/ui/Forms/BatchConvert.cs index 467553b95..d61fb0819 100644 --- a/src/ui/Forms/BatchConvert.cs +++ b/src/ui/Forms/BatchConvert.cs @@ -824,6 +824,7 @@ namespace Nikse.SubtitleEdit.Forms var mkvSrt = new List(); var mkvSsa = new List(); var mkvAss = new List(); + var mkvTextST = new List(); var mkvCount = 0; var isTs = false; var isMp4 = false; @@ -912,11 +913,15 @@ namespace Nikse.SubtitleEdit.Forms { mkvAss.Add(MakeMkvTrackInfoString(track)); } + else if (track.CodecId.Equals("S_HDMV/TEXTST", StringComparison.OrdinalIgnoreCase)) + { + mkvTextST.Add(MakeMkvTrackInfoString(track)); + } } } } - if (mkvVobSub.Count + mkvPgs.Count + mkvSrt.Count + mkvSsa.Count + mkvAss.Count <= 0) + if (mkvVobSub.Count + mkvPgs.Count + mkvSrt.Count + mkvSsa.Count + mkvAss.Count + mkvTextST.Count <= 0) { item.SubItems.Add(LanguageSettings.Current.UnknownSubtitle.Title); } @@ -974,7 +979,8 @@ namespace Nikse.SubtitleEdit.Forms { "VobSub", mkvVobSub }, { "SRT", mkvSrt }, { "SSA", mkvSsa }, - { "ASS", mkvAss } + { "ASS", mkvAss }, + { "TextST", mkvTextST }, }; foreach (var mkvSubFormat in mkvSubFormats) @@ -1559,6 +1565,26 @@ namespace Nikse.SubtitleEdit.Forms fromFormat = new AdvancedSubStationAlpha(); } + mkvFileNames.Add(fileName); + break; + } + } + else if (track.CodecId.Equals("S_HDMV/TEXTST", StringComparison.OrdinalIgnoreCase)) + { + if (trackId == track.TrackNumber.ToString(CultureInfo.InvariantCulture)) + { + var mkvSub = matroska.GetSubtitle(track.TrackNumber, null); + Utilities.LoadMatroskaTextSubtitle(track, matroska, mkvSub, sub); + Utilities.ParseMatroskaTextSt(track, mkvSub, sub); + + fileName = fileName.Substring(0, fileName.LastIndexOf('.')) + "." + GetMkvLanguage(track.Language).Replace("undefined.", string.Empty) + "mkv"; + if (mkvFileNames.Contains(fileName)) + { + fileName = fileName.Substring(0, fileName.LastIndexOf('.')) + ".#" + trackId + "." + GetMkvLanguage(track.Language) + "mkv"; + } + + fromFormat = new SubRip(); + mkvFileNames.Add(fileName); break; } diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index 7325470c4..187a4991b 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -47,6 +47,7 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar; using CheckForUpdatesHelper = Nikse.SubtitleEdit.Logic.CheckForUpdatesHelper; using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox; using Timer = System.Windows.Forms.Timer; @@ -15076,27 +15077,8 @@ namespace Nikse.SubtitleEdit.Forms _subtitle.Paragraphs.Clear(); Utilities.LoadMatroskaTextSubtitle(matroskaSubtitleInfo, matroska, sub, _subtitle); - for (int index = 0; index < sub.Count; index++) - { - try - { - var msub = sub[index]; - int idx = -6; // MakeMKV starts at DialogPresentationSegment - var data = msub.GetData(matroskaSubtitleInfo); - if (VobSubParser.IsPrivateStream2(data, 0)) - { - idx = 0; // starts with MPEG2 private stream 2 (just to be sure) - } - - var dps = new TextST.DialogPresentationSegment(data, idx); - _subtitle.Paragraphs[index].Text = dps.Text; - } - catch (Exception exception) - { - _subtitle.Paragraphs[index].Text = exception.Message; - } - } - + Utilities.ParseMatroskaTextSt(matroskaSubtitleInfo, sub, _subtitle); + if (_networkSession == null) { SubtitleListview1.HideColumn(SubtitleListView.SubtitleColumn.Extra); diff --git a/src/ui/Logic/CommandLineConvert/CommandLineConverter.cs b/src/ui/Logic/CommandLineConvert/CommandLineConverter.cs index e9f1001af..7ab44eaf2 100644 --- a/src/ui/Logic/CommandLineConvert/CommandLineConverter.cs +++ b/src/ui/Logic/CommandLineConvert/CommandLineConverter.cs @@ -13,7 +13,7 @@ using Nikse.SubtitleEdit.Logic.Ocr; using System; using System.Collections.Generic; using System.Drawing; -using System.Drawing.Imaging; +using System.Drawing.Imaging; using System.Globalization; using System.IO; using System.Linq; @@ -671,6 +671,11 @@ namespace Nikse.SubtitleEdit.Logic.CommandLineConvert var ss = matroska.GetSubtitle(track.TrackNumber, null); format = Utilities.LoadMatroskaTextSubtitle(track, matroska, ss, sub); + if (track.CodecId.Contains("S_HDMV/TEXTST", StringComparison.OrdinalIgnoreCase)) + { + Utilities.ParseMatroskaTextSt(track, ss, sub); + } + var newFileName = fileName.Substring(0, fileName.LastIndexOf('.')) + "." + lang + ".mkv"; if (!mkvFileNames.Add(newFileName)) { @@ -723,7 +728,7 @@ namespace Nikse.SubtitleEdit.Logic.CommandLineConvert else if (!done && FileUtil.IsVobSub(fileName)) { _stdOutWriter.WriteLine("Found VobSub subtitle format"); - ConvertVobSubSubtitle(fileName, targetFormat, offset, deleteContains, targetEncoding, outputFolder, targetFileName, count, ref converted, ref errors, formats, overwrite, pacCodePage, targetFrameRate, multipleReplaceImportFiles, actions, forcedOnly, ocrEngine, ocrDb, renumber: renumber, adjustDurationMs: adjustDurationMs); + ConvertVobSubSubtitle(fileName, targetFormat, offset, deleteContains, targetEncoding, outputFolder, targetFileName, count, ref converted, ref errors, formats, overwrite, pacCodePage, targetFrameRate, multipleReplaceImportFiles, actions, forcedOnly, ocrEngine, ocrDb, renumber: renumber, adjustDurationMs: adjustDurationMs); done = true; } @@ -1749,11 +1754,11 @@ namespace Nikse.SubtitleEdit.Logic.CommandLineConvert using (var binarySubtitleFile = new FileStream(outputFileName, FileMode.Create)) { var isImageBased = IsImageBased(format); - + List bin = null; if (bin != null) { - bin = binaryParagraphs.Cast().ToList(); + bin = binaryParagraphs.Cast().ToList(); } BdSupSaver.SaveBdSup(fileName, sub, bin, form, width, height, isImageBased, binarySubtitleFile, format, cancellationToken);