示例#1
0
 private void ShareButtonBt_Click(object sender, RoutedEventArgs e)
 {
     CaptureSource.Stop();
     CaptureSource.SignalToStop();
     ShareScreenBt.IsEnabled = true;
     ShareButtonBt.IsEnabled = false;
     LoadCam();
 }
示例#2
0
 public void Stop()
 {
     _ScreenSource.SignalToStop();
     _ScreenSource.Stop();
     _CameraSource.SignalToStop();
     _CameraSource.Stop();
     _Writer.Close();
     _Writer.Dispose();
 }
        /// <summary>
        /// 停止
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void stopButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.isRecording = false;
                stopWatch.Reset();
                videoStreamer.Stop();
                videoWriter.Close();
                recordSound.EndRecordSound(WavFileUrl);

                try
                {
                    //停摄像头
                    Camera.Stop();

                    //关闭录像文件,如果忘了不关闭,将会得到一个损坏的文件,无法播放
                    VideoOutPut.Close();
                }
                catch { }

                //获取和保存音频流到文件(桌面)

                /*  AviManager aviManager = new AviManager(AviFileUrl, true);
                 * aviManager.AddAudioStream(WavFileUrl, 0);
                 * aviManager.Close();
                 * //获取和保存音频到摄像头视频文件
                 * AviManager avim = new AviManager(AppDomain.CurrentDomain.BaseDirectory + "\\MV\\vedios.avi", true);
                 * avim.AddAudioStream(WavFileUrl, 0);
                 * avim.Close();
                 *
                 */
            }
            catch (Exception ex)
            {
            }
            finally
            {
                Application.Exit();
            }
        }
        public void StopRecord()
        {
            if (isRecording)
            {
                isRecording = false;
                captureStream.Stop();
                audio.Stop();
                System.Threading.Thread.Sleep(100);
                video.Close();

                mergeAudioAndVideo();
            }
        }
示例#5
0
 /// <summary>
 /// 结束
 /// </summary>
 public virtual void End()
 {
     VideoStreamer.Stop();
     VideoWriter.Close();
     //是否需要录制声音
     if (wavRecorder != null)
     {
         wavRecorder.End();
         //获取和保存音频流到文件(桌面录制)
         AviManager aviManager = new AviManager(AviFilePath, true);
         aviManager.AddAudioStream(wavRecorder.WavFilePath, 0);
         aviManager.Close();
         //删除临时音频文件
         try { File.Delete(wavRecorder.WavFilePath); } catch { }
     }
 }
示例#6
0
 /// <summary>
 /// 停止录制
 /// </summary>
 /// <param name="ShowErr">当发生异常时是否显示错误提示</param>
 /// <param name="CloseCamera">是否关闭摄像头窗口</param>
 /// <param name="SaveFile">是否保留输出文件:可以放弃录制</param>
 internal void StopRecord(bool ShowErr = true, bool CloseCamera = true, bool SaveFile = true)
 {
     try
     {
         IsRecording = false;
         if (CloseCamera && SettingHelp.Settings.摄像头) //摄像头关闭时调用该方法不需要再去关闭摄像头
         {
             CarmeraShowWin?.Close();                 //如果摄像头窗口不为空则调用关闭方法关闭窗口
         }
         if (SettingHelp.Settings.桌面)
         {
             try
             {
                 VideoStreamer.Stop();//.Net Core时该方法异常,统一都加一个异常捕获
             }
             catch { }
             VideoWriter.Close();
         }
         if (SettingHelp.Settings.声音)
         {
             AudioStreamer.StopRecording();
             AudioStreamer.Dispose();
             AudioWriter.Close();
         }
         HiddenTools(SettingHelp.Settings.自动隐藏);
         btParse.Visibility = Visibility.Collapsed; //暂停按钮隐藏
         btStop.Visibility  = Visibility.Collapsed; //停止按钮隐藏
         btSet.Visibility   = Visibility.Visible;   //恢复设置按钮显示
         lbTime.Visibility  = Visibility.Collapsed; //视频时长隐藏
         btClose.Visibility = Visibility.Collapsed; //关闭按钮隐藏
         btBegin.Visibility = Visibility.Visible;   //录制按钮显示
         if (SaveFile)                              //保留输出文件
         {
             waitBar.Value      = 0;
             barGrid.Visibility = Visibility.Visible;
             //有视频有声音的时候再进行ffmpeg合成
             if ((SettingHelp.Settings.桌面 || SettingHelp.Settings.摄像头) && SettingHelp.Settings.声音)
             {
                 System.Threading.Tasks.Task.Factory.StartNew(() =>
                 {
                     for (int i = 0; i < 10; i++)
                     {
                         try
                         {
                             Dispatcher.Invoke(() => { waitBar.Value = i; });
                         }
                         catch
                         {
                             break;
                         }
                         Thread.Sleep(1000);
                     }
                 });//起一个线程让进度条动起来
                 System.Threading.Tasks.Task.Factory.StartNew(() =>
                 {
                     //CurrentVideoPath为全局的,防止在转码的过程中又开始了新的录制使CurrentVideoPath导致转码完删错文件
                     string tempVideo = CurrentVideoPath;
                     string tempAudio = SettingHelp.Settings.声音 ? $"-i \"{CurrentAudioPath}\"" : "";
                     string outfile   = MakeFilePath(SettingHelp.Settings.编码类型);
                     Functions.CMD($"ffmpeg -i {tempVideo} {tempAudio} -acodec copy {outfile} -crf 12");
                     DeleteFile(tempVideo, tempAudio, !SettingHelp.Settings.保留视频, !SettingHelp.Settings.保留音频);
                     Dispatcher.Invoke(() =>
                     {
                         btClose.Visibility = Visibility.Visible;   //转码完恢复关闭按钮显示
                         barGrid.Visibility = Visibility.Collapsed; //隐藏转码进度条
                     });
                 });
             }
             else
             {
                 btClose.Visibility = Visibility.Visible;   //转码完恢复关闭按钮显示
                 barGrid.Visibility = Visibility.Collapsed; //隐藏转码进度条
             }
         }
         else//不保留输出则简单的将录制的原始音视频文件删除即算完成
         {
             DeleteFile(CurrentVideoPath, CurrentAudioPath, !SettingHelp.Settings.保留视频, !SettingHelp.Settings.保留音频);
         }
     }
     catch (Exception ex)
     {
         if (ShowErr)
         {
             Functions.Message(ex.Message);
         }
     }
 }
