diff --git a/Changelog.txt b/Changelog.txt index c0c71679e..c34967f79 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -7,6 +7,7 @@ * Add video format ProRes for "Generate video with burned-in sub" * Allow setting profile from cmd line - thx emcodem * ASSA set layer - thx JonSchram + * Allow OCR of XML/PNG from MXF - thx Rodney * IMPROVED: * Update German translation - thx Netspark * Update Chinese translation - thx nkh0472 diff --git a/src/libse/ContainerFormats/MaterialExchangeFormat/MxfParser.cs b/src/libse/ContainerFormats/MaterialExchangeFormat/MxfParser.cs index 8f981ad97..a54b2b94d 100644 --- a/src/libse/ContainerFormats/MaterialExchangeFormat/MxfParser.cs +++ b/src/libse/ContainerFormats/MaterialExchangeFormat/MxfParser.cs @@ -10,10 +10,11 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.MaterialExchangeFormat public bool IsValid { get; private set; } private readonly List _subtitleList = new List(); - public List GetSubtitles() - { - return _subtitleList; - } + private readonly List _images = new List(); + + public List GetSubtitles() => _subtitleList; + + public List GetImages() => _images; private long _startPosition; @@ -49,8 +50,15 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.MaterialExchangeFormat { stream.Seek(klv.DataPosition, SeekOrigin.Begin); var buffer = new byte[klv.DataSize]; - stream.Read(buffer, 0, buffer.Length); - if (buffer.Length >= 12) + var bytesRead = stream.Read(buffer, 0, buffer.Length); + + 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; 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")) { @@ -115,7 +123,7 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.MaterialExchangeFormat } _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 if (buffer[i + 00] == 0x06 && // OID diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index 3fb0f6d78..2eeb255fa 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -2924,6 +2924,18 @@ namespace Nikse.SubtitleEdit.Forms _converted = true; 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(); SubtitleListview1.Fill(_subtitle, _subtitleOriginal); _subtitleListViewIndex = -1;