public Recorder(RecorderParams Params) { this.Params = Params; // Create AVI writer and specify FPS writer = Params.CreateAviWriter(); // Create video stream videoStream = Params.CreateVideoStream(writer); // Set only name. Other properties were when creating stream, // either explicitly by arguments or implicitly by the encoder used videoStream.Name = "Captura"; screenThread = new Thread(RecordScreen) { Name = typeof(Recorder).Name + ".RecordScreen", IsBackground = true }; //screenThread.Start(); }
public void Run() { var di = new DirectoryInfo(ImageDirectory); var buffer = new byte[Params.Width * Params.Height * 4]; //Task videoWriteTask = null; //1403-1458 - ready: aoc face removal // 1459 - 1509 //1510 - 1529 - reay aoc face removal 2 //1530 - 1572 //1573 - 1597 - ready aoc face removal 3 //1598 - 1633 var timeTillNextFrame = TimeSpan.Zero; ManualResetEvent stopThread = new ManualResetEvent(false); using (var writer = Params.CreateAviWriter()) { var frameInterval = TimeSpan.FromSeconds(1 / (double)writer.FramesPerSecond); var videoStream = Params.CreateVideoStream(writer); videoStream.Name = "Captura"; var timedWriter = new TimedFrameWriter(videoStream, writer, Params); for (var i = StartFrame; /*!stopThread.WaitOne(timeTillNextFrame) &&*/ i >= EndFrame; i--) { var timestamp = DateTime.Now; //var fileName = $"facescan{i.ToString().PadLeft(3,'0')}-movie.png"; //ouA-2021-02-05_12-19-15001-movie-final.png var fileName = FileNameFormat.Replace("{x}", i.ToString().PadLeft(3, '0'));// $"faceoff -{i.ToString().PadLeft(3, '0')}.png"; var path = Path.Combine(di.FullName, fileName); if (File.Exists(path)) { //buffer = File.ReadAllBytes(path); } else { fileName = $"aocfacecut-{i.ToString().PadLeft(4, '0')}.png"; path = Path.Combine(di.FullName, fileName); //buffer = File.ReadAllBytes(path); } if (!File.Exists(path)) { continue; string bp = "Bad file"; } GetBuffer(path, buffer); //Screenshot(buffer); videoStream.WriteFrame(true, buffer, 0, buffer.Length); //timedWriter.WriteFrame(true, buffer, 0, buffer.Length); timeTillNextFrame = timestamp + frameInterval - DateTime.Now; if (timeTillNextFrame < TimeSpan.Zero) { timeTillNextFrame = TimeSpan.Zero; } } timedWriter.Close(); writer.Close(); } }