示例#7
0
 internal void StopRecord(bool ShowErr = true, bool CloseCamera = true)
 {
     try
     {
         if (CloseCamera && SettingHelp.Settings.摄像头)//摄像头关闭时调用该方法不需要再去关闭摄像头
         {
             foreach (Window shower in Application.Current.Windows)
             {
                 if (shower is CameraShow)
                 {
                     shower.Close();
                     break;
                 }
             }
         }
         if (SettingHelp.Settings.桌面)
         {
             videoStreamer.Stop();
             videoWriter.Close();
         }
         if (SettingHelp.Settings.声音)
         {
             audioStreamer.StopRecording();
             audioStreamer.Dispose();
         }
         isRecording = false;
         HiddenTools(SettingHelp.Settings.自动隐藏);
         btParse.Visibility = Visibility.Collapsed;
         btStop.Visibility  = Visibility.Collapsed;
         btSet.Visibility   = Visibility.Visible;
         lbTime.Visibility  = Visibility.Collapsed;
         btClose.Visibility = Visibility.Visible;
         btBegin.Visibility = Visibility.Visible;
         waitBar.Value      = 0;
         barGrid.Visibility = Visibility.Visible;
         //Convert后的MP4体积更小但清晰度没什么影响,所以无论有无声音都进行一次转换处理
         if (SettingHelp.Settings.桌面 || SettingHelp.Settings.摄像头)//没有视频则不转换
         {
             System.Threading.Tasks.Task.Factory.StartNew(() =>
             {
                 string tempVideo        = curVideoName, tempAudio = curAudioName;//运行未完成转换再次开始录制,所以这里需要把当前转换中的文件名记录下来
                 var ffMpeg              = new FFMpegConverter();
                 ffMpeg.ConvertProgress += FfMpeg_ConvertProgress;
                 FFMpegInput[] input     = SettingHelp.Settings.声音 ? new FFMpegInput[] { new FFMpegInput(tempVideo), new FFMpegInput(tempAudio) } : new FFMpegInput[] { new FFMpegInput(tempVideo) };
                 ffMpeg.ConvertMedia(input, MakeFilePath(SettingHelp.Settings.编码类型), SettingHelp.Settings.编码类型, new OutputSettings());
                 try
                 {
                     if (File.Exists(tempVideo) && !SettingHelp.Settings.保留视频)
                     {
                         File.Delete(tempVideo);
                     }
                     if (File.Exists(tempAudio) && !SettingHelp.Settings.保留音频)
                     {
                         File.Delete(tempAudio);                                                      //合成后移除音频文件
                     }
                 }
                 catch { }//防止文件被占用删除失败
                 Dispatcher.Invoke(() =>
                 {
                     barGrid.Visibility = Visibility.Collapsed;
                 });
             });
         }
     }
     catch (Exception ex)
     {
         if (ShowErr)
         {
             Message(ex.Message);
         }
     }
 }