Ver código fonte

Merge remote-tracking branch 'origin/zyy' into zhangxueyang

tags/录制修改前
zhangxueyang 4 anos atrás
pai
commit
c0ae243a6e

+ 57
- 16
Common/system/FFMpeg.cs Ver arquivo

@@ -1,6 +1,7 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3 3
 using System.Diagnostics;
4
+using System.Text;
4 5
 using System.Threading;
5 6
 
6 7
 using VisioForge.Shared.NAudio.CoreAudioApi;
@@ -99,7 +100,7 @@ namespace Common.system
99 100
             }
100 101
             if (IsRecordMicrophone)
101 102
             {
102
-                MicrophoneName = GetMicrophone();
103
+                MicrophoneName = GetInDeviceFull();
103 104
                 if (!string.IsNullOrWhiteSpace(MicrophoneName))
104 105
                 {
105 106
                     MicrophoneStr = "-f dshow -i audio=\"" + MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 ";
@@ -108,7 +109,7 @@ namespace Common.system
108 109
             switch (Extension.ToUpper())
109 110
             {
110 111
                 case ".MP4":
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 gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
112 113
                     //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;
113 114
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
114 115
                     //{
@@ -122,7 +123,7 @@ namespace Common.system
122 123
                     break;
123 124
                 case ".AVI":
124 125
                 case ".FLV":
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;
126
+                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac -f " + Extension.ToLower().Replace(".", "") + " " + PathName;
126 127
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
127 128
                     //{
128 129
                     //    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的参数
@@ -134,9 +135,10 @@ namespace Common.system
134 135
                     //}
135 136
                     break;
136 137
                 default:
137
-                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f gdigrab -i desktop -pix_fmt yuv420p -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
138
+                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
138 139
                     break;
139 140
             }
141
+            LogHelper.WriteInfoLog("【录屏】:"+myProcess.StartInfo.Arguments);
140 142
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
141 143
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
142 144
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
@@ -192,7 +194,7 @@ namespace Common.system
192 194
             if (StartRecordAudio(audioMicrophonePath))
193 195
             {
194 196
                 IsRecordMicrophone = true;
195
-                MicrophoneName = GetMicrophone();
197
+                MicrophoneName = GetInDeviceFull();
196 198
             }
197 199
             else
198 200
             {
@@ -226,6 +228,7 @@ namespace Common.system
226 228
                         MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 " + PathName;
227 229
                 }
228 230
             }
231
+            LogHelper.WriteInfoLog("【录音】:" + myProcess.StartInfo.Arguments);
229 232
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
230 233
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
231 234
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
@@ -788,14 +791,14 @@ namespace Common.system
788 791
         }
789 792
 
790 793
         /// <summary>
791
-        /// 获取麦克风列表
794
+        /// 获取声音输入设备完整名称
792 795
         /// </summary>
793
-        public List<string> GetMicrophoneList()
796
+        /// <returns></returns>
797
+        public static string GetInDeviceFull()
794 798
         {
795
-            List<string> devs = new List<string>();
796
-
797
-            MMDeviceEnumerator enumberator = new MMDeviceEnumerator();
798
-            MMDeviceCollection deviceCollection = enumberator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.All);
799
+            List<string> devices = new List<string>();
800
+            var enumberator = new MMDeviceEnumerator();
801
+            var deviceCollection = enumberator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.All);
799 802
             for (int waveInDevice = 0; waveInDevice < WaveIn.DeviceCount; waveInDevice++)
