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(); } }