本文整理汇总了C#中Nikse.SubtitleEdit.Core.ContainerFormats.Matroska.MatroskaFile.GetSubtitle方法的典型用法代码示例。如果您正苦于以下问题:C# MatroskaFile.GetSubtitle方法的具体用法?C# MatroskaFile.GetSubtitle怎么用?C# MatroskaFile.GetSubtitle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nikse.SubtitleEdit.Core.ContainerFormats.Matroska.MatroskaFile
的用法示例。
在下文中一共展示了MatroskaFile.GetSubtitle方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MatroskaTestSrtContent
public void MatroskaTestSrtContent()
{
string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_SRT.mkv");
using (var parser = new MatroskaFile(fileName))
{
var tracks = parser.GetTracks(true);
var subtitles = parser.GetSubtitle(Convert.ToInt32(tracks[0].TrackNumber), null);
Assert.IsTrue(subtitles.Count == 2);
Assert.IsTrue(subtitles[0].Text == "Line 1");
Assert.IsTrue(subtitles[1].Text == "Line 2");
}
}
示例2: MatroskaTestVobSubPgsContent
public void MatroskaTestVobSubPgsContent()
{
string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_VobSub_PGS.mkv");
using (var parser = new MatroskaFile(fileName))
{
var tracks = parser.GetTracks(true);
var subtitles = parser.GetSubtitle(Convert.ToInt32(tracks[0].TrackNumber), null);
Assert.IsTrue(subtitles.Count == 2);
// TODO: Check bitmaps
//subtitles = parser.GetSubtitle(Convert.ToInt32(tracks[1].TrackNumber), null);
//Assert.IsTrue(subtitles.Count == 2);
//check bitmaps
}
}
示例3: LoadBluRaySubFromMatroska
private bool LoadBluRaySubFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska)
{
if (matroskaSubtitleInfo.ContentEncodingType == 1)
{
MessageBox.Show(_language.NoSupportEncryptedVobSub);
}
ShowStatus(_language.ParsingMatroskaFile);
Refresh();
Cursor.Current = Cursors.WaitCursor;
var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, MatroskaProgress);
TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
Cursor.Current = Cursors.Default;
int noOfErrors = 0;
string lastError = string.Empty;
MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
_subtitleListViewIndex = -1;
_subtitle.Paragraphs.Clear();
var subtitles = new List<BluRaySupParser.PcsData>();
var log = new StringBuilder();
foreach (var p in sub)
{
byte[] buffer = null;
if (matroskaSubtitleInfo.ContentEncodingType == 0) // compressed with zlib
{
var outStream = new MemoryStream();
var outZStream = new zlib.ZOutputStream(outStream);
var inStream = new MemoryStream(p.Data);
try
{
CopyStream(inStream, outZStream);
buffer = new byte[outZStream.TotalOut];
outStream.Position = 0;
outStream.Read(buffer, 0, buffer.Length);
}
catch (Exception exception)
{
var tc = new TimeCode(p.Start);
lastError = tc + ": " + exception.Message + ": " + exception.StackTrace;
noOfErrors++;
}
finally
{
outZStream.Close();
inStream.Close();
}
}
else
{
buffer = p.Data;
}
if (buffer != null && buffer.Length > 100)
{
var ms = new MemoryStream(buffer);
var list = BluRaySupParser.ParseBluRaySup(ms, log, true);
foreach (var sup in list)
{
sup.StartTime = (long)((p.Start - 1) * 90.0);
sup.EndTime = (long)((p.End - 1) * 90.0);
subtitles.Add(sup);
// fix overlapping
if (subtitles.Count > 1 && sub[subtitles.Count - 2].End > sub[subtitles.Count - 1].Start)
subtitles[subtitles.Count - 2].EndTime = subtitles[subtitles.Count - 1].StartTime - 1;
}
ms.Close();
}
else if (subtitles.Count > 0)
{
var lastSub = subtitles[subtitles.Count - 1];
if (lastSub.StartTime == lastSub.EndTime)
{
lastSub.EndTime = (long)((p.Start - 1) * 90.0);
if (lastSub.EndTime - lastSub.StartTime > 1000000)
lastSub.EndTime = lastSub.StartTime;
}
}
}
if (noOfErrors > 0)
{
MessageBox.Show(string.Format("{0} error(s) occurred during extraction of bdsup\r\n\r\n{1}", noOfErrors, lastError));
}
using (var formSubOcr = new VobSubOcr())
{
formSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, matroska.Path);
if (_loading)
{
formSubOcr.Icon = (Icon)Icon.Clone();
formSubOcr.ShowInTaskbar = true;
formSubOcr.ShowIcon = true;
}
if (formSubOcr.ShowDialog(this) == DialogResult.OK)
{
MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle);
_subtitle.Paragraphs.Clear();
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
//.........这里部分代码省略.........
示例4: LoadVobSubFromMatroska
private bool LoadVobSubFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska)
{
if (matroskaSubtitleInfo.ContentEncodingType == 1)
{
MessageBox.Show(_language.NoSupportEncryptedVobSub);
}
ShowStatus(_language.ParsingMatroskaFile);
Refresh();
Cursor.Current = Cursors.WaitCursor;
var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, MatroskaProgress);
TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
Cursor.Current = Cursors.Default;
MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
_subtitleListViewIndex = -1;
_subtitle.Paragraphs.Clear();
List<VobSubMergedPack> mergedVobSubPacks = new List<VobSubMergedPack>();
var idx = new Core.VobSub.Idx(matroskaSubtitleInfo.CodecPrivate.SplitToLines());
foreach (var p in sub)
{
if (matroskaSubtitleInfo.ContentEncodingType == 0) // compressed with zlib
{
bool error = false;
var outStream = new MemoryStream();
var outZStream = new zlib.ZOutputStream(outStream);
var inStream = new MemoryStream(p.Data);
byte[] buffer = null;
try
{
CopyStream(inStream, outZStream);
buffer = new byte[outZStream.TotalOut];
outStream.Position = 0;
outStream.Read(buffer, 0, buffer.Length);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message + Environment.NewLine + Environment.NewLine + exception.StackTrace);
error = true;
}
finally
{
outZStream.Close();
inStream.Close();
}
if (!error && buffer.Length > 2)
mergedVobSubPacks.Add(new VobSubMergedPack(buffer, TimeSpan.FromMilliseconds(p.Start), 32, null));
}
else
{
mergedVobSubPacks.Add(new VobSubMergedPack(p.Data, TimeSpan.FromMilliseconds(p.Start), 32, null));
}
if (mergedVobSubPacks.Count > 0)
mergedVobSubPacks[mergedVobSubPacks.Count - 1].EndTime = TimeSpan.FromMilliseconds(p.End);
// fix overlapping (some versions of Handbrake makes overlapping time codes - thx Hawke)
if (mergedVobSubPacks.Count > 1 && mergedVobSubPacks[mergedVobSubPacks.Count - 2].EndTime > mergedVobSubPacks[mergedVobSubPacks.Count - 1].StartTime)
mergedVobSubPacks[mergedVobSubPacks.Count - 2].EndTime = TimeSpan.FromMilliseconds(mergedVobSubPacks[mergedVobSubPacks.Count - 1].StartTime.TotalMilliseconds - 1);
}
using (var formSubOcr = new VobSubOcr())
{
formSubOcr.Initialize(mergedVobSubPacks, idx.Palette, Configuration.Settings.VobSubOcr, null); // TODO: language???
if (_loading)
{
formSubOcr.Icon = (Icon)Icon.Clone();
formSubOcr.ShowInTaskbar = true;
formSubOcr.ShowIcon = true;
}
if (formSubOcr.ShowDialog(this) == DialogResult.OK)
{
ResetSubtitle();
_subtitle.Paragraphs.Clear();
_subtitle.WasLoadedWithFrameNumbers = false;
foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
_subtitle.Paragraphs.Add(p);
ShowSource();
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
_subtitleListViewIndex = -1;
SubtitleListview1.FirstVisibleIndex = -1;
SubtitleListview1.SelectIndexAndEnsureVisible(0);
_fileName = Path.GetFileNameWithoutExtension(matroska.Path);
_converted = true;
Text = Title;
Configuration.Settings.Save();
return true;
}
}
return false;
}
示例5: LoadTextSTFromMatroska
private bool LoadTextSTFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska, bool batchMode)
{
ShowStatus(_language.ParsingMatroskaFile);
Refresh();
Cursor.Current = Cursors.WaitCursor;
var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, MatroskaProgress);
TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
Cursor.Current = Cursors.Default;
MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
_subtitleListViewIndex = -1;
if (!batchMode)
ResetSubtitle();
_subtitle.Paragraphs.Clear();
Utilities.LoadMatroskaTextSubtitle(matroskaSubtitleInfo, matroska, sub, _subtitle);
for (int index = 0; index < sub.Count; index++)
{
try
{
var msub = sub[index];
int idx = -6; // MakeMKV starts at DialogPresentationSegment
if (VobSubParser.IsPrivateStream2(msub.Data, 0))
idx = 0; // starts with MPEG2 private stream 2 (just to be sure)
var dps = new Nikse.SubtitleEdit.Core.SubtitleFormats.TextST.DialogPresentationSegment(msub.Data, idx);
_subtitle.Paragraphs[index].Text = dps.Text;
}
catch (Exception exception)
{
_subtitle.Paragraphs[index].Text = exception.Message;
}
}
if (_networkSession == null && SubtitleListview1.IsExtraColumnVisible)
{
SubtitleListview1.HideExtraColumn();
}
comboBoxSubtitleFormats.SelectedIndexChanged -= ComboBoxSubtitleFormatsSelectedIndexChanged;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
comboBoxSubtitleFormats.SelectedIndexChanged += ComboBoxSubtitleFormatsSelectedIndexChanged;
SetEncoding(Encoding.UTF8);
ShowStatus(_language.SubtitleImportedFromMatroskaFile);
_subtitle.Renumber();
_subtitle.WasLoadedWithFrameNumbers = false;
if (matroska.Path.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase) || matroska.Path.EndsWith(".mks", StringComparison.OrdinalIgnoreCase))
{
_fileName = matroska.Path.Remove(matroska.Path.Length - 4);
Text = Title + " - " + _fileName;
}
else
{
Text = Title;
}
_fileDateTime = new DateTime();
_converted = true;
if (batchMode)
return true;
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
if (_subtitle.Paragraphs.Count > 0)
SubtitleListview1.SelectIndexAndEnsureVisible(0);
ShowSource();
return true;
}
示例6: LoadMatroskaSubtitle
private bool LoadMatroskaSubtitle(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska, bool batchMode)
{
if (matroskaSubtitleInfo.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase))
{
if (batchMode)
return false;
return LoadVobSubFromMatroska(matroskaSubtitleInfo, matroska);
}
if (matroskaSubtitleInfo.CodecId.Equals("S_HDMV/PGS", StringComparison.OrdinalIgnoreCase))
{
if (batchMode)
return false;
return LoadBluRaySubFromMatroska(matroskaSubtitleInfo, matroska);
}
if (matroskaSubtitleInfo.CodecId.Equals("S_HDMV/TEXTST", StringComparison.OrdinalIgnoreCase))
{
if (batchMode)
return false;
return LoadTextSTFromMatroska(matroskaSubtitleInfo, matroska, batchMode);
}
ShowStatus(_language.ParsingMatroskaFile);
Refresh();
Cursor.Current = Cursors.WaitCursor;
var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, MatroskaProgress);
TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
Cursor.Current = Cursors.Default;
MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
_subtitleListViewIndex = -1;
if (!batchMode)
ResetSubtitle();
_subtitle.Paragraphs.Clear();
var format = Utilities.LoadMatroskaTextSubtitle(matroskaSubtitleInfo, matroska, sub, _subtitle);
if (matroskaSubtitleInfo.CodecPrivate.Contains("[script info]", StringComparison.OrdinalIgnoreCase))
{
if (_networkSession == null)
{
SubtitleListview1.ShowExtraColumn(_languageGeneral.Style);
SubtitleListview1.DisplayExtraFromExtra = true;
}
}
else if (_networkSession == null && SubtitleListview1.IsExtraColumnVisible)
{
SubtitleListview1.HideExtraColumn();
}
comboBoxSubtitleFormats.SelectedIndexChanged -= ComboBoxSubtitleFormatsSelectedIndexChanged;
SetCurrentFormat(format);
comboBoxSubtitleFormats.SelectedIndexChanged += ComboBoxSubtitleFormatsSelectedIndexChanged;
SetEncoding(Encoding.UTF8);
ShowStatus(_language.SubtitleImportedFromMatroskaFile);
_subtitle.Renumber();
_subtitle.WasLoadedWithFrameNumbers = false;
if (matroska.Path.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase) || matroska.Path.EndsWith(".mks", StringComparison.OrdinalIgnoreCase))
{
_fileName = matroska.Path.Remove(matroska.Path.Length - 4);
Text = Title + " - " + _fileName;
}
else
{
Text = Title;
}
_fileDateTime = new DateTime();
_converted = true;
if (batchMode)
return true;
SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
if (_subtitle.Paragraphs.Count > 0)
SubtitleListview1.SelectIndexAndEnsureVisible(0);
ShowSource();
return true;
}
示例7: LoadMatroskaSubtitleForSync
private Subtitle LoadMatroskaSubtitleForSync(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska)
{
var subtitle = new Subtitle();
bool isSsa = false;
if (matroskaSubtitleInfo.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase))
{
return subtitle;
}
if (matroskaSubtitleInfo.CodecId.Equals("S_HDMV/PGS", StringComparison.OrdinalIgnoreCase))
{
return subtitle;
}
SubtitleFormat format;
if (matroskaSubtitleInfo.CodecPrivate.Contains("[script info]", StringComparison.OrdinalIgnoreCase))
{
if (matroskaSubtitleInfo.CodecPrivate.Contains("[V4 Styles]", StringComparison.OrdinalIgnoreCase))
format = new SubStationAlpha();
else
format = new AdvancedSubStationAlpha();
isSsa = true;
}
else
{
format = new SubRip();
}
var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, MatroskaProgress);
TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
if (isSsa)
{
foreach (var p in Utilities.LoadMatroskaSSA(matroskaSubtitleInfo, matroska.Path, format, sub).Paragraphs)
{
subtitle.Paragraphs.Add(p);
}
}
else
{
foreach (var p in sub)
{
subtitle.Paragraphs.Add(new Paragraph(p.Text, p.Start, p.End));
}
}
return subtitle;
}
示例8: buttonConvert_Click
//.........这里部分代码省略.........
}
else if (format == null && fileName.EndsWith(".sub", StringComparison.OrdinalIgnoreCase) && FileUtil.IsVobSub(fileName))
{
isVobSub = true;
}
else if (format == null && (fileName.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase) || fileName.EndsWith(".mks", StringComparison.OrdinalIgnoreCase)) && item.SubItems[2].Text.StartsWith("Matroska"))
{
isMatroska = true;
}
if (format == null && bluRaySubtitles.Count == 0 && !isVobSub && !isMatroska)
{
IncrementAndShowProgress();
}
else
{
if (isMatroska && (Path.GetExtension(fileName).Equals(".mkv", StringComparison.OrdinalIgnoreCase) || Path.GetExtension(fileName).Equals(".mks", StringComparison.OrdinalIgnoreCase)))
{
using (var matroska = new MatroskaFile(fileName))
{
if (matroska.IsValid)
{
foreach (var track in matroska.GetTracks(true))
{
if (track.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase))
{
// TODO: Convert from VobSub image based format!
}
else if (track.CodecId.Equals("S_HDMV/PGS", StringComparison.OrdinalIgnoreCase))
{
// TODO: Convert from Blu-ray image based format!
}
else if (track.CodecId.Equals("S_TEXT/UTF8", StringComparison.OrdinalIgnoreCase) || track.CodecId.Equals("S_TEXT/SSA", StringComparison.OrdinalIgnoreCase) || track.CodecId.Equals("S_TEXT/ASS", StringComparison.OrdinalIgnoreCase))
{
var mkvSub = matroska.GetSubtitle(track.TrackNumber, null);
Utilities.LoadMatroskaTextSubtitle(track, matroska, mkvSub, sub);
break;
}
}
}
}
}
else if (bluRaySubtitles.Count > 0)
{
item.SubItems[3].Text = Configuration.Settings.Language.BatchConvert.Ocr;
using (var vobSubOcr = new VobSubOcr())
{
vobSubOcr.FileName = Path.GetFileName(fileName);
vobSubOcr.InitializeBatch(bluRaySubtitles, Configuration.Settings.VobSubOcr, fileName);
sub = vobSubOcr.SubtitleFromOcr;
}
}
else if (isVobSub)
{
item.SubItems[3].Text = Configuration.Settings.Language.BatchConvert.Ocr;
using (var vobSubOcr = new VobSubOcr())
{
vobSubOcr.InitializeBatch(fileName, Configuration.Settings.VobSubOcr);
sub = vobSubOcr.SubtitleFromOcr;
}
}
if (comboBoxSubtitleFormats.Text == AdvancedSubStationAlpha.NameOfFormat && _assStyle != null)
{
sub.Header = _assStyle;
}
else if (comboBoxSubtitleFormats.Text == SubStationAlpha.NameOfFormat && _ssaStyle != null)
{
示例9: Convert
//.........这里部分代码省略.........
if (!string.IsNullOrEmpty(inputFolder) && File.Exists(Path.Combine(inputFolder, fileName)))
{
fileName = Path.Combine(inputFolder, fileName);
}
if (File.Exists(fileName))
{
var sub = new Subtitle();
SubtitleFormat format = null;
bool done = false;
if (Path.GetExtension(fileName).Equals(".mkv", StringComparison.OrdinalIgnoreCase) || Path.GetExtension(fileName).Equals(".mks", StringComparison.OrdinalIgnoreCase))
{
using (var matroska = new MatroskaFile(fileName))
{
if (matroska.IsValid)
{
var tracks = matroska.GetTracks();
if (tracks.Count > 0)
{
foreach (var track in tracks)
{
if (track.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("{0}: {1} - Cannot convert from VobSub image based format!", fileName, toFormat);
}
else if (track.CodecId.Equals("S_HDMV/PGS", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("{0}: {1} - Cannot convert from Blu-ray image based format!", fileName, toFormat);
}
else
{
var ss = matroska.GetSubtitle(track.TrackNumber, null);
format = Utilities.LoadMatroskaTextSubtitle(track, matroska, ss, sub);
string newFileName = fileName;
if (tracks.Count > 1)
newFileName = fileName.Insert(fileName.Length - 4, "_" + track.TrackNumber + "_" + track.Language.Replace("?", string.Empty).Replace("!", string.Empty).Replace("*", string.Empty).Replace(",", string.Empty).Replace("/", string.Empty).Trim());
if (format.GetType() == typeof(AdvancedSubStationAlpha) || format.GetType() == typeof(SubStationAlpha))
{
if (toFormat.ToLower() != AdvancedSubStationAlpha.NameOfFormat.ToLower().Replace(" ", string.Empty) &&
toFormat.ToLower() != SubStationAlpha.NameOfFormat.ToLower().Replace(" ", string.Empty))
{
foreach (SubtitleFormat sf in formats)
{
if (sf.Name.Replace(" ", string.Empty).Equals(toFormat, StringComparison.OrdinalIgnoreCase) || sf.Name.Replace(" ", string.Empty).Equals(toFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
{
format.RemoveNativeFormatting(sub, sf);
break;
}
}
}
}
BatchConvertSave(toFormat, offset, targetEncoding, outputFolder, count, ref converted, ref errors, formats, newFileName, sub, format, overwrite, pacCodePage, targetFrameRate);
done = true;
}
}
}
}
}
}
if (FileUtil.IsBluRaySup(fileName))
{
示例10: LoadDvbFromMatroska
private bool LoadDvbFromMatroska(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska, bool batchMode)
{
ShowStatus(_language.ParsingMatroskaFile);
Refresh();
Cursor.Current = Cursors.WaitCursor;
var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, MatroskaProgress);
TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
Cursor.Current = Cursors.Default;
MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
_subtitleListViewIndex = -1;
if (!batchMode)
ResetSubtitle();
_subtitle.Paragraphs.Clear();
var subtitleImages = new List<DvbSubPes>();
var subtitle = new Subtitle();
Utilities.LoadMatroskaTextSubtitle(matroskaSubtitleInfo, matroska, sub, _subtitle);
for (int index = 0; index < sub.Count; index++)
{
try
{
var msub = sub[index];
DvbSubPes pes = null;
if (msub.Data.Length > 9 && msub.Data[0] == 15 && msub.Data[1] >= SubtitleSegment.PageCompositionSegment && msub.Data[1] <= SubtitleSegment.DisplayDefinitionSegment) // sync byte + segment id
{
var buffer = new byte[msub.Data.Length + 3];
Buffer.BlockCopy(msub.Data, 0, buffer, 2, msub.Data.Length);
buffer[0] = 32;
buffer[1] = 0;
buffer[buffer.Length - 1] = 255;
pes = new DvbSubPes(0, buffer);
}
else if (VobSubParser.IsMpeg2PackHeader(msub.Data))
{
pes = new DvbSubPes(msub.Data, Mpeg2Header.Length);
}
else if (VobSubParser.IsPrivateStream1(msub.Data, 0))
{
pes = new DvbSubPes(msub.Data, 0);
}
else if (msub.Data.Length > 9 && msub.Data[0] == 32 && msub.Data[1] == 0 && msub.Data[2] == 14 && msub.Data[3] == 16)
{
pes = new DvbSubPes(0, msub.Data);
}
if (pes == null && subtitle.Paragraphs.Count > 0)
{
var last = subtitle.Paragraphs[subtitle.Paragraphs.Count - 1];
if (last.Duration.TotalMilliseconds < 100)
{
last.EndTime.TotalMilliseconds = msub.Start;
if (last.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
{
last.EndTime.TotalMilliseconds = last.StartTime.TotalMilliseconds + 3000;
}
}
}
if (pes != null && pes.PageCompositions != null && pes.PageCompositions.Any(p => p.Regions.Count > 0))
{
subtitleImages.Add(pes);
subtitle.Paragraphs.Add(new Paragraph(string.Empty, msub.Start, msub.End));
}
}
catch
{
// continue
}
}
if (subtitleImages.Count == 0)
{
return false;
}
for (int index = 0; index < subtitle.Paragraphs.Count; index++)
{
var p = subtitle.Paragraphs[index];
if (p.Duration.TotalMilliseconds < 200)
{
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + 3000;
}
var next = subtitle.GetParagraphOrDefault(index + 1);
if (next != null && next.StartTime.TotalMilliseconds < p.EndTime.TotalMilliseconds)
{
p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
}
}
using (var formSubOcr = new VobSubOcr())
{
formSubOcr.Initialize(subtitle, subtitleImages, Configuration.Settings.VobSubOcr, null); // TODO: language???
if (_loading)
{
formSubOcr.Icon = (Icon)Icon.Clone();
formSubOcr.ShowInTaskbar = true;
formSubOcr.ShowIcon = true;
}
if (formSubOcr.ShowDialog(this) == DialogResult.OK)
{
ResetSubtitle();
//.........这里部分代码省略.........
示例11: Convert
//.........这里部分代码省略.........
var formats = SubtitleFormat.AllSubtitleFormats;
foreach (var fileName in files)
{
count++;
var fileInfo = new FileInfo(fileName);
if (fileInfo.Exists)
{
var sub = new Subtitle();
SubtitleFormat format = null;
bool done = false;
if (fileInfo.Extension.Equals(".mkv", StringComparison.OrdinalIgnoreCase) || fileInfo.Extension.Equals(".mks", StringComparison.OrdinalIgnoreCase))
{
using (var matroska = new MatroskaFile(fileName))
{
if (matroska.IsValid)
{
var tracks = matroska.GetTracks(true);
if (tracks.Count > 0)
{
foreach (var track in tracks)
{
if (track.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("{0}: {1} - Cannot convert from VobSub image based format!", fileName, targetFormat);
}
else if (track.CodecId.Equals("S_HDMV/PGS", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("{0}: {1} - Cannot convert from Blu-ray image based format!", fileName, targetFormat);
}
else
{
var ss = matroska.GetSubtitle(track.TrackNumber, null);
format = Utilities.LoadMatroskaTextSubtitle(track, matroska, ss, sub);
string newFileName = fileName;
if (tracks.Count > 1)
newFileName = fileName.Insert(fileName.Length - 4, "_" + track.TrackNumber + "_" + track.Language.Replace("?", string.Empty).Replace("!", string.Empty).Replace("*", string.Empty).Replace(",", string.Empty).Replace("/", string.Empty).Trim());
if (format.GetType() == typeof(AdvancedSubStationAlpha) || format.GetType() == typeof(SubStationAlpha))
{
if (!AdvancedSubStationAlpha.NameOfFormat.Replace(" ", string.Empty).Equals(targetFormat, StringComparison.OrdinalIgnoreCase) &&
!SubStationAlpha.NameOfFormat.Replace(" ", string.Empty).Equals(targetFormat, StringComparison.OrdinalIgnoreCase))
{
foreach (SubtitleFormat sf in formats)
{
if (sf.Name.Replace(" ", string.Empty).Equals(targetFormat, StringComparison.OrdinalIgnoreCase))
{
format.RemoveNativeFormatting(sub, sf);
break;
}
}
}
}
BatchConvertSave(targetFormat, offset, targetEncoding, outputFolder, count, ref converted, ref errors, formats, newFileName, sub, format, overwrite, pacCodePage, targetFrameRate, multipleReplaceImportFiles, removeTextForHi, fixCommonErrors, redoCasing);
done = true;
}
}
}
}
}
}
if (!done && FileUtil.IsBluRaySup(fileName))
{