800 803
             {
801 804
                 WaveInCapabilities deviceInfo = WaveIn.GetCapabilities(waveInDevice);
@@ -803,20 +806,58 @@ namespace Common.system
803 806
                 {
804 807
                     try
805 808
                     {
806
-
807 809
                         if (device.FriendlyName.StartsWith(deviceInfo.ProductName))
808 810
                         {
809
-                            devs.Add(device.FriendlyName);
811
+                            devices.Add(device.FriendlyName);
810 812
                             break;
811 813
                         }
812 814
                     }
813
-                    catch (Exception)
815
+                    catch (Exception ex)
814 816
                     {
815
-
817
+                        continue;
818
+                    }
819
+                }
820
+            }
821
+            if (devices.Count > 0)
822
+            {
823
+                byte[] buffer = Encoding.UTF8.GetBytes(devices[0]);
824
+                string MicrophoneName = Encoding.UTF8.GetString(buffer); // 统一使用UTF-8
825
+                return MicrophoneName;
826
+            }
827
+            else
828
+            {
829
+                return "";
830
+            }
831
+        }
832
+        /// <summary>
833
+        /// 获取声音输入设备完整名称
834
+        /// </summary>
835
+        /// <returns></returns>
836
+        public List<string> GetInDeviceListFull()
837
+        {
838
+            List<string> devices = new List<string>();
839
+            var enumberator = new MMDeviceEnumerator();
840
+            var deviceCollection = enumberator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.All);
841
+            for (int waveInDevice = 0; waveInDevice < WaveIn.DeviceCount; waveInDevice++)
842
+            {
843
+                WaveInCapabilities deviceInfo = WaveIn.GetCapabilities(waveInDevice);
844
+                foreach (MMDevice device in deviceCollection)
845
+                {
846
+                    try
847
+                    {
848
+                        if (device.FriendlyName.StartsWith(deviceInfo.ProductName))
849
+                        {
850
+                            devices.Add(device.FriendlyName);
851
+                            break;
852
+                        }
853
+                    }
854
+                    catch (Exception ex)
855
+                    {
856
+                        continue;
816 857
                     }
817 858
                 }
818 859
             }
819
-            return devs;
860
+            return devices;
820 861
         }
821 862
 
822 863
         /// <summary>

+ 14
- 6
Common/system/ImageHelper.cs Ver arquivo

@@ -421,14 +421,21 @@ namespace Common.system
421 421
                         encoder.Save(memoryStream);
422 422
                         //System.Drawing.Image img = System.Drawing.Image.FromStream(memoryStream);
423 423
                         Bitmap bit = new Bitmap(memoryStream);
424
-                        try
424
+                        if ((int)ImgWidth-2 < (int)bit.Width)
425 425
                         {
426
-                            Graphics g = Graphics.FromImage(Img);
427
-                            //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
428
-                            g.DrawImage(bit, new Rectangle(0, 0, ImgWidth, ImgHeight), new Rectangle(0, 0, (int)bit.Width, (int)bit.Height), GraphicsUnit.Pixel);
429
-                            g.Dispose();
426
+                            try
427
+                            {
428
+                                Graphics g = Graphics.FromImage(Img);
429
+                                //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
430
+                                g.DrawImage(bit, new Rectangle(0, 0, ImgWidth, ImgHeight), new Rectangle(0, 0, (int)bit.Width, (int)bit.Height), GraphicsUnit.Pixel);
431
+                                g.Dispose();
432
+                            }
433
+                            catch
434
+                            {
435
+                                Img = bit;
436
+                            }
430 437
                         }
431
-                        catch
438
+                        else
432 439
                         {
433 440
                             Img = bit;
434 441
                         }
@@ -439,6 +446,7 @@ namespace Common.system
439 446
                             //FileToolsCommon.DeleteFile(filePathName);
440 447
                             //bitmap.Save(filePathName);
441 448
                             //bitmap.Dispose();
449
+                            memoryStream.Dispose();
442 450
                             Img.Dispose();
443 451
                             bit.Dispose();
444 452
                         }))).Start();

+ 5
- 2
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs Ver arquivo

@@ -351,7 +351,6 @@ namespace XHWK.WKTool
351 351
                         WkType = Enum_WKVidetype.RecordingScreen
352 352
                     };
353 353
                     SetUpVideoPathName();
354
-                    IsFirstRS = false;
355 354
                     k_hook.Start();//安装键盘钩子
356 355
 
357 356
                     if (APP.W_CountdownWindow == null)
@@ -417,7 +416,10 @@ namespace XHWK.WKTool
417 416
                     #endregion
418 417
                     new Thread(new ThreadStart(new Action(() =>
419 418
                     {
420
-                        Thread.Sleep(800);
419
+                        if (IsFirstRS)
420
+                        {
421
+                            Thread.Sleep(800);
422
+                        }
421 423
                         if(APP.FFmpeg.myProcess!=null)
422 424
                         {
423 425
                             Thread.Sleep(100);
@@ -435,6 +437,7 @@ namespace XHWK.WKTool
435 437
                 {
436 438
                     MessageWindow.Show(ex.Message);
437 439
                 }
440
+                IsFirstRS = false;
438 441
             }
439 442
             else
440 443
             {

Carregando…
Cancelar
Salvar