Browse Source

zhao:1增加视频转码 2修改录屏倒计时 3修改缩略图名

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

+ 17
- 1
Common/system/BlackboardNew.cs View File

@@ -319,7 +319,23 @@ namespace Common.system
319 319
                 if (stroke != null && stroke.StylusPoints.Count > 1)
320 320
                 {
321 321
                     isFirst = true;
322
-                    strokes_page_all[i].lines.Last().lines_curr.Add(stroke);
322
+                    try
323
+                    {
324
+                        strokes_page_all[i].lines.Last().lines_curr.Add(stroke);
325
+                    }
326
+                    catch (Exception ex)
327
+                    {
328
+                        if (strokes_page_all != null)
329
+                        {
330
+                            if (strokes_page_all.Count == 0)
331
+                            {
332
+                                ZBBPage pagetemp = new ZBBPage();
333
+                                pagetemp.lines.Add(new ZBBPageStep());
334
+                                strokes_page_all.Add(pagetemp);
335
+                            }
336
+                        }
337
+                        LogHelper.WriteErrLog("【画板】(changepages)添加失败,strokes_page_all为0," + ex.Message, ex);
338
+                    }
323 339
                 }
324 340
                 stylusPoints = new StylusPointCollection();
325 341
                 stylusPoint = new StylusPoint();

+ 178
- 100
Common/system/FFMpeg.cs View File

@@ -65,7 +65,7 @@ namespace Common.system
65 65
             {
66 66
 
67 67
             }
68
-            if(StartRecordSpeakerAudio(audioSpeakerPath))
68
+            if (StartRecordSpeakerAudio(audioSpeakerPath))
69 69
             {
70 70
                 IsRecordSpeaker = true;
71 71
             }
@@ -94,7 +94,7 @@ namespace Common.system
94 94
             {
95 95
                 SpeakerStr = "-f dshow -i audio=\"virtual-audio-capturer\" ";
96 96
             }
