private void button_Start_Click(object sender, RoutedEventArgs e) { //MessageBox.Show(this.user.PointFromScreen(new System.Windows.Point()).X.ToString()); System.Drawing.Rectangle r = new System.Drawing.Rectangle((int)this.webMap.PointToScreen(new System.Windows.Point()).X, (int)this.webMap.PointToScreen(new System.Windows.Point()).Y, (int)webMap.Width, (int)webMap.Height); System.Windows.MessageBox.Show(r.X + " " + r.Y + " " + r.Width + " " + r.Height); //TODO 开始录制桌面,依据 声音复选框 来选择使用 声卡 麦克风 还是混合录制 //TODO label 中显示实际录制的时间,需要考虑暂停和恢复这种情况。 格式为 hh:mm:ss try { int audioSampleRate = 16000; int channelCount = 2; seconds = 0; System.Drawing.Size videoSize = Screen.PrimaryScreen.Bounds.Size; #region 设置采集器 //桌面采集器 //如果需要录制鼠标的操作,第二个参数请设置为true this.desktopCapturer = CapturerFactory.CreateDesktopCapturer(frameRate, false, r); this.desktopCapturer.ImageCaptured += ImageCaptured; videoSize = this.desktopCapturer.VideoSize; //声卡采集器 【目前声卡采集仅支持vista以及以上系统】 this.soundcardCapturer = CapturerFactory.CreateSoundcardCapturer(); this.soundcardCapturer.CaptureError += capturer_CaptureError; audioSampleRate = this.soundcardCapturer.SampleRate; this.soundcardCapturer.AudioCaptured += audioMixter_AudioMixed; #endregion #region 开始采集 this.soundcardCapturer.Start(); this.desktopCapturer.Start(); #endregion #region 录制组件 this.justRecordVideo = false; this.videoFileMaker = new VideoFileMaker(); this.videoFileMaker.Initialize("test.mp4", VideoCodecType.H264, videoSize.Width, videoSize.Height, frameRate, VideoQuality.High, AudioCodecType.AAC, audioSampleRate, channelCount, true); #endregion this.isRecording = true; this.isParsing = false; this.timer.Start(); this.btn_Start.IsEnabled = false; } catch (Exception ee) { System.Windows.MessageBox.Show(ee.Message); } }
//开始桌面、麦克风、声卡 采集、录制 private void button1_Click(object sender, EventArgs e) { try { this.audioCount = 0; int frameRate = 15; this.desktopCapturer = CapturerFactory.CreateDesktopCapturer(frameRate, false); this.desktopCapturer.ImageCaptured += new CbGeneric <Bitmap>(desktopCapturer_ImageCaptured); //声卡采集器 【目前声卡采集仅支持vista以及以上系统】 this.soundcardCapturer = CapturerFactory.CreateSoundcardCapturer(); //麦克风采集器 this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(0); //混音器 this.audioMixter = CapturerFactory.CreateAudioMixter(this.microphoneCapturer, this.soundcardCapturer, SoundcardMode4Mix.DoubleChannel, true); this.audioMixter.AudioMixed += new CbGeneric <byte[]>(audioMixter_AudioMixed); this.microphoneCapturer.CaptureError += new CbGeneric <Exception>(capturer_CaptureError); this.soundcardCapturer.CaptureError += new CbGeneric <Exception>(capturer_CaptureError); //开始采集 this.microphoneCapturer.Start(); this.soundcardCapturer.Start(); this.desktopCapturer.Start(); //录制组件 this.videoFileMaker = new VideoFileMaker(); Size videoSize = Screen.PrimaryScreen.Bounds.Size; this.sizeRevised = (videoSize.Width % 4 != 0) || (videoSize.Height % 4 != 0); if (this.sizeRevised) { videoSize = new Size(videoSize.Width / 4 * 4, videoSize.Height / 4 * 4); } this.videoFileMaker.Initialize("test.mp4", VideoCodecType.H264, videoSize.Width, videoSize.Height, frameRate, VideoQuality.High, AudioCodecType.AAC, this.audioMixter.SampleRate, this.audioMixter.ChannelCount, true); this.isRecording = true; this.button_startRecord.Enabled = false; this.button_stopRecord.Enabled = true; this.label_recording.Visible = true; } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void StopRecordAsyn() { this.isRecording = false; this.desktopCapturer.Stop(); this.desktopCapturer.Dispose(); this.microphoneCapturer.Stop(); this.microphoneCapturer.Dispose(); this.soundcardCapturer.Stop(); this.soundcardCapturer.Dispose(); //必须要释放声卡采集器!!!!!!!! this.audioMixter.Dispose(); this.videoFileMaker.Close(true); this.videoFileMaker.Dispose(); this.videoFileMaker = null; this.AfterStopRecord(); }
//初始化录像设备,并开始录制。 public void Initialize(string filePath) { if (!this.dynamicCameraConnector2Friend.Connected) { throw new Exception("连接器尚未连接到对方的摄像头!"); } this.videoSize = this.dynamicCameraConnector2Friend.VideoSize; Size myVideoSize = new Size(this.videoSize.Width / 3, this.videoSize.Height / 3); this.myVideoRect = new Rectangle(this.videoSize.Width - myVideoSize.Width, this.videoSize.Height - myVideoSize.Height, myVideoSize.Width, myVideoSize.Height); this.videoFileMaker = new VideoFileMaker(); this.videoFileMaker.AutoDisposeVideoFrame = true; this.videoFileMaker.Initialize(filePath, VideoCodecType.H264, this.videoSize.Width, this.videoSize.Height, 10, VideoQuality.High, AudioCodecType.AAC, 16000, 1, true); this.audioInOutMixer.Initialize(this.multimediaManager); this.isRecording = true; CbGeneric cb = new CbGeneric(this.RecordThread); cb.BeginInvoke(null, null); }
public Mp4FileAccessRecorder() : base() { this.videoFileMaker = new VideoFileMaker(); }
private void button_Start_Click(object sender, RoutedEventArgs e) { //TODO 开始录制桌面,依据 声音复选框 来选择使用 声卡 麦克风 还是混合录制 //TODO label 中显示实际录制的时间,需要考虑暂停和恢复这种情况。 格式为 hh:mm:ss if (string.IsNullOrEmpty(this.filePath.Text) || string.IsNullOrEmpty(this.fileNmae.Text)) { MessageBox.Show("文件路径和文件名!"); return; } else if (File.Exists(System.IO.Path.Combine(this.filePath.Text, this.fileNmae.Text))) { MessageBox.Show("文件已经存在"); return; } try { int audioSampleRate = 16000; int channelCount = 1; seconds = 0; System.Drawing.Size videoSize = Screen.PrimaryScreen.Bounds.Size; this.justRecordAudio = this.radioButton_justAudio.IsChecked.Value; if (this.justRecordAudio && this.checkBox_micro.IsChecked == false && this.checkBox_soundCard.IsChecked == false) { MessageBox.Show("一定要选择一个声音的采集源!"); return; } #region 设置采集器 if (this.radioButton_desktop.IsChecked == true) { //桌面采集器 //如果需要录制鼠标的操作,第二个参数请设置为true this.desktopCapturer = CapturerFactory.CreateDesktopCapturer(frameRate, false); this.desktopCapturer.ImageCaptured += ImageCaptured; videoSize = this.desktopCapturer.VideoSize; } else if (this.radioButton_camera.IsChecked == true) { //摄像头采集器 videoSize = new System.Drawing.Size(int.Parse(this.textBox_width.Text), int.Parse(this.textBox_height.Text)); this.cameraCapturer = CapturerFactory.CreateCameraCapturer(0, videoSize, frameRate); this.cameraCapturer.ImageCaptured += new CbGeneric <Bitmap>(ImageCaptured); } if (this.checkBox_micro.IsChecked == true) { //麦克风采集器 this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(0); this.microphoneCapturer.CaptureError += capturer_CaptureError; } if (this.checkBox_soundCard.IsChecked == true) { //声卡采集器 【目前声卡采集仅支持vista以及以上系统】 this.soundcardCapturer = CapturerFactory.CreateSoundcardCapturer(); this.soundcardCapturer.CaptureError += capturer_CaptureError; audioSampleRate = this.soundcardCapturer.SampleRate; channelCount = this.soundcardCapturer.ChannelCount; } if (this.checkBox_micro.IsChecked == true && this.checkBox_soundCard.IsChecked == true) { //混音器 this.audioMixter = CapturerFactory.CreateAudioMixter(this.microphoneCapturer, this.soundcardCapturer, SoundcardMode4Mix.DoubleChannel, true); this.audioMixter.AudioMixed += audioMixter_AudioMixed; //如果是混音,则不再需要预订microphoneCapturer和soundcardCapturer的AudioCaptured事件 audioSampleRate = this.audioMixter.SampleRate; channelCount = this.audioMixter.ChannelCount; } else if (this.checkBox_micro.IsChecked == true) { this.microphoneCapturer.AudioCaptured += audioMixter_AudioMixed; } else if (this.checkBox_soundCard.IsChecked == true) { this.soundcardCapturer.AudioCaptured += audioMixter_AudioMixed; } #endregion #region 开始采集 if (this.checkBox_micro.IsChecked == true) { this.microphoneCapturer.Start(); } if (this.checkBox_soundCard.IsChecked == true) { this.soundcardCapturer.Start(); } if (this.radioButton_camera.IsChecked == true) { this.cameraCapturer.Start(); } else if (this.radioButton_desktop.IsChecked == true) { this.desktopCapturer.Start(); } #endregion #region 录制组件 if (this.justRecordAudio) //仅仅录制声音 { this.audioFileMaker = new AudioFileMaker(); this.audioFileMaker.Initialize("test.mp3", audioSampleRate, channelCount); } else { //宽和高修正为4的倍数 this.sizeRevised = (videoSize.Width % 4 != 0) || (videoSize.Height % 4 != 0); if (this.sizeRevised) { videoSize = new System.Drawing.Size(videoSize.Width / 4 * 4, videoSize.Height / 4 * 4); } if (this.checkBox_micro.IsChecked == false && this.checkBox_soundCard.IsChecked == false) //仅仅录制图像 { this.justRecordVideo = true; this.silenceVideoFileMaker = new SilenceVideoFileMaker(); this.silenceVideoFileMaker.Initialize(System.IO.Path.Combine(this.filePath.Text, this.fileNmae.Text) + ".mp4", VideoCodecType.H264, videoSize.Width, videoSize.Height, frameRate, VideoQuality.Middle); } else //录制声音+图像 { this.justRecordVideo = false; this.videoFileMaker = new VideoFileMaker(); this.videoFileMaker.Initialize(System.IO.Path.Combine(this.filePath.Text, this.fileNmae.Text) + ".mp4", VideoCodecType.H264, videoSize.Width, videoSize.Height, frameRate, VideoQuality.High, AudioCodecType.AAC, audioSampleRate, channelCount, true); } } #endregion this.isRecording = true; this.isParsing = false; this.timer.Start(); this.checkBox_micro.IsEnabled = false; this.checkBox_soundCard.IsEnabled = false; this.radioButton_desktop.IsEnabled = false; this.radioButton_camera.IsEnabled = false; this.radioButton_justAudio.IsEnabled = false; this.button_Start.IsEnabled = false; } catch (Exception ee) { MessageBox.Show(ee.Message); } }