Browse Source

zhao:1优化录制录屏2完善日志,增加杀毒软件拦截报告

tags/录制修改前
耀 4 years ago
parent
commit
4d1ad3e54c

+ 72
- 11
Common/system/FFMpeg.cs View File

6
 using System.Linq;
6
 using System.Linq;
7
 using System.Text;
7
 using System.Text;
8
 using System.Threading;
8
 using System.Threading;
9
+using System.Windows.Forms;
9
 
10
 
10
 using VisioForge.Shared.NAudio.CoreAudioApi;
11
 using VisioForge.Shared.NAudio.CoreAudioApi;
11
 using VisioForge.Shared.NAudio.Wave;
12
 using VisioForge.Shared.NAudio.Wave;
45
         /// 录制屏幕
46
         /// 录制屏幕
46
         /// </summary>
47
         /// </summary>
47
         /// <param name="FilePath">文件存储路径</param>
48
         /// <param name="FilePath">文件存储路径</param>
48
-        public void StartRecordingVideo(string FilePath)
49
+        public bool StartRecordingVideo(string FilePath,out string ErrMessage)
49
         {
50
         {
50
             while (myProcess != null)
51
             while (myProcess != null)
51
             {
52
             {
52
                 Thread.Sleep(100);
53
                 Thread.Sleep(100);
53
             }
54
             }
55
+            ErrMessage = null;
54
             //路径
56
             //路径
55
             string Path = FileToolsCommon.GetDirectoryName(FilePath);
57
             string Path = FileToolsCommon.GetDirectoryName(FilePath);
56
             string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
58
             string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
155
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
157
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
156
             myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
158
             myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
157
             myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
159
             myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
158
-            myProcess.Start();
159
-            myProcess.BeginErrorReadLine();
160
+            try
161
+            {
162
+                myProcess.Start();
163
+                myProcess.BeginErrorReadLine();
164
+            }
165
+            catch (Exception ex)
166
+            {
167
+                if (ex.Message.Contains("访问"))
168
+                {
169
+                    ErrMessage = "访问被拒绝,请关闭杀毒软件或新任此软件后重试!";
170
+                }
171
+                else
172
+                {
173
+                    ErrMessage = ex.Message + " 请关闭杀毒软件或信任此软件后重试!";
174
+                }
175
+                LogHelper.WriteErrLog("【录音】(StartRecordingAudio)" + ErrMessage, ex);
176
+                myProcess.Dispose();
177
+                myProcess = null;
178
+                return false;
179
+            }
180
+            return true;
160
         }
181
         }
161
 
182
 
162
         /// <summary>
183
         /// <summary>
163
         /// 录制音频
184
         /// 录制音频
164
         /// </summary>
185
         /// </summary>
165
         /// <param name="Mp3Path">MP3音频位置</param>
186
         /// <param name="Mp3Path">MP3音频位置</param>
