void RecordScreen() { var buffer = new byte[Params.Width * Params.Height * 4]; var timeTillNextFrame = TimeSpan.Zero; Control.CheckForIllegalCrossThreadCalls = false; bool creatingNewFile = false; while (!closed) { creatingNewFile = false; var startDate = DateTime.Now; 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); while (!stopThread.WaitOne(timeTillNextFrame) && !creatingNewFile) { var timestamp = DateTime.Now; bool captured = Screenshot(buffer); if (captured) { timedWriter.WriteFrame(true, buffer, 0, buffer.Length); } //videoStream.WriteFrame(true, buffer, 0, buffer.Length); timeTillNextFrame = timestamp + frameInterval - DateTime.Now; if (timeTillNextFrame < TimeSpan.Zero) { timeTillNextFrame = TimeSpan.Zero; } if (DateTime.Now.Subtract(startDate).Minutes == 1) { creatingNewFile = true; } } writer.Close(); if (!creatingNewFile) { closed = true; } if (Params.YTUpload) { UploadToYouTube(Params.FileName); Params.FileName = DateTime.Now.ToString("out-yyyy-MM-dd_HH-mm-ss.avi"); } } } }
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 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"; if (Params.AudioSourceId != -1) { try { var waveFormat = Params.WaveFormat; audioStream = Params.CreateAudioStream(writer); audioStream.Name = "Voice"; audioSource = new WaveInEvent { DeviceNumber = Params.AudioSourceId, WaveFormat = waveFormat, // Buffer size to store duration of 1 frame BufferMilliseconds = (int)Math.Ceiling(1000 / writer.FramesPerSecond), NumberOfBuffers = 3, }; audioSource.DataAvailable += AudioDataAvailable; } catch { } } screenThread = new Thread(RecordScreen) { Name = typeof(Recorder).Name + ".RecordScreen", IsBackground = true }; if (audioSource != null) { videoFrameWritten.Set(); audioBlockWritten.Reset(); audioSource.StartRecording(); } screenThread.Start(); }
public Recorder(RecorderParams Params) { this.Params = Params; if (Params.CaptureVideo) { // 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"; } try { int AudioSourceId = int.Parse(Params.AudioSourceId); if (AudioSourceId != -1) { if (Params.CaptureVideo) { audioStream = Params.CreateAudioStream(writer); audioStream.Name = "Voice"; } audioSource = new WaveInEvent { DeviceNumber = AudioSourceId, WaveFormat = Params.WaveFormat, // Buffer size to store duration of 1 frame BufferMilliseconds = (int)Math.Ceiling(1000 / writer.FramesPerSecond), NumberOfBuffers = 3, }; } } catch { var dev = Params.LoopbackDevice; SilencePlayer = new WasapiOut(dev, AudioClientShareMode.Shared, false, 100); SilencePlayer.Init(new SilenceProvider(Params.WaveFormat)); SilencePlayer.Play(); if (Params.CaptureVideo) { audioStream = Params.CreateAudioStream(writer); audioStream.Name = "Loopback"; } audioSource = new WasapiLoopbackCapture(dev) { ShareMode = AudioClientShareMode.Shared }; } if (Params.CaptureVideo) { screenThread = new Thread(RecordScreen) { Name = typeof(Recorder).Name + ".RecordScreen", IsBackground = true }; } else WaveWriter = Params.CreateWaveWriter(); if (Params.CaptureVideo) screenThread.Start(); if (audioSource != null) { audioSource.DataAvailable += AudioDataAvailable; if (Params.CaptureVideo) { videoFrameWritten.Set(); audioBlockWritten.Reset(); } audioSource.StartRecording(); } }