Improve support for S_HDMV/TEXTST in MKV - thx ipsi :)

Work on #8039
This commit is contained in:
Nikolaj Olsson 2024-03-21 07:13:28 +01:00
parent 0333813033
commit a6aaca56df
4 changed files with 65 additions and 27 deletions

View File

@ -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<MatroskaSubtitle> 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];

View File

@ -824,6 +824,7 @@ namespace Nikse.SubtitleEdit.Forms
var mkvSrt = new List<string>();
var mkvSsa = new List<string>();
var mkvAss = new List<string>();
var mkvTextST = new List<string>();
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;
}

View File

@ -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,26 +15077,7 @@ 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)
{

View File

@ -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))
{