/// <summary> /// Stops recording. /// </summary> /// public void StopRecording() { if (!IsRecording) { return; } lock (syncObj) { IsRecording = false; if (videoWriter != null) { videoWriter.Close(); videoWriter.Dispose(); videoWriter = null; } if (audioMixer != null) { audioMixer.Stop(); foreach (IAudioSource source in audioMixer.Sources) { source.Stop(); source.Dispose(); } audioMixer.Dispose(); audioMixer = null; } HasRecorded = true; } }
private void StartButton_Click(object sender, System.EventArgs e) { IsRecording = true; RecordingStartTime = System.DateTime.MinValue; if (AudioCaptureDevice != null) { AudioCaptureDevice.Start(); } if (AudioSourceMixer != null) { AudioSourceMixer.Start(); } timerRecording.Start(); }
private void StopButton_Click(object sender, System.EventArgs e) { IsRecording = false; if (AudioSourceMixer != null) { AudioSourceMixer.Stop(); //AudioSourceMixer.WaitForStop(); } if (AudioCaptureDevice != null) { AudioCaptureDevice.Stop(); //AudioCaptureDevice.WaitForStop(); } timerRecording.Stop(); VideoFileWriter.Close(); }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// /// <param name="disposing"><c>true</c> to release both managed /// and unmanaged resources; <c>false</c> to release only unmanaged /// resources.</param> /// void Dispose(bool disposing) { if (disposing) { // free managed resources if (clickCapture != null) { clickCapture.Dispose(); clickCapture = null; } if (cursorCapture != null) { cursorCapture.Dispose(); cursorCapture = null; } if (keyCapture != null) { keyCapture.Dispose(); keyCapture = null; } if (audioMixer != null) { audioMixer.Dispose(); audioMixer = null; } if (videoWriter != null) { videoWriter.Dispose(); videoWriter = null; } } }
/// <summary> /// Starts recording. Only works if the player has /// already been started and is grabbing frames. /// </summary> /// public void StartRecording() { if (IsRecording || !IsPlaying) { return; } Rectangle area = CaptureRegion; string fileName = NewFileName(); int height = area.Height; int width = area.Width; Rational framerate = new Rational(1000, screenStream.FrameInterval); int videoBitRate = 1200 * 1000; int audioBitRate = 320 * 1000; int audioFrameSize = 10 * 4096; OutputPath = Path.Combine(main.CurrentDirectory, fileName); RecordingStartTime = DateTime.MinValue; videoWriter = new VideoFileWriter(); videoWriter.BitRate = videoBitRate; videoWriter.FrameRate = framerate; videoWriter.Width = width; videoWriter.Height = height; videoWriter.VideoCodec = VideoCodec.H264; videoWriter.VideoOptions["crf"] = "18"; // visually lossless videoWriter.VideoOptions["preset"] = "veryfast"; videoWriter.VideoOptions["tune"] = "zerolatency"; videoWriter.VideoOptions["x264opts"] = "no-mbtree:sliced-threads:sync-lookahead=0"; // Create audio devices which have been checked var audioDevices = new List <AudioCaptureDevice>(); foreach (var audioViewModel in AudioCaptureDevices) { if (!audioViewModel.Checked) { continue; } var device = new AudioCaptureDevice(audioViewModel.DeviceInfo); device.AudioSourceError += Device_AudioSourceError; device.Format = SampleFormat.Format32BitIeeeFloat; device.SampleRate = Settings.Default.SampleRate; device.DesiredFrameSize = audioFrameSize; device.Start(); audioDevices.Add(device); } if (audioDevices.Count > 0) // Check if we need to record audio { audioMixer = new AudioSourceMixer(audioDevices); audioMixer.AudioSourceError += Device_AudioSourceError; audioMixer.NewFrame += AudioDevice_NewFrame; audioMixer.Start(); videoWriter.AudioBitRate = audioBitRate; videoWriter.AudioCodec = AudioCodec.Aac; videoWriter.AudioLayout = audioMixer.NumberOfChannels == 1 ? AudioLayout.Mono : AudioLayout.Stereo; videoWriter.FrameSize = audioFrameSize; videoWriter.SampleRate = audioMixer.SampleRate; } //this.lastFrameTime = DateTime.MinValue; videoWriter.Open(OutputPath); HasRecorded = false; IsRecording = true; }