Browse Source

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

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

+ 4
- 3
Common/system/FFMpeg.cs View File

108
             switch (Extension.ToUpper())
108
             switch (Extension.ToUpper())
109
             {
109
             {
110
                 case ".MP4":
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
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
113
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
113
                     //{
114
                     //{
114
                     //    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的参数
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
                     break;
122
                     break;
122
                 case ".AVI":
123
                 case ".AVI":
123
                 case ".FLV":
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
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
126
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
126
                     //{
127
                     //{
127
                     //    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的参数
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
                     //}
134
                     //}
134
                     break;
135
                     break;
135
                 default:
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
                     break;
138
                     break;
138
             }
139
             }
139
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
140
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动

+ 38
- 16
Common/system/ImageHelper.cs View File

6
 using System.Text;
6
 using System.Text;
7
 using System.Threading;
7
 using System.Threading;
8
 using System.Windows;
8
 using System.Windows;
9
+using System.Windows.Documents;
9
 using System.Windows.Media;
10
 using System.Windows.Media;
10
 using System.Windows.Media.Imaging;
11
 using System.Windows.Media.Imaging;
11
 
12
 
13
+using VisioForge.Shared.Helpers;
14
+
12
 namespace Common.system
15
 namespace Common.system
13
 {
16
 {
14
     /// <summary>
17
     /// <summary>
447
                 }
450
                 }
448
                 else
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
                     System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
467
                     System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
451
                     encoder.Save(fs);
468
                     encoder.Save(fs);
452
                     fs.Close();
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
             catch (Exception ex)
472
             catch (Exception ex)
474
                 //Console.WriteLine(ex.Message);
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
         #endregion
492
         #endregion
478
 
493
 
479
         #region 去掉白边
494
         #region 去掉白边
600
         }
615
         }
601
         #endregion
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 View File

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

+ 1
- 1
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs View File

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

Loading…
Cancel
Save