本文整理汇总了C#中Nikse.SubtitleEdit.Core.ContainerFormats.Matroska.MatroskaFile类的典型用法代码示例。如果您正苦于以下问题:C# MatroskaFile类的具体用法?C# MatroskaFile怎么用?C# MatroskaFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MatroskaFile类属于Nikse.SubtitleEdit.Core.ContainerFormats.Matroska命名空间,在下文中一共展示了MatroskaFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MatroskaTestInvalid
public void MatroskaTestInvalid()
{
string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_TS_with_graphics.ts");
using (var parser = new MatroskaFile(fileName))
{
Assert.IsFalse(parser.IsValid);
}
}
示例2: MatroskaTestValid
public void MatroskaTestValid()
{
string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_SRT.mkv");
using (var parser = new MatroskaFile(fileName))
{
Assert.IsTrue(parser.IsValid);
}
}
示例3: MatroskaTestIsSrt
public void MatroskaTestIsSrt()
{
string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_SRT.mkv");
using (var parser = new MatroskaFile(fileName))
{
var tracks = parser.GetTracks(true);
Assert.IsTrue(tracks[0].CodecId == "S_TEXT/UTF8");
}
}
示例4: MatroskaTestVobSubPgs
public void MatroskaTestVobSubPgs()
{
string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_VobSub_PGS.mkv");
using (var parser = new MatroskaFile(fileName))
{
var tracks = parser.GetTracks(true);
Assert.IsTrue(tracks[0].CodecId == "S_VOBSUB");
Assert.IsTrue(tracks[1].CodecId == "S_HDMV/PGS");
}
}
示例5: 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");
}
}
示例6: 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
}
}
示例7: TryReadVideoInfoViaMatroskaHeader
public static VideoInfo TryReadVideoInfoViaMatroskaHeader(string fileName)
{
var info = new VideoInfo { Success = false };
MatroskaFile matroska = null;
try
{
matroska = new MatroskaFile(fileName);
if (matroska.IsValid)
{
double frameRate;
int width;
int height;
double milliseconds;
string videoCodec;
matroska.GetInfo(out frameRate, out width, out height, out milliseconds, out videoCodec);
info.Width = width;
info.Height = height;
info.FramesPerSecond = frameRate;
info.Success = true;
info.TotalMilliseconds = milliseconds;
info.TotalSeconds = milliseconds / TimeCode.BaseUnit;
info.TotalFrames = info.TotalSeconds * frameRate;
info.VideoCodec = videoCodec;
}
}
catch (Exception)
{
throw;
}
finally
{
if (matroska != null)
{
matroska.Dispose();
}
}
return info;
}
示例8: LoadMatroskaTextSubtitle
public static SubtitleFormat LoadMatroskaTextSubtitle(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska, List<MatroskaSubtitle> sub, Subtitle subtitle)
{
if (subtitle == null)
throw new ArgumentNullException("subtitle");
subtitle.Paragraphs.Clear();
var isSsa = false;
SubtitleFormat format = new SubRip();
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;
}
if (isSsa)
{
foreach (var p in LoadMatroskaSSA(matroskaSubtitleInfo, matroska.Path, format, sub).Paragraphs)
{
subtitle.Paragraphs.Add(p);
}
if (!string.IsNullOrEmpty(matroskaSubtitleInfo.CodecPrivate))
{
bool eventsStarted = false;
bool fontsStarted = false;
bool graphicsStarted = false;
var header = new StringBuilder();
foreach (string line in matroskaSubtitleInfo.CodecPrivate.Replace(Environment.NewLine, "\n").Split('\n'))
{
if (!eventsStarted && !fontsStarted && !graphicsStarted)
{
header.AppendLine(line);
}
if (line.TrimStart().StartsWith("dialog:", StringComparison.OrdinalIgnoreCase))
{
eventsStarted = true;
fontsStarted = false;
graphicsStarted = false;
}
else if (line.Trim().Equals("[events]", StringComparison.OrdinalIgnoreCase))
{
eventsStarted = true;
fontsStarted = false;
graphicsStarted = false;
}
else if (line.Trim().Equals("[fonts]", StringComparison.OrdinalIgnoreCase))
{
eventsStarted = false;
fontsStarted = true;
graphicsStarted = false;
}
else if (line.Trim().Equals("[graphics]", StringComparison.OrdinalIgnoreCase))
{
eventsStarted = false;
fontsStarted = false;
graphicsStarted = true;
}
}
subtitle.Header = header.ToString().TrimEnd();
if (!subtitle.Header.Contains("[events]", StringComparison.OrdinalIgnoreCase))
{
subtitle.Header += Environment.NewLine + Environment.NewLine + "[Events]" + Environment.NewLine;
}
}
}
else
{
foreach (var p in sub)
{
subtitle.Paragraphs.Add(new Paragraph(p.Text, p.Start, p.End));
}
}
subtitle.Renumber();
return format;
}
示例9: 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();
//.........这里部分代码省略.........
示例10: 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);
//.........这里部分代码省略.........
示例11: 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;
}
示例12: 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;
}
示例13: OpenSubtitle
private void OpenSubtitle(string fileName, Encoding encoding, string videoFileName, string originalFileName)
{
if (File.Exists(fileName))
{
bool videoFileLoaded = false;
var file = new FileInfo(fileName);
var ext = file.Extension.ToLowerInvariant();
// save last first visible index + first selected index from listview
if (!string.IsNullOrEmpty(_fileName))
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName, originalFileName);
openFileDialog1.InitialDirectory = file.DirectoryName;
if (ext == ".sub" && IsVobSubFile(fileName, false))
{
if (MessageBox.Show(this, _language.ImportThisVobSubSubtitle, _title, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
ImportAndOcrVobSubSubtitleNew(fileName, _loading);
}
return;
}
if (ext == ".sup")
{
if (FileUtil.IsBluRaySup(fileName))
{
ImportAndOcrBluRaySup(fileName, _loading);
return;
}
else if (FileUtil.IsSpDvdSup(fileName))
{
ImportAndOcrSpDvdSup(fileName, _loading);
return;
}
}
if (ext == ".mkv" || ext == ".mks")
{
ImportSubtitleFromMatroskaFile(fileName);
return;
}
if (ext == ".divx" || ext == ".avi")
{
if (ImportSubtitleFromDivX(fileName))
return;
}
if ((ext == ".ts" || ext == ".rec" || ext == ".mpeg" || ext == ".mpg") && file.Length > 10000 && FileUtil.IsTransportStream(fileName))
{
ImportSubtitleFromTransportStream(fileName);
return;
}
if (((ext == ".m2ts" || ext == ".ts") && file.Length > 10000 && FileUtil.IsM2TransportStream(fileName)) ||
(ext == ".textst" && FileUtil.IsMpeg2PrivateStream2(fileName)))
{
bool isTextSt = false;
if (file.Length < 2000000)
{
var textSt = new TextST();
isTextSt = textSt.IsMine(null, fileName);
}
if (!isTextSt)
{
ImportSubtitleFromTransportStream(fileName);
return;
}
}
if ((ext == ".mp4" || ext == ".m4v" || ext == ".3gp") && file.Length > 10000)
{
if (ImportSubtitleFromMp4(fileName))
OpenVideo(fileName);
return;
}
if (ext == ".mxf")
{
if (FileUtil.IsMaterialExchangeFormat(fileName))
{
var parser = new MxfParser(fileName);
if (parser.IsValid)
{
var subtitles = parser.GetSubtitles();
if (subtitles.Count > 0)
{
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
var list = new List<string>(subtitles[0].SplitToLines());
_subtitle = new Subtitle();
var mxfFormat = _subtitle.ReloadLoadSubtitle(list, null, null);
SetCurrentFormat(mxfFormat);
_fileName = Path.GetFileNameWithoutExtension(fileName);
SetTitle();
ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName));
_sourceViewChange = false;
_changeSubtitleToString = _subtitle.GetFastHashCode();
//.........这里部分代码省略.........
示例14: buttonRipWave_Click
private void buttonRipWave_Click(object sender, EventArgs e)
{
if (listViewInputFiles.Items.Count == 0)
{
MessageBox.Show(Configuration.Settings.Language.BatchConvert.NothingToConvert);
return;
}
_converting = true;
buttonRipWave.Enabled = false;
progressBar1.Style = ProgressBarStyle.Blocks;
progressBar1.Maximum = listViewInputFiles.Items.Count;
progressBar1.Value = 0;
progressBar1.Visible = progressBar1.Maximum > 2;
buttonInputBrowse.Enabled = false;
buttonSearchFolder.Enabled = false;
_abort = false;
listViewInputFiles.BeginUpdate();
foreach (ListViewItem item in listViewInputFiles.Items)
item.SubItems[3].Text = "-";
listViewInputFiles.EndUpdate();
Refresh();
int index = 0;
while (index < listViewInputFiles.Items.Count && _abort == false)
{
var item = listViewInputFiles.Items[index];
Action<string> updateStatus = status =>
{
item.SubItems[3].Text = status;
Refresh();
};
updateStatus(Configuration.Settings.Language.AddWaveformBatch.ExtractingAudio);
string fileName = item.Text;
try
{
string targetFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".wav");
Process process;
try
{
string encoderName;
process = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out encoderName);
labelInfo.Text = encoderName;
}
catch (DllNotFoundException)
{
if (MessageBox.Show(Configuration.Settings.Language.AddWaveform.VlcMediaPlayerNotFound + Environment.NewLine +
Environment.NewLine + Configuration.Settings.Language.AddWaveform.GoToVlcMediaPlayerHomePage,
Configuration.Settings.Language.AddWaveform.VlcMediaPlayerNotFoundTitle,
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
Process.Start("http://www.videolan.org/");
}
buttonRipWave.Enabled = true;
return;
}
process.Start();
while (!process.HasExited && !_abort)
{
Application.DoEvents();
}
// check for delay in matroska files
var audioTrackNames = new List<string>();
var mkvAudioTrackNumbers = new Dictionary<int, int>();
if (fileName.ToLower().EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
{
MatroskaFile matroska = null;
try
{
matroska = new MatroskaFile(fileName);
if (matroska.IsValid)
{
foreach (var track in matroska.GetTracks())
{
if (track.IsAudio)
{
if (track.CodecId != null && track.Language != null)
audioTrackNames.Add("#" + track.TrackNumber + ": " + track.CodecId.Replace("\0", string.Empty) + " - " + track.Language.Replace("\0", string.Empty));
else
audioTrackNames.Add("#" + track.TrackNumber);
mkvAudioTrackNumbers.Add(mkvAudioTrackNumbers.Count, track.TrackNumber);
}
}
if (mkvAudioTrackNumbers.Count > 0)
{
_delayInMilliseconds = (int)matroska.GetTrackStartTime(mkvAudioTrackNumbers[0]);
}
}
}
catch
{
_delayInMilliseconds = 0;
}
finally
{
if (matroska != null)
{
matroska.Dispose();
}
//.........这里部分代码省略.........
示例15: MatroskaTestDelayed500Ms
public void MatroskaTestDelayed500Ms()
{
string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_delayed.mkv");
using (var parser = new MatroskaFile(fileName))
{
var delay = parser.GetTrackStartTime(parser.GetTracks()[0].TrackNumber);
Assert.IsTrue(delay == 500);
}
}