public void TestRecordVideoBasic() { ConsoleBitmap bitmap = new ConsoleBitmap(4, 2), redBitmap = null, greenBitmap = null, magentaPixelBitmap = null; using (var sharedStream = new MemoryStream()) { using (var bitmapVideoWriter = new ConsoleBitmapStreamWriter(sharedStream) { CloseInnerStream = false }) { bitmap = new ConsoleBitmap(4, 2); redBitmap = bitmapVideoWriter.WriteFrame(bitmap.FillRect(ConsoleCharacter.RedBG())).Clone(); greenBitmap = bitmapVideoWriter.WriteFrame(bitmap.FillRect(ConsoleCharacter.GreenBG())).Clone(); magentaPixelBitmap = bitmapVideoWriter.WriteFrame(bitmap.DrawPoint(ConsoleCharacter.MagentaBG(), 0, 0)).Clone(); } sharedStream.Position = 0; // rewind the stream to the beginning to read it back // create a reader and make sure we can read each frame back exactly as they were written var bitmapVideoReader = new ConsoleBitmapStreamReader(sharedStream); Assert.AreEqual(redBitmap, bitmapVideoReader.ReadFrame().CurrentBitmap); Assert.AreEqual(greenBitmap, bitmapVideoReader.ReadFrame().CurrentBitmap); Assert.AreEqual(magentaPixelBitmap, bitmapVideoReader.ReadFrame().CurrentBitmap); Assert.IsNull(bitmapVideoReader.ReadFrame().CurrentFrame); } }
public void TestRecordVideoLargeVideo() { ConsoleBitmap bitmap = new ConsoleBitmap(1, 1); var numFrames = 10000; using (var sharedStream = new MemoryStream()) { var bitmapVideoWriter = new ConsoleBitmapStreamWriter(sharedStream) { CloseInnerStream = false }; for (var i = 0; i < numFrames; i++) { bitmapVideoWriter.WriteFrame(bitmap, true, TimeSpan.FromMilliseconds(i)); } bitmapVideoWriter.Dispose(); sharedStream.Position = 0; // rewind the stream to the beginning to read it back var destination = TimeSpan.Zero; var reader = new ConsoleBitmapStreamReader(sharedStream); var video = reader.ReadToEnd(); var lastFrameIndex = 0; var sw = Stopwatch.StartNew(); while ((lastFrameIndex = video.Seek(destination, out bitmap, lastFrameIndex >= 0 ? lastFrameIndex : 0)) != numFrames - 1) { destination = destination.Add(TimeSpan.FromMilliseconds(1)); } sw.Stop(); Assert.IsTrue(sw.ElapsedMilliseconds < 10); Console.WriteLine($"Playback took {sw.ElapsedMilliseconds} ms"); } }
public bool TryGetCurrentRecording(out ConsoleBitmapStreamReader reader) => TryGetRecording(CurrentTestRecordingFilePath, out reader);