protected CaptureBase(CaptureType type) { switch (type) { case CaptureType.Desktop: { this.mCapturer = CapturerFactory.CreateDesktopCapturer(10, true); ((IDesktopCapturer)this.mCapturer).ImageCaptured += Capture; break; } case CaptureType.Audio: { ((IMicrophoneCapturer)this.mCapturer).AudioCaptured += Capture; break; } case CaptureType.Camera: { this.mCapturer = CapturerFactory.CreateCameraCapturer(0, new Size(640, 480), 20); ((ICameraCapturer)this.mCapturer).ImageCaptured += Capture; break; } } }
private void VoiceChat() { epVoiceLocal = new IPEndPoint(IPAddress.Parse(textBox1.Text), Convert.ToInt32("90")); epVoiceRemote = new IPEndPoint(IPAddress.Parse(textBox2.Text), Convert.ToInt32("90")); sckVoice.Bind(epVoiceLocal); sckVoice.Connect(epVoiceRemote); /* * vc.sckSetter(sckVoice); * vc.intPtr = this.Handle; * vc.CreatePalyDevice(); * vc.CreateSecondaryBuffer(); */ this.audioPlayer = PlayerFactory.CreateAudioPlayer(int.Parse("0"), 16000, 1, 16, 2); byte[] bytData = new byte[999999]; while (true) { if (sckVoice.Poll(5000, SelectMode.SelectRead)) { if (flag == true) { //vc.StartRecord("C:\\Users\\zbyclar\\Desktop\\test2.wav"); this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(int.Parse("0")); this.microphoneCapturer.Start(); this.microphoneCapturer.AudioCaptured += new ESBasic.CbGeneric <byte[]>(microphoneCapturer_AudioCaptured); flag = false; } //Console.WriteLine("There are voices !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); sckVoice.BeginReceiveFrom(bytData, 0, bytData.Length, SocketFlags.None, ref epVoiceRemote, new AsyncCallback(ReceiveData), null); } } }
private void start_Click(object sender, RoutedEventArgs e) { this.isRecording = true; System.Drawing.Size videoSize = Screen.PrimaryScreen.Bounds.Size; System.Drawing.Rectangle myRect = new System.Drawing.Rectangle(); RECT rct = new RECT(); GetWindowRect(new HandleRef(this, new WindowInteropHelper(this).Handle), out rct); myRect.X = rct.Left; myRect.Y = rct.Top; myRect.Width = rct.Right - rct.Left + 1; myRect.Height = rct.Bottom - rct.Top + 1; this.desktopCapturer = CapturerFactory.CreateDesktopCapturer(frameRate, false, myRect); this.desktopCapturer.ImageCaptured += ImageCaptured; videoSize = this.desktopCapturer.VideoSize; this.desktopCapturer.Start(); this.start.IsEnabled = false; 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); } string time = System.DateTime.Now.ToString("hh'-'mm'-'ss", CultureInfo.CurrentUICulture.DateTimeFormat); this.silenceVideoFileMaker = new SilenceVideoFileMaker(); this.silenceVideoFileMaker.Initialize("E:\\testDir\\" + time + ".mp4", VideoCodecType.H264, videoSize.Width, videoSize.Height, frameRate, VideoQuality.High); }
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 accumulater frameCounter = new accumulater(); //帧数计数器 /*【大致思路】 * 程序启动时开启采集,用分贝显示器来获取每一帧的分贝。 * 在采集事件处理函数中轮询分贝值。 * 如果分贝值高于一定值,开启录制 * 如果分贝值低于一定值,低分贝计数器加一,帧数计数器加一 * 如果低分贝计数器在一定帧数内,低分贝计数器等于帧数计数器,即该段时间内持续低分贝,关闭录制 */ public Form1() { InitializeComponent(); this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(0); //采集器,启动程序时即开启 this.microphoneCapturer.AudioCaptured += new ESBasic.CbGeneric <byte[]>(microphoneCapturer_AudioCaptured); //预定采集事件 this.microphoneCapturer.Start(); //开始采集 //初始化录制器所需的参数 this.audioFileMaker.Initialize("test.mp3", this.microphoneCapturer.SampleRate, this.microphoneCapturer.ChannelCount); }
private void button1_Click(object sender, EventArgs e) { //capture image from camera device this.cameraCapturer = CapturerFactory.CreateCameraCapturer(0, new Size(int.Parse("320"), int.Parse("240")), 20); this.cameraCapturer.ImageCaptured += new ESBasic.CbGeneric <Bitmap>(ImageCaptured); this.cameraCapturer.Start(); //At the same time, capture voice from microphone device this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(int.Parse("0")); this.microphoneCapturer.AudioCaptured += new ESBasic.CbGeneric <byte[]>(microphoneCapturer_AudioCaptured); this.microphoneCapturer.Start(); flag = false; }
//开始桌面、麦克风、声卡 采集、录制 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 button2_Click(object sender, EventArgs e) { try { //vc.StartRecord("C:\\Users\\zbyclar\\Desktop\\test1.wav"); this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(int.Parse("0")); this.microphoneCapturer.Start(); this.microphoneCapturer.AudioCaptured += new ESBasic.CbGeneric <byte[]>(microphoneCapturer_AudioCaptured); flag = false; } catch (Exception ex) { Console.WriteLine(ex); } }
private void VideoChat() { epVideoLocal = new IPEndPoint(IPAddress.Parse(textBox1.Text), Convert.ToInt32("110")); epVideoRemote = new IPEndPoint(IPAddress.Parse(textBox2.Text), Convert.ToInt32("110")); sckVideo.Bind(epVideoLocal); sckVideo.Connect(epVideoRemote); while (true) { if (sckVideo.Poll(5000, SelectMode.SelectRead)) { if (flag == true) { //capture image from camera device this.cameraCapturer = CapturerFactory.CreateCameraCapturer(0, new Size(int.Parse("320"), int.Parse("240")), 20); this.cameraCapturer.ImageCaptured += new ESBasic.CbGeneric <Bitmap>(ImageCaptured); this.cameraCapturer.Start(); //At the same time, capture voice from microphone device this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(int.Parse("0")); this.microphoneCapturer.AudioCaptured += new ESBasic.CbGeneric <byte[]>(microphoneCapturer_AudioCaptured); this.microphoneCapturer.Start(); flag = false; } Console.WriteLine("There are both images and voice !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); MemoryStream ms = new MemoryStream(); int size = 0; while (size < 230454) { byte[] img = new byte[230454]; int r = sckVideo.Receive(img, img.Length, SocketFlags.None); size = size + r; Console.WriteLine("This time, there are " + r + " datagrams" + "\n" + "And in total " + size + " have been received"); ms.Write(img, 0, r); } if (size == 230454) { Form1_ImageCaptured(StreamToBitmap(ms)); } } } }
/// <summary> /// 初始化声音收集器 /// </summary> /// <param name="outFileName">输出MP3文件名</param> /// <param name="microphoneIndex">第几个麦克风,默认为第一个(0)</param> public void InitialCapturer(string outFileName, int microphoneIndex = 0) { microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(microphoneIndex); microphoneCapturer.AudioCaptured += new ESBasic.CbGeneric <byte[]>( delegate(byte[] audioData) { //收集数据 videoFileMaker.AddAudioFrame(audioData); } ); // audioPlayer = PlayerFactory.CreateAudioPlayer(0, 16000, 1, 16, 2); if (videoFileMaker == null) { videoFileMaker = new AudioFileMaker(); Console.WriteLine(outFileName); videoFileMaker.Initialize(outFileName, 16000, 1);//初始化 } }
//Part1 语音通信 private void button1_Click_1(object sender, EventArgs e) { if (button1.Text == "语音通话") { //远端socket配置 ipeRemote1 = new IPEndPoint(IPAddress.Parse(label1.Text.ToString()), 8500); audioPlayer = PlayerFactory.CreateAudioPlayer(0, 16000, 1, 16, 2); microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(0); microphoneCapturer.AudioCaptured += new ESBasic.CbGeneric <byte[]>(microphoneCapturer_AudioCaptured); Listen_sound(); microphoneCapturer.Start(); button1.Text = "停止语音通话"; } else { microphoneCapturer.Stop(); ListenThread_sound.Suspend(); button1.Text = "语音通话"; } }
//Part3 视频通信 private void button5_Click(object sender, EventArgs e) { if (button5.Text == "视频聊天") { ipeRemote2 = new IPEndPoint(IPAddress.Parse(label1.Text.ToString()), 9000); cameracapturer = CapturerFactory.CreateCameraCapturer(0, new Size(int.Parse("160"), int.Parse("120")), 10);//采集格式 cameracapturer.ImageCaptured += new ESBasic.CbGeneric <Bitmap>(ImageCaptured); Listen_video(); cameracapturer.Start(); button5.Text = "停止视频聊天"; } else { cameracapturer.Stop(); ListenThread_video.Suspend(); pictureBox1.Image = null; pictureBox2.Image = null; button5.Text = "视频聊天"; } }
private void 录制视频ToolStripMenuItem_Click(object sender, EventArgs e) { try { int audioSampleRate = 16000; int channelCount = 1; System.Drawing.Size videoSize = Screen.PrimaryScreen.Bounds.Size; { videoSize = new System.Drawing.Size(640, 480); this.cameraCapturer = CapturerFactory.CreateCameraCapturer(0, videoSize, frameRate); this.cameraCapturer.ImageCaptured += new CbGeneric <Bitmap>(this.Form1_ImageCaptured); } { this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(0); this.microphoneCapturer.CaptureError += new CbGeneric <Exception>(this.CaptureError); } this.microphoneCapturer.AudioCaptured += audioMixter_AudioMixed; this.microphoneCapturer.Start(); this.cameraCapturer.Start(); 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); } this.videoFileMaker = new VideoFileMaker(); this.videoFileMaker.Initialize(video_save_path, VideoCodecType.H264, videoSize.Width, videoSize.Height, frameRate, VideoQuality.High, AudioCodecType.AAC, audioSampleRate, channelCount, true); } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void button1_Click(object sender, EventArgs e) { try { //根据选择创建对应的采集器 if (this.comboBox1.SelectedIndex == 0) { this.capturer = CapturerFactory.CreateCameraCapturer(0, new Size(int.Parse(this.textBox_width.Text), int.Parse(this.textBox_height.Text)), 20); ((ICameraCapturer)this.capturer).ImageCaptured += new ESBasic.CbGeneric <Bitmap>(Form1_ImageCaptured); } else if (this.comboBox1.SelectedIndex == 1) { this.capturer = CapturerFactory.CreateDesktopCapturer(60, false); ((IDesktopCapturer)this.capturer).ImageCaptured += new ESBasic.CbGeneric <Bitmap>(Form1_ImageCaptured); } else if (this.comboBox1.SelectedIndex == 2) { this.capturer = CapturerFactory.CreateMicrophoneCapturer(0); ((IMicrophoneCapturer)this.capturer).AudioCaptured += new ESBasic.CbGeneric <byte[]>(Form1_AudioCaptured); } else { this.capturer = CapturerFactory.CreateSoundcardCapturer(); ((ISoundcardCapturer)this.capturer).AudioCaptured += new ESBasic.CbGeneric <byte[]>(Form1_AudioCaptured); } this.button1.Enabled = false; this.button2.Enabled = true; this.comboBox1.Enabled = false; this.autioDataTotalLen = 0; this.label_audioDataTotal.Text = "0"; //开始采集 this.capturer.Start(); } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void button3_Click(object sender, EventArgs e) { if (audiolabel.Text == "AudioOff") { try { this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(0); int sm = this.microphoneCapturer.SampleRate; this.microphoneCapturer.AudioCaptured += new ESBasic.CbGeneric <byte[]>(microphoneCapturer_AudioCaptured); this.audioPlayer = PlayerFactory.CreateAudioPlayer(0, 16000, 1, 16, 2); this.microphoneCapturer.Start(); audiolabel.Text = "AudioOn"; audioButton.Text = "Stop"; //this.label_msg.Text = "正在采集麦克风,并播放 . . ."; //this.label_msg.Visible = true; //this.button_wav.Enabled = false; //this.button_mic.Enabled = false; //this.button_stop.Enabled = true; } catch (Exception ee) { MessageBox.Show(ee.Message); } plotmodelTemp = new PlotModel { Title = "声音" }; lineSeries = new LineSeries { Title = "Example 1", ItemsSource = datlist }; StemSeries s1 = new StemSeries { Title = "Example 1", ItemsSource = datlist }; plotmodelTemp.Series.Add(s1); audiowindow = new drawWindow(plotmodelTemp); audiowindow.Show(); } else { if (this.audioPlayer == null) { return; } if (this.microphoneCapturer != null) { this.microphoneCapturer.Stop(); this.microphoneCapturer.Dispose(); this.microphoneCapturer = null; } this.audioPlayer.Clear(); this.audioPlayer.Dispose(); this.audioPlayer = null; audiolabel.Text = "AudioOff"; audioButton.Text = "Audio"; //this.label_msg.Visible = false; //this.button_wav.Enabled = true; //this.button_mic.Enabled = true; //this.button_stop.Enabled = false; } }
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); } }