166
-        public bool StartRecordingAudio(string Mp3Path)
187
+        public bool StartRecordingAudio(string Mp3Path,out string ErrMessage)
167
         {
188
         {
189
+            ErrMessage = null;
168
             while (myProcess != null)
190
             while (myProcess != null)
169
             {
191
             {
170
                 Thread.Sleep(100);
192
                 Thread.Sleep(100);
215
             StopRecordAudio(1);
237
             StopRecordAudio(1);
216
             if (!IsRecordSpeaker && !IsRecordMicrophone)
238
             if (!IsRecordSpeaker && !IsRecordMicrophone)
217
             {
239
             {
240
+                ErrMessage = "无法录制声音,请关闭杀毒软件,确保声卡和麦克风处于可用状态!";
218
                 return false;
241
                 return false;
219
             }
242
             }
220
             #endregion
243
             #endregion
248
             myProcess.StartInfo.RedirectStandardInput = true;    //用于模拟该进程控制台的输入
271
             myProcess.StartInfo.RedirectStandardInput = true;    //用于模拟该进程控制台的输入
249
             //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
272
             //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
250
             myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
273
             myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
251
-            myProcess.Start();                //启动线程
252
-            myProcess.BeginErrorReadLine();   //开始异步读取
274
+            try
275
+            {
276
+                myProcess.Start();                //启动线程
277
+                myProcess.BeginErrorReadLine();   //开始异步读取
278
+            }
279
+            catch (Exception ex)
280
+            {
281
+                if (ex.Message.Contains("访问"))
282
+                {
283
+                    ErrMessage = "无法录制声音,访问被拒绝,请关闭杀毒软件或信任此软件后重试!";
284
+                }
285
+                else
286
+                {
287
+                    ErrMessage = ex.Message+" 请关闭杀毒软件或信任此软件后重试!";
288
+                }
289
+                LogHelper.WriteErrLog("【录音】(StartRecordingAudio)"+ErrMessage,ex);
290
+                myProcess.Dispose();
291
+                myProcess = null;
292
+                return false;
293
+            }
253
             return true;
294
             return true;
254
         }
295
         }
255
 
296
 
324
         /// <param name="Frequency">每秒帧率</param>
365
         /// <param name="Frequency">每秒帧率</param>
325
         /// <param name="VideoWidth">视频宽度</param>
366
         /// <param name="VideoWidth">视频宽度</param>
326
         /// <param name="VideoHeight">视频高度</param>
367
         /// <param name="VideoHeight">视频高度</param>
327
-        public bool SynthesisVideo(string ImageListPath, string Mp3Path, string VideoSavePath, int Frequency, int VideoWidth, int VideoHeight)
368
+        public bool SynthesisVideo(string ImageListPath, string Mp3Path, string VideoSavePath, int Frequency, int VideoWidth, int VideoHeight,out string ErrMessage)
328
         {
369
         {
329
             //new Thread(new ThreadStart(new Action(() =>
370
             //new Thread(new ThreadStart(new Action(() =>
330
             //{
371
             //{
334
             {
375
             {
335
                 Thread.Sleep(100);
376
                 Thread.Sleep(100);
336
             }
377
             }
378
+            ErrMessage = null;
337
             string Extension = FileToolsCommon.GetIOExtension(VideoSavePath);//扩展名
379
             string Extension = FileToolsCommon.GetIOExtension(VideoSavePath);//扩展名
338
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
380
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
339
             //Debug.WriteLine(KillProcessArray.Length.ToString());
381
             //Debug.WriteLine(KillProcessArray.Length.ToString());
393
                 myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
435
                 myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
394
                                                                        //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
436
                                                                        //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
395
                 myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
437
                 myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
396
-                myProcess.Start();                 //启动线程
397
-                myProcess.BeginErrorReadLine();    //开始异步读取
398
-                myProcess.WaitForExit();           //阻塞等待进程结束
399
-                myProcess.Close();                 //关闭进程
438
+                try
439
+                {
440
+                    myProcess.Start();                 //启动线程
441
+                    myProcess.BeginErrorReadLine();    //开始异步读取
442
+                    myProcess.WaitForExit();           //阻塞等待进程结束
443
+                    myProcess.Close();                 //关闭进程
444
+                }
445
+                catch (Exception ex)
446
+                {
447
+                    if (ex.Message.Contains("访问"))
448
+                    {
449
+                        ErrMessage = "访问被拒绝,请关闭杀毒软件或新任此软件后重试!";
450
+                    }
451
+                    else
452
+                    {
453
+                        ErrMessage = ex.Message + " 请关闭杀毒软件或信任此软件后重试!";
454
+                    }
455
+                    LogHelper.WriteErrLog("【录音】(StartRecordingAudio)" + ErrMessage, ex);
456
+                    myProcess.Dispose();
457
+                    myProcess = null;
458
+                    return false;
459
+                }
400
                 myProcess.Dispose();               //释放资源
460
                 myProcess.Dispose();               //释放资源
401
                 #region 进程是否已经释放
461
                 #region 进程是否已经释放
402
                 bool IsRunning = true;
462
                 bool IsRunning = true;
423
             catch (Exception ex)
483
             catch (Exception ex)
424
             {
484
             {
425
                 LogHelper.WriteErrLog("【视频合成】(SynthesisVideo)视频生成失败," + ex.Message, ex);
485
                 LogHelper.WriteErrLog("【视频合成】(SynthesisVideo)视频生成失败," + ex.Message, ex);
486
+                ErrMessage = ex.Message;
426
                 return false;
487
                 return false;
427
             }
488
             }
428
             //Dispatcher.Invoke(() =>
489
             //Dispatcher.Invoke(() =>

+ 22
- 1
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs View File

424
                         {
424
                         {
425
                             Thread.Sleep(100);
425
                             Thread.Sleep(100);
426
                         }
426
                         }
427
-                        APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
427
+                        bool SynRes=APP.FFmpeg.StartRecordingVideo(VideoSavePathName,out string ErrMessage);
428
 
428
 
429
                         Thread.Sleep(1300);
429
                         Thread.Sleep(1300);
430
                         Dispatcher.Invoke(() =>
430
                         Dispatcher.Invoke(() =>
431
                         {
431
                         {
432
+                            if(!SynRes)
433
+                            {
434
+                                MessageWindow.Show(ErrMessage);
435
+                                //隐藏画笔工具栏
436
+                                //BtnToolbarDown_Click(null, null);
437
+                                gridToolbar.Visibility = Visibility.Hidden;
438
+                                gridColour.Visibility = Visibility.Hidden;
439
+                                gridThickness.Visibility = Visibility.Hidden;
440
+                                ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
441
+                                ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
442
+                                BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
443
+                                imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
444
+                                btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
445
+                                imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
446
+                                btnBlackPenTwo.IsEnabled = false;//红笔不可点击
447
+                                txbTime.Visibility = Visibility.Hidden;//时间不显示
448
+                                BtnRecordingScreen.ToolTip = "开始";
449
+                                IsSuspend = true;
450
+                                IsFirstRS = true;
451
+                                return;
452
+                            }
432
                             Stack();
453
                             Stack();
433
                         });
454
                         });
434
                     }))).Start();
