mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Allow OCR of XML/PNG from MXF - thx Rodney :)
This commit is contained in:
parent
16eec09a1d
commit
9db957027d
@ -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
|
||||
|
@ -10,10 +10,11 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.MaterialExchangeFormat
|
||||
public bool IsValid { get; private set; }
|
||||
|
||||
private readonly List<string> _subtitleList = new List<string>();
|
||||
public List<string> GetSubtitles()
|
||||
{
|
||||
return _subtitleList;
|
||||
}
|
||||
private readonly List<byte[]> _images = new List<byte[]>();
|
||||
|
||||
public List<string> GetSubtitles() => _subtitleList;
|
||||
|
||||
public List<byte[]> 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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user