public void ReadsSegmentInfo() { var stream = new MemoryStream(); var writer = new EbmlWriter(stream); using (var segment = writer.StartMasterElement(MatroskaDtd.Segment.Identifier)) { using (var segmentInfo = segment.StartMasterElement(MatroskaDtd.Segment.Info.Identifier)) { segmentInfo.WriteUtf(MatroskaDtd.Segment.Info.Title.Identifier, "Test data"); segmentInfo.WriteUtf(MatroskaDtd.Segment.Info.WritingApp.Identifier, "writing app"); segmentInfo.WriteUtf(MatroskaDtd.Segment.Info.MuxingApp.Identifier, "mux app"); segmentInfo.Write(MatroskaDtd.Segment.Info.Duration.Identifier, 1234f); } // write some dummy data segment.Write(VInt.MakeId(123), 0); } stream.Position = 0; var infoReader = new SegmentInfoUpdater(); infoReader.Open(stream); Assert.AreEqual("Test data", infoReader.Title); Assert.AreEqual("writing app", infoReader.WritingApp); Assert.AreEqual("mux app", infoReader.MuxingApp); Assert.AreEqual(TimeSpan.FromMilliseconds(1234), infoReader.Duration); }
/// <summary> /// Creates new entry for MKV file (reads attributes from file) /// </summary> /// <param name="file"></param> /// <returns></returns> public static ListEntryViewModel CreateMkvFile(FileInfo file) { using (var upd = new SegmentInfoUpdater()) { upd.OpenRead(file); var ts = upd.Duration; return new File(file, upd.Title) { Duration = string.Format("{0:00}:{1:00}:{2:00}", (int)ts.TotalHours, ts.Minutes, ts.Seconds) }; } }
public void ReusesNextFiller() { var stream = new MemoryStream(); var writer = new EbmlWriter(stream); writer.Write(VInt.MakeId(122), 321); using (var segment = writer.StartMasterElement(MatroskaDtd.Segment.Identifier)) { using (var segmentInfo = segment.StartMasterElement(MatroskaDtd.Segment.Info.Identifier)) { segmentInfo.WriteUtf(MatroskaDtd.Segment.Info.Title.Identifier, "Test data"); } // write some dummy data segment.Write(StandardDtd.Void.Identifier, new byte[1000]); segment.Write(VInt.MakeId(123), 123); // marker } stream.Position = 0; // act var infoReader = new SegmentInfoUpdater(); infoReader.Open(stream); infoReader.Title = new string('a', 500); infoReader.Write(); // verify the stream is correct stream.Position = 0; var reader = new EbmlReader(stream); reader.ReadNext(); Assert.AreEqual(122, reader.ElementId.Value, "start marker"); Assert.AreEqual(321, reader.ReadInt()); reader.ReadNext(); Assert.AreEqual(MatroskaDtd.Segment.Identifier, reader.ElementId); reader.EnterContainer(); reader.ReadNext(); Assert.AreEqual(MatroskaDtd.Segment.Info.Identifier, reader.ElementId); Assert.Greater(reader.ElementSize, 500); reader.ReadNext(); Assert.AreEqual(StandardDtd.Void.Identifier, reader.ElementId); reader.ReadNext(); Assert.AreEqual(123, reader.ElementId.Value, "end data marker"); Assert.AreEqual(123, reader.ReadInt()); }
public void SimpleUseCase() { var file = new FileInfo(@"Z:\!\t.mkv"); var segmentInfo = new SegmentInfoUpdater(); segmentInfo.Open(file); Debug.Print("Duration: {0}", segmentInfo.Duration); Debug.Print("MuxingApp: {0}", segmentInfo.MuxingApp); Debug.Print("WritingApp: {0}", segmentInfo.WritingApp); Debug.Print("Title: {0}", segmentInfo.Title); segmentInfo.Title = "s4e16 The Cohabitation Formulation"; segmentInfo.WritingApp = "NEbml.Viewer 0.1"; segmentInfo.Write(); segmentInfo.Close(); }