455
                     }))).Start();

+ 8
- 3
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs View File

3092
                     new Thread(new ThreadStart(new Action(() =>
3092
                     new Thread(new ThreadStart(new Action(() =>
3093
                     {
3093
                     {
3094
                         Thread.Sleep(1000);
3094
                         Thread.Sleep(1000);
3095
-                        IsRecordAudio = APP.FFmpeg.StartRecordingAudio(AudioPathName);
3095
+                        IsRecordAudio = APP.FFmpeg.StartRecordingAudio(AudioPathName,out string ErrMessage);
3096
                         Thread.Sleep(1000);
3096
                         Thread.Sleep(1000);
3097
                         Dispatcher.Invoke(() =>
3097
                         Dispatcher.Invoke(() =>
3098
                         {
3098
                         {
3099
+                            if(!IsRecordAudio)
3100
+                            {
3101
+                                MessageWindow.Show(ErrMessage);
3102
+                            }
3099
                             Recorddt = DateTime.Now;
3103
                             Recorddt = DateTime.Now;
3100
                             IsStartCount = true;
3104
                             IsStartCount = true;
3101
                             //Stack();
3105
                             //Stack();
3361
                                 AudioPathName = null;
3365
                                 AudioPathName = null;
3362
                             }
3366
                             }
3363
                             //合成视频
3367
                             //合成视频
3364
-                            bool SynRes = APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSynthesisPathName, 5, gridActWidth, gridActHeight);
3368
+                            bool SynRes = APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSynthesisPathName, 5, gridActWidth, gridActHeight,out string ErrMessage);
3365
                             //}))).Start();
3369
                             //}))).Start();
3366
                             //new Thread(new ThreadStart(new Action(() =>
3370
                             //new Thread(new ThreadStart(new Action(() =>
3367
                             //{
3371
                             //{
3369
                             {
3373
                             {
3370
                                 Dispatcher.Invoke(() =>
3374
                                 Dispatcher.Invoke(() =>
3371
                                 {
3375
                                 {
3372
-                                    MessageWindow.Show("视频录制失败,无法保存此视频!");
3376
+                                    //MessageWindow.Show("视频录制失败,无法保存此视频!");
3377
+                                    MessageWindow.Show("录制失败,"+ErrMessage);
3373
                                     BtnRecord.IsEnabled = true;
3378
                                     BtnRecord.IsEnabled = true;
3374
                                     btnStop.IsEnabled = true;
3379
                                     btnStop.IsEnabled = true;
3375
                                     TxbRecordingWord.Text = "录制";
3380
                                     TxbRecordingWord.Text = "录制";

Loading…
Cancel
Save