EBU long texts
This commit is contained in:
Nikolaj Olsson 2024-10-26 18:51:09 +02:00
parent 0913c8d72a
commit bee041bf27
3 changed files with 84 additions and 33 deletions

View File

@ -36,6 +36,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Groq/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Groq/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Immersive/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Immersive/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Imsc/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Imsc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lappish/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Libre/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Libre/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Matroska/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Matroska/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nikse/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Nikse/@EntryIndexedValue">True</s:Boolean>
@ -43,6 +44,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nuendo/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Nuendo/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ollama/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Ollama/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Persistable/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Persistable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Programme/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Purfview/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Purfview/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Spectrograms/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Spectrograms/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stbl/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Stbl/@EntryIndexedValue">True</s:Boolean>
@ -54,4 +56,5 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Undocked/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Undocked/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unescape/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Unescape/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Vanc/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Vanc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Vosk/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> <s:Boolean x:Key="/Default/UserDictionary/Words/=Vosk/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Wallon/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -168,7 +168,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
return 60.0; return 60.0;
} }
return 30.0; // should be DiskFormatcode STL30.01 return 30.0; // should be DiskFormatCode STL30.01
} }
} }
@ -282,34 +282,28 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
CommentFlag = 0; CommentFlag = 0;
} }
public byte[] GetBytes(EbuGeneralSubtitleInformation header) public byte[] GetBytesExtra(EbuGeneralSubtitleInformation header, MemoryStream extra)
{ {
var buffer = new byte[128]; // Text and Timing Information (TTI) block consists of 128 bytes var buffer = SaveHeader(header);
var bytes = extra.ToArray();
for (var i = 0; i < 112; i++)
{
if (i < bytes.Length)
{
buffer[16 + i] = bytes[i];
}
else
{
buffer[16 + i] = 0x8f;
}
}
buffer[0] = SubtitleGroupNumber; return buffer;
var temp = BitConverter.GetBytes(SubtitleNumber); }
buffer[1] = temp[0];
buffer[2] = temp[1];
buffer[3] = ExtensionBlockNumber;
buffer[4] = CumulativeStatus;
var frames = GetFrameFromMilliseconds(TimeCodeInMilliseconds, header.FrameRate, out var extraSeconds); public byte[] GetBytes(EbuGeneralSubtitleInformation header, MemoryStream extra)
var tc = new TimeCode(TimeCodeInHours, TimeCodeInMinutes, TimeCodeInSeconds + extraSeconds, 0); {
buffer[5] = (byte)tc.Hours; var buffer = SaveHeader(header);
buffer[6] = (byte)tc.Minutes;
buffer[7] = (byte)tc.Seconds;
buffer[8] = frames;
frames = GetFrameFromMilliseconds(TimeCodeOutMilliseconds, header.FrameRate, out extraSeconds);
tc = new TimeCode(TimeCodeOutHours, TimeCodeOutMinutes, TimeCodeOutSeconds + extraSeconds, 0);
buffer[9] = (byte)tc.Hours;
buffer[10] = (byte)tc.Minutes;
buffer[11] = (byte)tc.Seconds;
buffer[12] = frames;
buffer[13] = VerticalPosition;
buffer[14] = JustificationCode;
buffer[15] = CommentFlag;
var encoding = GetEncoding(header.CodePageNumber); var encoding = GetEncoding(header.CodePageNumber);
if (header.LanguageCode == LanguageCodeChinese) if (header.LanguageCode == LanguageCodeChinese)
@ -340,6 +334,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
} }
} }
if (byteList.Count > 112)
{
extra.Write(byteList.ToArray(), 112, byteList.Count - 112);
}
return buffer; return buffer;
} }
@ -572,6 +571,43 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
buffer[16 + i] = 0x8f; buffer[16 + i] = 0x8f;
} }
} }
if (bytes.Length > 112)
{
extra.Write(bytes, 112, bytes.Length - 112);
}
return buffer;
}
private byte[] SaveHeader(EbuGeneralSubtitleInformation header)
{
var buffer = new byte[128]; // Text and Timing Information (TTI) block consists of 128 bytes
buffer[0] = SubtitleGroupNumber;
var temp = BitConverter.GetBytes(SubtitleNumber);
buffer[1] = temp[0];
buffer[2] = temp[1];
buffer[3] = ExtensionBlockNumber;
buffer[4] = CumulativeStatus;
var frames = GetFrameFromMilliseconds(TimeCodeInMilliseconds, header.FrameRate, out var extraSeconds);
var tc = new TimeCode(TimeCodeInHours, TimeCodeInMinutes, TimeCodeInSeconds + extraSeconds, 0);
buffer[5] = (byte)tc.Hours;
buffer[6] = (byte)tc.Minutes;
buffer[7] = (byte)tc.Seconds;
buffer[8] = frames;
frames = GetFrameFromMilliseconds(TimeCodeOutMilliseconds, header.FrameRate, out extraSeconds);
tc = new TimeCode(TimeCodeOutHours, TimeCodeOutMinutes, TimeCodeOutSeconds + extraSeconds, 0);
buffer[9] = (byte)tc.Hours;
buffer[10] = (byte)tc.Minutes;
buffer[11] = (byte)tc.Seconds;
buffer[12] = frames;
buffer[13] = VerticalPosition;
buffer[14] = JustificationCode;
buffer[15] = CommentFlag;
return buffer; return buffer;
} }
@ -1532,8 +1568,20 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
tti.TimeCodeOutMilliseconds = p.EndTime.Milliseconds; tti.TimeCodeOutMilliseconds = p.EndTime.Milliseconds;
} }
buffer = tti.GetBytes(header); var extra = new MemoryStream();
stream.Write(buffer, 0, buffer.Length); buffer = tti.GetBytes(header, extra);
if (extra.Length > 0)
{
buffer[3] = 0; // ExtensionBlockNumber
stream.Write(buffer, 0, buffer.Length);
buffer = tti.GetBytesExtra(header, extra);
stream.Write(buffer, 0, buffer.Length);
}
else
{
stream.Write(buffer, 0, buffer.Length);
}
subtitleNumber++; subtitleNumber++;
} }
return true; return true;
@ -1606,8 +1654,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{ {
try try
{ {
byte[] buffer = FileUtil.ReadAllBytesShared(fileName); var buffer = FileUtil.ReadAllBytesShared(fileName);
EbuGeneralSubtitleInformation header = ReadHeader(buffer); var header = ReadHeader(buffer);
if (header.DiskFormatCode.StartsWith("STL23", StringComparison.Ordinal) || if (header.DiskFormatCode.StartsWith("STL23", StringComparison.Ordinal) ||
header.DiskFormatCode.StartsWith("STL24", StringComparison.Ordinal) || header.DiskFormatCode.StartsWith("STL24", StringComparison.Ordinal) ||
header.DiskFormatCode.StartsWith("STL25", StringComparison.Ordinal) || header.DiskFormatCode.StartsWith("STL25", StringComparison.Ordinal) ||

View File

@ -2891,14 +2891,14 @@ can edit in same subtitle file (collaboration)",
ContinuationStyle = "Continuation style", ContinuationStyle = "Continuation style",
CpsLineLengthStyle = "Cps/line-length", CpsLineLengthStyle = "Cps/line-length",
CpsLineLengthStyleCalcAll = "Count all characters", CpsLineLengthStyleCalcAll = "Count all characters",
CpsLineLengthStyleCalcNoSpaceCpsOnly = "Count all except space, cps only", CpsLineLengthStyleCalcNoSpaceCpsOnly = "Count all except space, CPS only",
CpsLineLengthStyleCalcNoSpace = "Count all except space", CpsLineLengthStyleCalcNoSpace = "Count all except space",
CpsLineLengthStyleCalcCjk = "CJK 1, Latin 0.5", CpsLineLengthStyleCalcCjk = "CJK 1, Latin 0.5",
CpsLineLengthStyleCalcCjkNoSpace = "CJK 1, Latin 0.5, space 0", CpsLineLengthStyleCalcCjkNoSpace = "CJK 1, Latin 0.5, space 0",
CpsLineLengthStyleCalcIncludeCompositionCharacters = "Include composition characters", CpsLineLengthStyleCalcIncludeCompositionCharacters = "Include composition characters",
CpsLineLengthStyleCalcIncludeCompositionCharactersNotSpace = "Include composition characters, not space", CpsLineLengthStyleCalcIncludeCompositionCharactersNotSpace = "Include composition characters, not space",
CpsLineLengthStyleCalcNoSpaceOrPunctuation = "No space or punctuation ()[]-:;,.!?", CpsLineLengthStyleCalcNoSpaceOrPunctuation = "No space or punctuation ()[]-:;,.!?",
CpsLineLengthStyleCalcNoSpaceOrPunctuationCpsOnly = "No space or punctuation, cps only", CpsLineLengthStyleCalcNoSpaceOrPunctuationCpsOnly = "No space or punctuation, CPS only",
ContinuationStyleNone = "None", ContinuationStyleNone = "None",
ContinuationStyleNoneTrailingDots = "None, dots for pauses (trailing only)", ContinuationStyleNoneTrailingDots = "None, dots for pauses (trailing only)",
ContinuationStyleNoneLeadingTrailingDots = "None, dots for pauses", ContinuationStyleNoneLeadingTrailingDots = "None, dots for pauses",