Display progress when parsing .ts files

This commit is contained in:
niksedk 2014-11-21 21:30:23 +01:00
parent 0fe5d99fa2
commit deb5e83cc3
7 changed files with 43 additions and 7 deletions

View File

@ -18,6 +18,7 @@
* Updated Slovenian translation - thx Hawk
* Updated Portuguese translation - thx moob
* Export to images now remembers shadow width
* Display progress when reading Transport Stream files
* FIXED:
* Compare window works again now - thx SimplyTheBOSS
* Changed duration via Waveform start/end is shown again - thx Quetsbeek/Mirko

View File

@ -8533,12 +8533,34 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private string _lastProgressMessage = string.Empty;
private void MatroskaProgress(long position, long total)
{
ShowStatus(string.Format("{0}, {1:0}%", _language.ParsingMatroskaFile, position * 100 / total));
string msg = string.Format("{0}, {1:0}%", _language.ParsingMatroskaFile, position * 100 / total);
if (_lastProgressMessage == msg)
return;
ShowStatus(msg);
statusStrip1.Refresh();
if (DateTime.Now.Ticks % 10 == 0)
Application.DoEvents();
_lastProgressMessage = msg;
}
private void TransportStreamProgress(long position, long total)
{
if (string.IsNullOrWhiteSpace(_language.ParsingTransportStreamFile))
_language.ParsingTransportStreamFile = "Parsing Transport Stream file. Please wait...";
string msg = string.Format("{0}, {1:0}%", _language.ParsingTransportStreamFile, position * 100 / total);
if (_lastProgressMessage == msg)
return;
ShowStatus(msg);
statusStrip1.Refresh();
if (DateTime.Now.Ticks % 10 == 0)
Application.DoEvents();
_lastProgressMessage = msg;
}
private Subtitle LoadMatroskaSubtitleForSync(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska)
@ -8930,7 +8952,7 @@ namespace Nikse.SubtitleEdit.Forms
ShowStatus(_language.ParsingTransportStream);
Refresh();
var tsParser = new TransportStreamParser();
tsParser.ParseTSFile(fileName);
tsParser.Parse(fileName, TransportStreamProgress);
ShowStatus(string.Empty);
if (tsParser.SubtitlePacketIds.Count == 0)

View File

@ -1019,6 +1019,7 @@ namespace Nikse.SubtitleEdit.Logic
NoSubtitlesFound = "No subtitles found",
NotAValidMatroskaFileX = "This is not a valid Matroska file: {0}",
ParsingMatroskaFile = "Parsing Matroska file. Please wait...",
ParsingTransportStreamFile = "Parsing Transport Stream file. Please wait...",
BeforeImportFromMatroskaFile = "Before import subtitle from Matroska file",
SubtitleImportedFromMatroskaFile = "Subtitle imported from Matroska file",
DropFileXNotAccepted = "Drop file '{0}' not accepted - file is too large",

View File

@ -2282,6 +2282,9 @@ namespace Nikse.SubtitleEdit.Logic
case "Main/ParsingMatroskaFile":
language.Main.ParsingMatroskaFile = reader.Value;
break;
case "Main/ParsingTransportStreamFile":
language.Main.ParsingTransportStreamFile = reader.Value;
break;
case "Main/BeforeImportFromMatroskaFile":
language.Main.BeforeImportFromMatroskaFile = reader.Value;
break;

View File

@ -904,6 +904,7 @@
public string NoSubtitlesFound { get; set; }
public string NotAValidMatroskaFileX { get; set; }
public string ParsingMatroskaFile { get; set; }
public string ParsingTransportStreamFile { get; set; }
public string BeforeImportFromMatroskaFile { get; set; }
public string SubtitleImportedFromMatroskaFile { get; set; }
public string DropFileXNotAccepted { get; set; }

View File

@ -12,6 +12,9 @@ namespace Nikse.SubtitleEdit.Logic.TransportStream
/// </summary>
public class TransportStreamParser
{
public delegate void LoadTransportStreamCallback(long position, long total);
public int NumberOfNullPackets { get; private set; }
public long TotalNumberOfPackets { get; private set; }
public long TotalNumberOfPrivateStream1 { get; private set; }
@ -24,11 +27,11 @@ namespace Nikse.SubtitleEdit.Logic.TransportStream
public bool IsM2TransportStream { get; private set; }
public ulong FirstVideoPts { get; private set; }
public void ParseTSFile(string fileName)
public void Parse(string fileName, LoadTransportStreamCallback callback)
{
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
ParseTSFile(fs);
Parse(fs, callback);
}
}
@ -36,7 +39,7 @@ namespace Nikse.SubtitleEdit.Logic.TransportStream
/// Can be used with e.g. MemoryStream or FileStream
/// </summary>
/// <param name="ms">Input stream</param>
public void ParseTSFile(Stream ms)
public void Parse(Stream ms, LoadTransportStreamCallback callback)
{
bool firstVideoPtsFound = false;
IsM2TransportStream = false;
@ -60,7 +63,8 @@ namespace Nikse.SubtitleEdit.Logic.TransportStream
if (m2TsTimeCodeBuffer[0] == 0x54 && m2TsTimeCodeBuffer[1] == 0x46 && m2TsTimeCodeBuffer[2] == 0x72)
position = 3760;
while (position < ms.Length)
long transportStreamLength = ms.Length;
while (position < transportStreamLength)
{
ms.Seek(position, SeekOrigin.Begin);
@ -162,6 +166,10 @@ namespace Nikse.SubtitleEdit.Logic.TransportStream
//}
}
if (callback != null)
{
callback.Invoke(ms.Position, transportStreamLength);
}
}
TotalNumberOfPackets++;
position += packetLength;

View File

@ -12,7 +12,7 @@ namespace Test.Logic.TransportStream
{
string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_TS_with_graphics.ts");
var parser = new Nikse.SubtitleEdit.Logic.TransportStream.TransportStreamParser();
parser.ParseTSFile(fileName);
parser.Parse(fileName, null);
var subtitles = parser.GetDvbSubtitles(41);
Assert.IsTrue(subtitles.Count == 10);