瀏覽代碼

zhao:1解决缩放百分比后无法录制全屏的问题。 2优化录制效率,限制录制视频大小,异步保存。

tags/录制修改前
耀 4 年之前
父節點
當前提交
3e5f75b995

+ 4
- 3
Common/system/FFMpeg.cs 查看文件

@@ -108,7 +108,8 @@ namespace Common.system
108 108
             switch (Extension.ToUpper())
109 109
             {
110 110
                 case ".MP4":
111
-                    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 " + PathName;
111
+                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f gdigrab -i desktop -pix_fmt yuv420p -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
112
+                    //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 " + PathName;
112 113
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
113 114
                     //{
114 115
                     //    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 " + PathName;  //ffmpeg的参数
@@ -121,7 +122,7 @@ namespace Common.system
121 122
                     break;
122 123
                 case ".AVI":
123 124
                 case ".FLV":
124
-                    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;
125
+                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f gdigrab -i desktop -pix_fmt yuv420p -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac -f " + Extension.ToLower().Replace(".", "") + " " + PathName;
125 126
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
126 127
                     //{
127 128
                     //    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的参数
@@ -133,7 +134,7 @@ namespace Common.system
133 134
                     //}
134 135
                     break;
135 136
                 default:
136
-                    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 " + PathName;
137
+                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f gdigrab -i desktop -pix_fmt yuv420p -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
137 138
                     break;
138 139
             }
139 140
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动

+ 38
- 16
Common/system/ImageHelper.cs 查看文件

@@ -6,9 +6,12 @@ using System.IO;
6 6
 using System.Text;
7 7
 using System.Threading;
8 8
 using System.Windows;
9
+using System.Windows.Documents;
9 10
 using System.Windows.Media;
10 11
 using System.Windows.Media.Imaging;
11 12
 
13
+using VisioForge.Shared.Helpers;
14
+
12 15
 namespace Common.system
13 16
 {
14 17
     /// <summary>
@@ -447,25 +450,23 @@ namespace Common.system
447 450
                 }
448 451
                 else
449 452
                 {
453
+                    //SaveImageModel sim = new SaveImageModel();
454
+                    //sim.encoder = new PngBitmapEncoder();
455
+                    //sim.encoder = new PngBitmapEncoder();
456
+                    //BitmapFrame test= encoder.Frames[0];
457
+                    //sim.encoder.Frames.Add(BitmapFrame.Create(test));
458
+                    ////sim.encoder.Frames[0].CopyTo(encoder.Frames[0]);
459
+                    ////sim.encoder.CopyTo(encoder);
460
+                    ////encoder.CopyTo(sim.encoder);
461
+                    //sim.FilePath = filePathName;
462
+                    ////sim.bmp = new RenderTargetBitmap(width, height, PrimaryScreen.DpiX, PrimaryScreen.DpiY, PixelFormats.Pbgra32);
463
+                    ////bmp.CopyTo(sim.bmp);
464
+                    //Thread t1 = new Thread(SaveImage);
465
+                    //t1.Start(sim);
466
+
450 467
                     System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
451 468
                     encoder.Save(fs);
452 469
                     fs.Close();
453
-
454
-                    //MemoryStream memoryStream = new MemoryStream();
455
-                    //encoder.Save(memoryStream);
456
-                    //Bitmap bit = new Bitmap(memoryStream);
457
-                    //bit.Save(filePathName);
458
-                    //bit.Dispose();
459
-
460
-                    //using (FileStream tFileStream = new FileStream(filePathName,FileMode.Create, FileAccess.Write))
461
-                    //{
462
-                    //    PngBitmapEncoder tPngBitmapEncoder = new PngBitmapEncoder();
463
-                    //    tPngBitmapEncoder.Interlace = PngInterlaceOption.On;
464
-                    //    tPngBitmapEncoder.Frames.Add(BitmapFrame.Create(bmp));
465
-                    //    tPngBitmapEncoder.Save(tFileStream);
466
-                    //    tFileStream.Close();
467
-                    //}
468
-
469 470
                 }
470 471
             }
471 472
             catch (Exception ex)
@@ -474,6 +475,20 @@ namespace Common.system
474 475
                 //Console.WriteLine(ex.Message);
475 476
             }
476 477
         }
478
+
479
+        private static void SaveImage(object obj)
480
+        {
481
+            SaveImageModel sim = (SaveImageModel)obj;
482
+            //RenderTargetBitmap bmp = sim.bmp;
483
+            //BitmapEncoder encoder = new PngBitmapEncoder();
484
+            //encoder.Frames.Add(BitmapFrame.Create(bmp));
485
+            BitmapEncoder encoder = sim.encoder;
486
+            string filePathName = sim.FilePath;
487
+            System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
488
+            encoder.Save(fs);
489
+            fs.Close();
490
+        }
491
+
477 492
         #endregion
478 493
 
479 494
         #region 去掉白边
@@ -600,4 +615,11 @@ namespace Common.system
600 615
         }
601 616
         #endregion
602 617
     }
618
+    public class SaveImageModel
619
+    {
620
+        public string FilePath { get; set; }
621
+        public BitmapEncoder encoder { get; set; }
622
+        //public RenderTargetBitmap bmp { get; set; }
623
+    }
624
+
603 625
 }

+ 2
- 5
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs 查看文件

@@ -391,17 +391,14 @@ namespace XHWK.WKTool
391 391
                     #endregion
392 392
                     new Thread(new ThreadStart(new Action(() =>
393 393
                     {
394
-                        if (IsFirstRS)
395
-                        {
396
-                            Thread.Sleep(1500);
397
-                        }
394
+                        Thread.Sleep(800);
398 395
                         if(APP.FFmpeg.myProcess!=null)
399 396
                         {
400 397
                             Thread.Sleep(100);
401 398
                         }
402 399
                         APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
403 400
 
404
-                        Thread.Sleep(1000);
401
+                        Thread.Sleep(1300);
405 402
                         Dispatcher.Invoke(() =>
406 403
                         {
407 404
                             Stack();

+ 1
- 1
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs 查看文件

@@ -3114,7 +3114,7 @@ namespace XHWK.WKTool
3114 3114
                         //}
3115 3115
                         #endregion         
3116 3116
                         //保存图片
3117
-                        ImageHelper.SaveUIToImage(GridMain, FilePathName, gridActWidth, gridActHeight, 0, 0);
3117
+                        ImageHelper.SaveUIToImage(GridMain, FilePathName, gridActWidth, gridActHeight, gridActWidth, gridActHeight);
3118 3118
                         //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f)), 0, 0);
3119 3119
                         //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), (int)RsW, (int)RsH);
3120 3120
                         //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), 1281, 1026);

Loading…
取消
儲存