97
-            if(IsRecordMicrophone)
97
+            if (IsRecordMicrophone)
98 98
             {
99 99
                 MicrophoneName = GetMicrophone();
100 100
                 if (!string.IsNullOrWhiteSpace(MicrophoneName))
@@ -118,7 +118,7 @@ namespace Common.system
118 118
                     break;
119 119
                 case ".AVI":
120 120
                 case ".FLV":
121
-                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac -f " + Extension.ToLower().Replace(".","") + " " + PathName;
121
+                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac -f " + Extension.ToLower().Replace(".", "") + " " + PathName;
122 122
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
123 123
                     //{
124 124
                     //    myProcess.StartInfo.Arguments = "-f dshow -i video=\"screen-capture-recorder\" -f dshow -i audio=\"virtual-audio-capturer\" -vcodec libx264 -acodec libmp3lame -r 15 -crf 22 -f " + Extension.ToLower() + " " + PathName;  //ffmpeg的参数
@@ -204,16 +204,16 @@ namespace Common.system
204 204
             myProcess = new Process();
205 205
             LogPath = CreateffmpegLog();
206 206
             this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
207
-            if(IsRecordSpeaker && IsRecordMicrophone)
207
+            if (IsRecordSpeaker && IsRecordMicrophone)
208 208
             {
209 209
                 myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\"  -f dshow -i audio=\"" +
210 210
                         MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 " + PathName;
211 211
             }
212
-            else if(IsRecordSpeaker)
212
+            else if (IsRecordSpeaker)
213 213
             {
214 214
                 myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" " + PathName;
215 215
             }
216
-            else if(IsRecordMicrophone)
216
+            else if (IsRecordMicrophone)
217 217
             {
218 218
                 //录制麦克风
219 219
                 if (!string.IsNullOrWhiteSpace(MicrophoneName))
@@ -304,7 +304,7 @@ namespace Common.system
304 304
         /// <param name="Frequency">每秒帧率</param>
305 305
         /// <param name="VideoWidth">视频宽度</param>
306 306
         /// <param name="VideoHeight">视频高度</param>
307
-        public void SynthesisVideo(string ImageListPath, string Mp3Path, string VideoSavePath, int Frequency, int VideoWidth, int VideoHeight)
307
+        public bool SynthesisVideo(string ImageListPath, string Mp3Path, string VideoSavePath, int Frequency, int VideoWidth, int VideoHeight)
308 308
         {
309 309
             //new Thread(new ThreadStart(new Action(() =>
310 310
             //{
@@ -322,77 +322,86 @@ namespace Common.system
322 322
                 KillProcess.Kill();
323 323
             }
324 324
             myProcess = new Process();
325
-            LogPath = CreateffmpegLog();
326
-            string mp3Str = "";
327
-            #region 判断音频是否存在
328
-            if (!string.IsNullOrWhiteSpace(Mp3Path))
325
+            try
329 326
             {
330
-                if (FileToolsCommon.IsExistFile(Mp3Path))
327
+
328
+                LogPath = CreateffmpegLog();
329
+                string mp3Str = "";
330
+                #region 判断音频是否存在
331
+                if (!string.IsNullOrWhiteSpace(Mp3Path))
331 332
                 {
332
-                    mp3Str = "-i " + Mp3Path;
333
+                    if (FileToolsCommon.IsExistFile(Mp3Path))
334
+                    {
335
+                        mp3Str = "-i " + Mp3Path;
336
+                    }
333 337
                 }
334
-            }
335
-            #endregion
336
-            this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
337
-            switch (Extension.ToUpper())
338
-            {
339
-                case ".MP4":
340
-                    myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
341
-                        ImageListPath + @"%d.png " +
342
-                        mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
343
-                        VideoSavePath;
344
-                    break;
345
-                case ".AVI":
346
-                    myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
347
-                        ImageListPath + @"%d.png " +
348
-                        mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -f AVI " +
349
-                        VideoSavePath;
350
-                    break;
351
-                case ".FLV":
352
-                    myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
353
-                        ImageListPath + @"%d.png " +
354
-                        mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -f FLV " +
355
-                        VideoSavePath;
356
-                    break;
357
-                default:
358
-                    myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
359
-                        ImageListPath + @"%d.png " +
360
-                        mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
361
-                        VideoSavePath;
362
-                    break;
363
-            }
364
-            myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
365
-            myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
366
-            myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
367
-            myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
368
-                                                                   //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
369
-            myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
370
-            myProcess.Start();                 //启动线程
371
-            myProcess.BeginErrorReadLine();    //开始异步读取
372
-            myProcess.WaitForExit();           //阻塞等待进程结束
373
-            myProcess.Close();                 //关闭进程
374
-            myProcess.Dispose();               //释放资源
375
-            #region 进程是否已经释放
376
-            bool IsRunning = true;
377
-            while (IsRunning)
378
-            {
379
-                IsRunning = false;
380
-                Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
381
-                foreach (var KillProcess in ProcessArray)
338
+                #endregion
339
+                this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
340
+                switch (Extension.ToUpper())
382 341
                 {
383
-                    IsRunning = true;
384
-                    Thread.Sleep(100);
342
+                    case ".MP4":
343
+                        myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
344
+                            ImageListPath + @"%d.png " +
345
+                            mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
346
+                            VideoSavePath;
347
+                        break;
348
+                    case ".AVI":
349
+                        myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
350
+                            ImageListPath + @"%d.png " +
351
+                            mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -f AVI " +
352
+                            VideoSavePath;
353
+                        break;
354
+                    case ".FLV":
355
+                        myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
356
+                            ImageListPath + @"%d.png " +
357
+                            mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -f FLV " +
358
+                            VideoSavePath;
359
+                        break;
360
+                    default:
361
+                        myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
362
+                            ImageListPath + @"%d.png " +
363
+                            mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
364
+                            VideoSavePath;
365
+                        break;
385 366
                 }
386
-            }
387
-            #endregion
388
-            myProcess = null;
389
-            //生成视频后删除图片和音频保存列表
390
-            //FileToolsCommon.DeleteDirectory(ImageListPath);
391
-            //FileToolsCommon.DeleteDirectory(FileToolsCommon.GetDirectoryName(Mp3Path));
392
-
393
-            Thread.Sleep(100);
394
-            FileToolsCommon.DeleteDirectory(FileToolsCommon.GetDirectoryName(VideoSavePath) + "temp");
367
+                myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
368
+                myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
369
+                myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
370
+                myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
371
+                                                                       //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
372
+                myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
373
+                myProcess.Start();                 //启动线程
374
+                myProcess.BeginErrorReadLine();    //开始异步读取
375
+                myProcess.WaitForExit();           //阻塞等待进程结束
376
+                myProcess.Close();                 //关闭进程
377
+                myProcess.Dispose();               //释放资源
378
+                #region 进程是否已经释放
379
+                bool IsRunning = true;
380
+                while (IsRunning)
381
+                {
382
+                    IsRunning = false;
383
+                    Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
384
+                    foreach (var KillProcess in ProcessArray)
385
+                    {
386
+                        IsRunning = true;
387
+                        Thread.Sleep(100);
388
+                    }
389
+                }
390
+                #endregion
391
+                myProcess = null;
392
+                //生成视频后删除图片和音频保存列表
393
+                //FileToolsCommon.DeleteDirectory(ImageListPath);
394
+                //FileToolsCommon.DeleteDirectory(FileToolsCommon.GetDirectoryName(Mp3Path));
395 395
 
396
+                Thread.Sleep(100);
397
+                FileToolsCommon.DeleteDirectory(FileToolsCommon.GetDirectoryName(VideoSavePath) + "temp");
398
+                return true;
399
+            }
400
+            catch (Exception ex)
401
+            {
402
+                LogHelper.WriteErrLog("【视频合成】(SynthesisVideo)视频生成失败," + ex.Message, ex);
403
+                return false;
404
+            }
396 405
             //Dispatcher.Invoke(() =>
397 406
             //{
398 407
             //});
@@ -552,7 +561,7 @@ namespace Common.system
552 561
         /// </summary>
553 562
         /// <param name="VideoPath">视频地址</param>
554 563
         /// <param name="ImagePath">图片地址</param>
555
-        public void GenerateThumbnails(string VideoPath, string ImagePath)
564
+        public bool GenerateThumbnails(string VideoPath, string ImagePath)
556 565
         {
557 566
             while (myProcess != null)
558 567
             {
@@ -563,36 +572,105 @@ namespace Common.system
563 572
             {
564 573
                 KillProcess.Kill();
565 574
             }
566
-            myProcess = new Process();
567
-            LogPath = CreateffmpegLog();
568
-            this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
569
-                                                                                                                  //myProcess.StartInfo.Arguments = "-i \"" + VideoPath + "\" -ss 1 -vframes 1 -r 1 -ac 1 -ab 2 -s " + thubWidth + "*" + thubHeight + " -f image2 \"" + ImagePath + "\"";
570
-            myProcess.StartInfo.Arguments = "-i \"" + VideoPath + "\" -ss 1 -vframes 1 -r 1 -ac 1 -ab 2 -f image2 \"" + ImagePath + "\"";
571
-            myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
572
-            myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
573
-            myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
574
-            myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
575
-                                                                   //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
576
-            myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
577
-            myProcess.Start();                 //启动线程
578
-            myProcess.BeginErrorReadLine();    //开始异步读取
579
-            myProcess.WaitForExit();           //阻塞等待进程结束
580
-            myProcess.Close();                 //关闭进程
581
-            myProcess.Dispose();               //释放资源
582
-            #region 进程是否已经释放
583
-            bool IsRunning = true;
584
-            while (IsRunning)
575
+            try
585 576
             {
586
-                IsRunning = false;
587
-                Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
588
-                foreach (var KillProcess in ProcessArray)
577
+                myProcess = new Process();
578
+                LogPath = CreateffmpegLog();
579
+                this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
580
+                                                                                                                      //myProcess.StartInfo.Arguments = "-i \"" + VideoPath + "\" -ss 1 -vframes 1 -r 1 -ac 1 -ab 2 -s " + thubWidth + "*" + thubHeight + " -f image2 \"" + ImagePath + "\"";
581
+                myProcess.StartInfo.Arguments = "-i \"" + VideoPath + "\" -ss 1 -vframes 1 -r 1 -ac 1 -ab 2 -f image2 \"" + ImagePath + "\"";
582
+                myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
583
+                myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
584
+                myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
585
+                myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
586
+                                                                       //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
587
+                myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
588
+                myProcess.Start();                 //启动线程
589
+                myProcess.BeginErrorReadLine();    //开始异步读取
590
+                myProcess.WaitForExit();           //阻塞等待进程结束
591
+                myProcess.Close();                 //关闭进程
592
+                myProcess.Dispose();               //释放资源
593
+                #region 进程是否已经释放
594
+                bool IsRunning = true;
595
+                while (IsRunning)
589 596
                 {
590
-                    IsRunning = true;
591
-                    Thread.Sleep(100);
597
+                    IsRunning = false;
598
+                    Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
599
+                    foreach (var KillProcess in ProcessArray)
600
+                    {
601
+                        IsRunning = true;
602
+                        Thread.Sleep(100);
603
+                    }
592 604
                 }
605
+                #endregion
606
+                myProcess = null;
607
+                return true;
608
+            }
609
+            catch (Exception ex)
610
+            {
611
+                LogHelper.WriteErrLog("【生成缩略图】(GenerateThumbnails)缩略图生成失败," + ex.Message, ex);
612
+                return false;
613
+            }
614
+        }
615
+        /// <summary>
616
+        /// 视频转码
617
+        /// </summary>
618
+        /// <param name="VideoPathName">源视频</param>
619
+        /// <param name="VideoSavePathName">目标视频存储路径</param>
620
+        /// <param name="Width">宽</param>
621
+        /// <param name="Height">高</param>
622
+        /// <returns></returns>
623
+        public bool VideoTranscode(string VideoPathName,string VideoSavePathName,int Width,int Height)
624
+        {
625
+            while (myProcess != null)
626
+            {
627
+                Thread.Sleep(100);
628
+            }
629
+            Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
630
+            foreach (var KillProcess in KillProcessArray)
631
+            {
632
+                KillProcess.Kill();
633
+            }
634
+            try
635
+            {
636
+                myProcess = new Process();
637
+                LogPath = CreateffmpegLog();
638
+                this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
639
+                myProcess.StartInfo.Arguments = "-i "+ VideoPathName + " -acodec copy -vcodec libx264 -s "+ Width + "*"+ Height + " "+ VideoSavePathName;
640
+                myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
641
+                myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
642
+                myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
643
+                myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
644
+                                                                       //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
645
+                myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
646
+                myProcess.Start();                 //启动线程
647
+                myProcess.BeginErrorReadLine();    //开始异步读取
648
+                myProcess.WaitForExit();           //阻塞等待进程结束
649
+                myProcess.Close();                 //关闭进程
650
+                myProcess.Dispose();               //释放资源
651
+                #region 进程是否已经释放
652
+                bool IsRunning = true;
653
+                while (IsRunning)
654
+                {
655
+                    IsRunning = false;
656
+                    Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
657
+                    foreach (var KillProcess in ProcessArray)
658
+                    {
659
+                        IsRunning = true;
660
+                        Thread.Sleep(100);
661
+                    }
662
+                }
663
+                #endregion
664
+                myProcess = null;
665
+                Thread.Sleep(200);
666
+                FileToolsCommon.DeleteFile(VideoPathName);
667
+                return true;
668
+            }
669
+            catch (Exception ex)
670
+            {
671
+                LogHelper.WriteErrLog("【视频转码】(VideoTranscode)视频转码失败," + ex.Message, ex);
672
+                return false;
593 673
             }
594
-            #endregion
595
-            myProcess = null;
596 674
         }
597 675
 
598 676
         /// <summary>
@@ -781,7 +859,7 @@ namespace Common.system
781 859
             {
782 860
                 if (waveIn != null)
783 861
                 {
784
-                    waveIn.StopRecording(); 
862
+                    waveIn.StopRecording();
785 863
                 }
786 864
                 if (capture != null)
787 865
                 {

+ 10
- 0
XHWK.WKTool/FileDirectoryWindow.xaml.cs View File

@@ -455,6 +455,11 @@ namespace XHWK.WKTool
455 455
             string filePathName = model_Video.VideoPath;
456 456
             string filePath = FileToolsCommon.GetDirectoryName(filePathName);
457 457
             string newFilePathName = filePath + NewName;
458
+            //缩略图
459
+            string ThumbnailPath = filePath + "ThumbnailPath/";
460
+            FileToolsCommon.CreateDirectory(ThumbnailPath);
461
+            //缩略图存储位置
462
+            string ThumbnailPathName = ThumbnailPath + NewName.Replace(".", "") + ".JPG";
458 463
             if (FileToolsCommon.IsExistFile(newFilePathName))
459 464
             {
460 465
                 Errmessage = "文件已存在,请重新修改文件名!";
@@ -462,8 +467,13 @@ namespace XHWK.WKTool
462 467
             }
463 468
             else
464 469
             {
470
+                //修改文件名
465 471
                 FileToolsCommon.Copy(filePathName, newFilePathName);
466 472
                 model_Video.VideoPath = newFilePathName;
473
+                //修改缩略图名
474
+                FileToolsCommon.DeleteFile(ThumbnailPathName);
475
+                FileToolsCommon.Copy(model_Video.ThumbnailPath, ThumbnailPathName);
476
+                model_Video.ThumbnailPath = ThumbnailPathName;
467 477
                 APP.SaveWkData();
468 478
                 return true;
469 479
             }

+ 19
- 15
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs View File

@@ -299,6 +299,19 @@ namespace XHWK.WKTool
299 299
                     SetUpVideoPathName();
300 300
                     IsFirstRS = false;
301 301
                     k_hook.Start();//安装键盘钩子
302
+
303
+                    if (APP.W_CountdownWindow == null)
304
+                    {
305
+                        APP.W_CountdownWindow = new CountdownWindow();
306
+                        APP.W_CountdownWindow.Initialize(true, 1800);
307
+                        //APP.W_CountdownWindow.Topmost = true;
308
+                    }
309
+                    else
310
+                    {
311
+                        APP.W_CountdownWindow.Initialize(true, 1800);
312
+                        //APP.W_CountdownWindow.Topmost = true;
313
+                    }
314
+                    APP.W_CountdownWindow.Show();
302 315
                 }
303 316
                 IsSuspend = false;
304 317
 
@@ -329,24 +342,15 @@ namespace XHWK.WKTool
329 342
                 txbTime.Visibility = Visibility.Visible;//时间显示
330 343
                 try
331 344
                 {
332
-                    if (APP.W_CountdownWindow == null)
333
-                    {
334
-                        APP.W_CountdownWindow = new CountdownWindow();
335
-                        APP.W_CountdownWindow.Initialize(true, 1800);
336
-                        //APP.W_CountdownWindow.Topmost = true;
337
-                    }
338
-                    else
339
-                    {
340
-                        APP.W_CountdownWindow.Initialize(true, 1800);
341
-                        //APP.W_CountdownWindow.Topmost = true;
342
-                    }
343
-                    APP.W_CountdownWindow.Show();
344 345
                     new Thread(new ThreadStart(new Action(() =>
345 346
                     {
346
-                        Thread.Sleep(1000);
347
+                        if (IsFirstRS)
348
+                        {
349
+                            Thread.Sleep(1500);
350
+                        }
347 351
                         APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
348 352
 
349
-                        Thread.Sleep(1800);
353
+                        Thread.Sleep(1000);
350 354
                         Dispatcher.Invoke(() =>
351 355
                         {
352 356
                             Stack();
@@ -438,7 +442,7 @@ namespace XHWK.WKTool
438 442
                     string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
439 443
                     FileToolsCommon.CreateDirectory(ThumbnailPath);
440 444
                     //缩略图存储位置
441
-                    string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
445
+                    string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".","") + ".JPG";
442 446
                     new Thread(new ThreadStart(new Action(() =>
443 447
                     {
444 448
                         while (!FileToolsCommon.IsExistFile(VideoSavePathName))

+ 93
- 17
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs View File

@@ -1613,6 +1613,45 @@ namespace XHWK.WKTool
1613 1613
                 APP.myloading.Hide();
1614 1614
             }
1615 1615
         }
1616
+
1617
+        /// <summary>
1618
+        /// 修改文件名
1619
+        /// </summary>
1620
+        /// <param name="Guid">唯一编号</param>
1621
+        /// <param name="NewName">新文件名带后缀 不带路径</param>
1622
+        /// <param name="Errmessage">错误信息</param>
1623
+        /// <returns></returns>
1624
+        bool ModifyPathName(string FileGuid, string NewName, out string Errmessage)
1625
+        {
1626
+            Errmessage = "";
1627
+            Model_Video model_Video = APP.VideoList.Find(x => x.FileGuid == FileGuid);
1628
+            string filePathName = model_Video.VideoPath;
1629
+            string filePath = FileToolsCommon.GetDirectoryName(filePathName);
1630
+            string newFilePathName = filePath + NewName;
1631
+            //缩略图
1632
+            string ThumbnailPath = filePath + "ThumbnailPath/";
1633
+            FileToolsCommon.CreateDirectory(ThumbnailPath);
1634
+            //缩略图存储位置
1635
+            string ThumbnailPathName = ThumbnailPath + NewName.Replace(".", "") + ".JPG";
1636
+            if (FileToolsCommon.IsExistFile(newFilePathName))
1637
+            {
1638
+                Errmessage = "文件已存在,请重新修改文件名!";
1639
+                return false;
1640
+            }
1641
+            else
1642
+            {
1643
+                //修改文件名
1644
+                FileToolsCommon.Copy(filePathName, newFilePathName);
1645
+                model_Video.VideoPath = newFilePathName;
1646
+                //修改缩略图名
1647
+                FileToolsCommon.DeleteFile(ThumbnailPathName);
1648
+                FileToolsCommon.Copy(model_Video.ThumbnailPath, ThumbnailPathName);
1649
+                model_Video.ThumbnailPath = ThumbnailPathName;
1650
+                APP.SaveWkData();
1651
+                return true;
1652
+            }
1653
+        }
1654
+
1616 1655
         #endregion
1617 1656
 
1618 1657
         #region 录制窗口
@@ -1634,6 +1673,10 @@ namespace XHWK.WKTool
1634 1673
         /// </summary>
1635 1674
         string VideoSavePathName;
1636 1675
         /// <summary>
1676
+        /// 视频合成路径名
1677
+        /// </summary>
1678
+        string VideoSynthesisPathName;
1679
+        /// <summary>
1637 1680
         /// 暂停录制
1638 1681
         /// </summary>
1639 1682
         bool IsSuspendR = true;
@@ -1723,7 +1766,8 @@ namespace XHWK.WKTool
1723 1766
         /// </summary>
1724 1767
         private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
1725 1768
         {
1726
-            TxbRecordScreenWord.Text = "保存中";//
1769
+            txbType.Visibility = Visibility.Visible;
1770
+            txbType.Text = "保存中";
1727 1771
             btnScreenRecording.IsEnabled = false;
1728 1772
 
1729 1773
             new Thread(new ThreadStart(new Action(() =>
@@ -1735,7 +1779,8 @@ namespace XHWK.WKTool
1735 1779
                 Dispatcher.Invoke(() =>
1736 1780
                 {
1737 1781
                     btnScreenRecording.IsEnabled = true;
1738
-                    TxbRecordScreenWord.Text = "录屏";
1782
+                    txbType.Visibility = Visibility.Hidden;
1783
+                    //TxbRecordScreenWord.Text = "录屏";
1739 1784
                 });
1740 1785
             }))).Start();
1741 1786
 
@@ -1867,10 +1912,12 @@ namespace XHWK.WKTool
1867 1912
                     FileToolsCommon.CreateDirectory(AudioPathName);
1868 1913
                     AudioPathName += APP.WKData.WkName + ".MP3";
1869 1914
                     VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
1915
+                    VideoSynthesisPathName = APP.WKData.WkPath  + APP.WKData.WkName + "_录制Syn." + VideoInfo.VideoType.ToString();
1870 1916
                     int num = 1;
1871 1917
                     while (FileToolsCommon.IsExistFile(VideoSavePathName))
1872 1918
                     {
1873 1919
                         VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
1920
+                        VideoSynthesisPathName = APP.WKData.WkPath  + APP.WKData.WkName + "_录制Syn_" + num + "." + VideoInfo.VideoType.ToString();
1874 1921
                         num++;
1875 1922
                     }
1876 1923
 
@@ -2159,7 +2206,7 @@ namespace XHWK.WKTool
2159 2206
                     string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
2160 2207
                     FileToolsCommon.CreateDirectory(ThumbnailPath);
2161 2208
                     //缩略图存储位置
2162
-                    string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
2209
+                    string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
2163 2210
                     int gridActWidth = (int)GridMain.ActualWidth;
2164 2211
                     int gridActHeight = (int)GridMain.ActualHeight;
2165 2212
                     APP.FFmpeg.StopFFmpeg(AudioPathName);
@@ -2174,6 +2221,9 @@ namespace XHWK.WKTool
2174 2221
                         {
2175 2222
                             IsStartCount = false;
2176 2223
                             timer.Stop();
2224
+                            End();
2225
+                            txbTime.Text = "";
2226
+                            txbTime.Visibility = Visibility.Hidden;
2177 2227
                         });
2178 2228
                         //}))).Start();
2179 2229
                         //new Thread(new ThreadStart(new Action(() =>
@@ -2195,35 +2245,54 @@ namespace XHWK.WKTool
2195 2245
                             //没有录制音频
2196 2246
                             AudioPathName = null;
2197 2247
                         }
2198
-                        APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, gridActWidth, gridActHeight);
2248
+                        //合成视频
2249
+                        bool SynRes= APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSynthesisPathName, 5, gridActWidth, gridActHeight);
2199 2250
                         //}))).Start();
2200 2251
                         //new Thread(new ThreadStart(new Action(() =>
2201 2252
                         //{
2202
-                        while (!FileToolsCommon.IsExistFile(VideoSavePathName))
2253
+                        if(!SynRes)
2203 2254
                         {
2204
-                            Thread.Sleep(100);
2255
+                            Dispatcher.Invoke(() =>
2256
+                            {
2257
+                                MessageWindow.Show("视频录制失败,无法保存此视频!");
2258
+                                BtnRecord.IsEnabled = true;
2259
+                                btnStop.IsEnabled = true;
2260
+                                TxbRecordingWord.Text = "录制";
2261
+                                txbType.Text = "";
2262
+                            });
2263
+                            return;
2205 2264
                         }
2206
-                        while (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(VideoSavePathName) + "temp/"))
2265
+                        Dispatcher.Invoke(() =>
2266
+                        {
2267
+                            txbType.Text = "转码中";
2268
+                        });
2269
+                        while (!FileToolsCommon.IsExistFile(VideoSynthesisPathName))
2207 2270
                         {
2208 2271
                             Thread.Sleep(100);
2209 2272
                         }
2210
-                        Dispatcher.Invoke(() =>
2273
+                        while (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(VideoSynthesisPathName) + "temp/"))
2211 2274
                         {
2212
-                            BtnRecord.IsEnabled = true;
2213
-                            btnStop.IsEnabled = true;
2214
-                            TxbRecordingWord.Text = "录制";
2215
-                            End();
2216
-                            txbTime.Text = "";
2217
-                            txbTime.Visibility = Visibility.Hidden;
2218
-                            txbType.Text = "";
2219
-                        });
2275
+                            Thread.Sleep(100);
2276
+                        }
2220 2277
                         FileToolsCommon.DeleteFile(ThumbnailPathName);
2221 2278
                         VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
2222 2279
                         Thread.Sleep(500);
2223 2280
                         //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
2224 2281
                         VideoInfo.VideoPath = VideoSavePathName;
2225 2282
                         VideoInfo.ThumbnailPath = ThumbnailPathName;
2226
-                        APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
2283
+                        //生成缩略图
2284
+                        bool ThuRes = APP.FFmpeg.GenerateThumbnails(VideoSynthesisPathName, ThumbnailPathName);
2285
+                        Thread.Sleep(500);
2286
+                        int imgW = (int)GridMain.ActualWidth + (GridMain.ActualWidth % 2 > 0 ? 1 : 0);
2287
+                        int imgH = (int)GridMain.ActualHeight + (GridMain.ActualHeight % 2 > 0 ? 1 : 0);
2288
+                        if (ThuRes)
2289
+                        {
2290
+                            Bitmap bmp = ImageHelper.ReadBitmapFile(ThumbnailPathName);
2291
+                            imgW = (int)bmp.Width + (bmp.Width % 2 > 0 ? 1 : 0);
2292
+                            imgH = (int)bmp.Height + (bmp.Height % 2 > 0 ? 1 : 0);
2293
+                        }
2294
+
2295
+                        APP.FFmpeg.VideoTranscode(VideoSynthesisPathName, VideoSavePathName, imgW, imgH);
2227 2296
                         VideoInfo.FileGuid = Guid.NewGuid().ToString();
2228 2297
                         VideoInfo.IsUpload = false;
2229 2298
                         VideoInfo.Uploaded = 0;
@@ -2232,6 +2301,13 @@ namespace XHWK.WKTool
2232 2301
                         //保存数据
2233 2302
                         APP.SaveWkData();
2234 2303
                         IsFirstR = true;
2304
+                        Dispatcher.Invoke(() =>
2305
+                        {
2306
+                            BtnRecord.IsEnabled = true;
2307
+                            btnStop.IsEnabled = true;
2308
+                            TxbRecordingWord.Text = "录制";
2309
+                            txbType.Text = "";
2310
+                        });
2235 2311
                     }))).Start();
2236 2312
                     //List<Model_Video> VideoList
2237 2313
                 }

Loading…
Cancel
Save