/// <summary> /// Records this instance. /// </summary> /// <exception cref="RedCell.Research.ResearchException"> /// Filename must be set before recording. /// or /// A recording has already started. /// </exception> /// <exception cref="System.InvalidOperationException">Filename must be set before recording.</exception> public void StartRecord() { // Automatic filename if (string.IsNullOrWhiteSpace(Filename)) Filename = "Video_" + DateTime.Now.ToString("yyyyMMddHHmmss"); if(_writer != null) throw new ResearchException("A recording has already started."); // Get video details from camera. if (StreamSetting == null) StreamSetting = Camera.StreamSetting; var encoder = new Mpeg4VideoEncoderVcm(StreamSetting.Width, StreamSetting.Height, StreamSetting.Framerate, 0, 50, KnownFourCCs.Codecs.X264); _writer = new AviWriter(Filename); _video = _writer.AddEncodingVideoStream(encoder, true, StreamSetting.Width, StreamSetting.Height); Camera.FrameAvailable += Camera_FrameAvailable; }
private bool StartRecording() { int captureWidth = (int)(m_Capture.CaptureBounds.Width * m_Capture.Scale), captureHeight = (int)(m_Capture.CaptureBounds.Height * m_Capture.Scale), codecSelectedIndex = comboBox_videoCodec.SelectedIndex, codecQuality = Convert.ToInt32(textBox_recordQuality.Text); try { m_AviWriter = new AviWriter(m_AviFilePath) { FramesPerSecond = m_Capture.FramesPerSecond, EmitIndex1 = true, }; if (codecSelectedIndex == 0) { m_AviVideoStream = m_AviWriter.AddVideoStream(captureWidth, captureHeight); } else if (codecSelectedIndex == 1) { m_AviVideoStream = m_AviWriter.AddMotionJpegVideoStream(captureWidth, captureHeight, codecQuality); } else { var codecs = Mpeg4VideoEncoderVcm.GetAvailableCodecs(); var encoder = new Mpeg4VideoEncoderVcm(captureWidth, captureHeight, m_Capture.FramesPerSecond, 0, codecQuality, codecs[codecSelectedIndex - 2].Codec); m_AviVideoStream = m_AviWriter.AddEncodingVideoStream(encoder); } if (checkBox_recordAudio.Checked) { m_AviAudioStream = m_AviWriter.AddAudioStream(m_Recorder.WaveFormat.Channels, m_Recorder.WaveFormat.SampleRate, m_Recorder.WaveFormat.BitsPerSample); } } catch { Debug.Log("Failed to Start Recording."); return false; } return true; }
private void LoadSettings() { try { writer = new AviWriter("test.avi") { FramesPerSecond = 25, // Emitting AVI v1 index in addition to OpenDML index (AVI v2) // improves compatibility with some software, including // standard Windows programs like Media Player and File Explorer EmitIndex1 = true }; var encoder = new Mpeg4VideoEncoderVcm((int)numericWidth.Value, (int)numericHeight.Value, 25, 0, 100, KnownFourCCs.Codecs.Xvid); // stream = writer.AddMotionJpegVideoStream(640, 480, quality: 100); //stream = writer.AddMpeg4VideoStream(640, 480, 30, quality: 70, codec: KnownFourCCs.Codecs.X264, forceSingleThreadedAccess: true); stream = writer.AddEncodingVideoStream(encoder, true, (int)numericWidth.Value, (int)numericHeight.Value); // set standard VGA resolution // stream.Width = 640; // stream.Height = 480; // class SharpAvi.KnownFourCCs.Codecs contains FOURCCs for several well-known codecs // Uncompressed is the default value, just set it for clarity //stream.Codec = KnownFourCCs.Codecs.MotionJpeg; // Uncompressed format requires to also specify bits per pixel //stream.BitsPerPixel = BitsPerPixel.Bpp32; } catch (Exception ex) { Console.WriteLine(ex.Message); } }