public void Stop() { _ScreenSource.SignalToStop(); _ScreenSource.Stop(); _CameraSource.SignalToStop(); _CameraSource.Stop(); _Writer.Close(); _Writer.Dispose(); }
public void Stop() { if (vf == null) { return; } timer1.Stop(); lock (vf) { vf.Close(); } vf.Dispose(); }
private static void reencode(FileInfo fileInput, FileInfo fileOutput, VideoCodec outputCodec, AVPixelFormat format = AVPixelFormat.FormatYuv420P, double expectedFrameRate = 2997 / 100.0) { using (var videoFileReader = new Accord.Video.FFMPEG.VideoFileReader()) { videoFileReader.Open(fileInput.FullName); using (var videoFileWriter = new Accord.Video.FFMPEG.VideoFileWriter()) { Assert.AreEqual(2997, videoFileReader.FrameRate.Numerator); Assert.AreEqual(100, videoFileReader.FrameRate.Denominator); videoFileWriter.Width = videoFileReader.Width; videoFileWriter.Height = videoFileReader.Height; videoFileWriter.FrameRate = videoFileReader.FrameRate; videoFileWriter.VideoCodec = outputCodec; Assert.AreEqual(AVPixelFormat.FormatYuv420P, videoFileWriter.PixelFormat); videoFileWriter.PixelFormat = format; videoFileWriter.Open(fileOutput.FullName); do { using (var bitmap = videoFileReader.ReadVideoFrame()) { if (bitmap == null) { break; } videoFileWriter.WriteVideoFrame(bitmap); } }while (true); videoFileWriter.Close(); } videoFileReader.Close(); } using (var videoFileReader = new Accord.Video.FFMPEG.VideoFileReader()) { videoFileReader.Open(fileOutput.FullName); Assert.AreEqual(expectedFrameRate, videoFileReader.FrameRate.Value, 0.01); } }
private static void reencode(FileInfo fileInput, FileInfo fileOutput, VideoCodec outputCodec) { using (var videoFileReader = new Accord.Video.FFMPEG.VideoFileReader()) { videoFileReader.Open(fileInput.FullName); using (var videoFileWriter = new Accord.Video.FFMPEG.VideoFileWriter()) { Assert.AreEqual(2997, videoFileReader.FrameRate.Numerator); Assert.AreEqual(100, videoFileReader.FrameRate.Denominator); videoFileWriter.Open ( fileOutput.FullName, videoFileReader.Width, videoFileReader.Height, videoFileReader.FrameRate, outputCodec ); do { using (var bitmap = videoFileReader.ReadVideoFrame()) { if (bitmap == null) { break; } videoFileWriter.WriteVideoFrame(bitmap); } }while (true); videoFileWriter.Close(); } videoFileReader.Close(); } using (var videoFileReader = new Accord.Video.FFMPEG.VideoFileReader()) { videoFileReader.Open(fileOutput.FullName); Assert.AreEqual(2997 / 100.0, videoFileReader.FrameRate.Value, 0.01); } }
public void Run_Btn_Click(object sender, EventArgs e) { isNeedAudio = isNeedAudio_Checkbox.Checked; switch (run_btn.Text) { case "開始錄影 (F2)": write_finish = false; renew_path(); isRecording = true; run_btn.Text = "停止錄影 (F2)"; f2.can_drag = false; videoOption.V_l = f2.Left; videoOption.V_t = f2.Top; videoOption.V_w = f2.Width; videoOption.V_h = f2.Height; int width = videoOption.V_w; int height = videoOption.V_h; //from https://en.code-bude.net/2013/04/17/how-to-create-video-files-in-c-from-single-images/ /*my.file_put_contents(video_path, "");*/ //writer.Open("C:\\temp\\a.avi", V_w, V_h); show_hide_f2(false); writer = new VideoFileWriter(); int w = Convert.ToInt32(Math.Ceiling(videoOption.V_w / 10.0)) * 10; int h = Convert.ToInt32(Math.Ceiling(videoOption.V_h / 10.0)) * 10; int videoBitRate = w * h * 3 * 30; //int videoBitRate = 1200 * 1000; //int audioBitRate = 320 * 1000; if (isNeedAudio) { //audio = new AudioCaptureDevice(); //audio.Format = Accord.Audio.SampleFormat.Format16Bit; //audio.SampleRate = 22050;// Accord.DirectSound.Accord.Audio.Tools.Default.SampleRate; //audio.DesiredFrameSize = 4096; //audio.NewFrame += audioDevice_NewFrame; //audio.DesiredFrameSize = 4096; //mciSendString("open new Type waveaudio alias recsound", null, 0, IntPtr.Zero); //mciSendString("set capture time format ms bitspersample 16 channels 2 samplespersec 48000 bytespersec 192000 alignment 4", null, 0, IntPtr.Zero); //mciSendString("record recsound", null, 0, IntPtr.Zero); //alert("gg"); //writer.Open(video_path, w, h, 30, VideoCodec.H264, videoBitRate, AudioCodec.MP3, audioBitRate, 44100,1); //writer.Open(video_path, w, h, 30, VideoCodec.H264, videoBitRate); //audio = new WasapiLoopbackCapture(); //audio.Initialize(); //audio_w = new WaveWriter(audio_path, audio.WaveFormat); //setup an eventhandler to receive the recorded data //audio.DataAvailable += (s, ee) => // { //save the recorded audio // audio_w.Write(ee.Data, ee.Offset, ee.ByteCount); // }; //start recording //audio.Start(); //Console.ReadKey(); system_audio = new WasapiLoopbackCapture(); //system_audio = new WasapiLoopbackCapture(); //wtf.DataAvailable //waveSource.WaveFormat = new WaveFormat(44100, 2); system_audio.DataAvailable += new EventHandler <WaveInEventArgs>(waveSource_DataAvailable); //system_audio.DataAvailable += (s, ee) => // { //save the recorded audio // waveSource_DataAvailable(s, ee); //audio_w.Write(ee.Data, ee.Offset, ee.ByteCount); // }; system_audio.RecordingStopped += new EventHandler <StoppedEventArgs>(waveSource_RecordingStopped); waveFile = new WaveFileWriter(audio_path, system_audio.WaveFormat); system_audio.StartRecording(); // system_audio.StartRecording(); } writer.Open(video_path, w, h, 30, VideoCodec.H264, videoBitRate); // //msc = new Thread(thread_msc); // msc.Start(); timer1.Enabled = true; sc = new Thread(thread_sc); sc.Start(); break; default: show_hide_f2(true); run_btn.Text = "開始錄影 (F2)"; f2.can_drag = true; isRecording = false; if (isNeedAudio) { //mciSendString("save recsound " + audio_path, null, 0, IntPtr.Zero); //mciSendString("close recsound", null, 0, IntPtr.Zero); //https://github.com/accord-net/framework/issues/418 //byte[] bffr = File.ReadAllBytes(audio_path); //writer.WriteAudioFrame() //writer.WriteAudioFrame() // // audio.Stop(); // audio.Dispose(); //audio = null; //audio_w.Dispose(); //audio_w = null; //GC.Collect(); //audio.Dispose(); system_audio.StopRecording(); if (system_audio != null) { system_audio.Dispose(); system_audio = null; } if (waveFile != null) { waveFile.Dispose(); waveFile = null; } // system_audio.StopRecording(); // system_audio.Dispose(); //my.copy(audio_path, _nt); //sc.Abort(); //Thread.Sleep(1000); //GC.Collect(); while (write_finish == false) { Thread.Sleep(10); } writer.Close(); writer = null; AviManager aviManager = new AviManager(video_path, true); aviManager.AddAudioStream(audio_path, 0); aviManager.Close(); timer1.Enabled = false; my.unlink(audio_path); } break; } }
public void finalize() { encoder.Close(); }