Allow OCR of XML/PNG from MXF - thx Rodney :)

This commit is contained in:
niksedk 2023-06-27 17:50:17 +02:00
parent 16eec09a1d
commit 9db957027d
3 changed files with 29 additions and 8 deletions

View File

@ -7,6 +7,7 @@
* Add video format ProRes for "Generate video with burned-in sub" * Add video format ProRes for "Generate video with burned-in sub"
* Allow setting profile from cmd line - thx emcodem * Allow setting profile from cmd line - thx emcodem
* ASSA set layer - thx JonSchram * ASSA set layer - thx JonSchram
* Allow OCR of XML/PNG from MXF - thx Rodney
* IMPROVED: * IMPROVED:
* Update German translation - thx Netspark * Update German translation - thx Netspark
* Update Chinese translation - thx nkh0472 * Update Chinese translation - thx nkh0472

View File

@ -10,10 +10,11 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.MaterialExchangeFormat
public bool IsValid { get; private set; } public bool IsValid { get; private set; }
private readonly List<string> _subtitleList = new List<string>(); private readonly List<string> _subtitleList = new List<string>();
public List<string> GetSubtitles() private readonly List<byte[]> _images = new List<byte[]>();
{
return _subtitleList; public List<string> GetSubtitles() => _subtitleList;
}
public List<byte[]> GetImages() => _images;
private long _startPosition; private long _startPosition;
@ -49,8 +50,15 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.MaterialExchangeFormat
{ {
stream.Seek(klv.DataPosition, SeekOrigin.Begin); stream.Seek(klv.DataPosition, SeekOrigin.Begin);
var buffer = new byte[klv.DataSize]; var buffer = new byte[klv.DataSize];
stream.Read(buffer, 0, buffer.Length); var bytesRead = stream.Read(buffer, 0, buffer.Length);
if (buffer.Length >= 12)
if (buffer[0] == 0x89 && buffer[1] == 0x50 && buffer[2] == 0x4E && buffer[3] == 0x47) // PNG header
{
_images.Add(buffer);
continue;
}
if (buffer.Length >= 12 && bytesRead >= 12)
{ {
string s; string s;
if (buffer[0] == 0xef && buffer[1] == 0xbb && buffer[2] == 0xbf) if (buffer[0] == 0xef && buffer[1] == 0xbb && buffer[2] == 0xbf)
@ -88,7 +96,7 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.MaterialExchangeFormat
} }
} }
private bool IsSubtitle(string s) private static bool IsSubtitle(string s)
{ {
if (s.Contains("\0")) if (s.Contains("\0"))
{ {
@ -115,7 +123,7 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.MaterialExchangeFormat
} }
_startPosition = 0; _startPosition = 0;
for (int i = 0; i < count - 11; i++) for (var i = 0; i < count - 11; i++)
{ {
//Header Partition PackId = 06 0E 2B 34 02 05 01 01 0D 01 02 //Header Partition PackId = 06 0E 2B 34 02 05 01 01 0D 01 02
if (buffer[i + 00] == 0x06 && // OID if (buffer[i + 00] == 0x06 && // OID

View File

@ -2924,6 +2924,18 @@ namespace Nikse.SubtitleEdit.Forms
_converted = true; _converted = true;
ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName) + " - " + string.Format(_language.ConvertedToX, mxfFormat.FriendlyName)); ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName) + " - " + string.Format(_language.ConvertedToX, mxfFormat.FriendlyName));
var images = parser.GetImages();
if (images.Count > 0 && images.Count == _subtitle.Paragraphs.Count && _subtitle.Paragraphs[0].Text.StartsWith("urn:uuid:", StringComparison.Ordinal))
{
for (var j = 0; j < images.Count; j++)
{
_subtitle.Paragraphs[j].Text = Convert.ToBase64String(images[j]);
}
ImportAndInlineBase64(_subtitle, _loading, fileName);
return;
}
UpdateSourceView(); UpdateSourceView();
SubtitleListview1.Fill(_subtitle, _subtitleOriginal); SubtitleListview1.Fill(_subtitle, _subtitleOriginal);
_subtitleListViewIndex = -1; _subtitleListViewIndex = -1;