Browse Source

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

tags/录制修改前
zhangxueyang 4 years ago
parent
commit
c0ae243a6e

+ 57
- 16
Common/system/FFMpeg.cs View File

1
 using System;
1
 using System;
2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
 using System.Diagnostics;
3
 using System.Diagnostics;
4
+using System.Text;
4
 using System.Threading;
5
 using System.Threading;
5
 
6
 
6
 using VisioForge.Shared.NAudio.CoreAudioApi;
7
 using VisioForge.Shared.NAudio.CoreAudioApi;
99
             }
100
             }
100
             if (IsRecordMicrophone)
101
             if (IsRecordMicrophone)
101
             {
102
             {
102
-                MicrophoneName = GetMicrophone();
103
+                MicrophoneName = GetInDeviceFull();
103
                 if (!string.IsNullOrWhiteSpace(MicrophoneName))
104
                 if (!string.IsNullOrWhiteSpace(MicrophoneName))
104
                 {
105
                 {
105
                     MicrophoneStr = "-f dshow -i audio=\"" + MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 ";
106
                     MicrophoneStr = "-f dshow -i audio=\"" + MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 ";
108
             switch (Extension.ToUpper())
109
             switch (Extension.ToUpper())
109
             {
110
             {
110
                 case ".MP4":
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
                     //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
                     //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
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
114
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
114
                     //{
115
                     //{
122
                     break;
123
                     break;
123
                 case ".AVI":
124
                 case ".AVI":
124
                 case ".FLV":
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
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
127
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
127
                     //{
128
                     //{
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的参数
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
                     //}
135
                     //}
135
                     break;
136
                     break;
136
                 default:
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
                     break;
139
                     break;
139
             }
140
             }
141
+            LogHelper.WriteInfoLog("【录屏】:"+myProcess.StartInfo.Arguments);
140
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
142
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
141
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
143
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
142
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
144
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
192
             if (StartRecordAudio(audioMicrophonePath))
194
             if (StartRecordAudio(audioMicrophonePath))
193
             {
195
             {
194
                 IsRecordMicrophone = true;
196
                 IsRecordMicrophone = true;
195
-                MicrophoneName = GetMicrophone();
197
+                MicrophoneName = GetInDeviceFull();
196
             }
198
             }
197
             else
199
             else
198
             {
200
             {
226
                         MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 " + PathName;
228
                         MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 " + PathName;
227
                 }
229
                 }
228
             }
230
             }
231
+            LogHelper.WriteInfoLog("【录音】:" + myProcess.StartInfo.Arguments);
229
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
232
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
230
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
233
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
231
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
234
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
788
         }
791
         }
789
 
792
 
790
         /// <summary>
793
         /// <summary>
791
-        /// 获取麦克风列表
794
+        /// 获取声音输入设备完整名称
792
         /// </summary>
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
             for (int waveInDevice = 0; waveInDevice < WaveIn.DeviceCount; waveInDevice++)
802
             for (int waveInDevice = 0; waveInDevice < WaveIn.DeviceCount; waveInDevice++)
800
             {
803
             {
801
                 WaveInCapabilities deviceInfo = WaveIn.GetCapabilities(waveInDevice);
804
                 WaveInCapabilities deviceInfo = WaveIn.GetCapabilities(waveInDevice);
803
                 {
806
                 {
804
                     try
807
                     try
805
                     {
808
                     {
806
-
807
                         if (device.FriendlyName.StartsWith(deviceInfo.ProductName))
809
                         if (device.FriendlyName.StartsWith(deviceInfo.ProductName))
808
                         {
810
                         {
809
-                            devs.Add(device.FriendlyName);
811
+                            devices.Add(device.FriendlyName);
810
                             break;
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
         /// <summary>
863
         /// <summary>

+ 14
- 6
Common/system/ImageHelper.cs View File

421
                         encoder.Save(memoryStream);
421
                         encoder.Save(memoryStream);
422
                         //System.Drawing.Image img = System.Drawing.Image.FromStream(memoryStream);
422
                         //System.Drawing.Image img = System.Drawing.Image.FromStream(memoryStream);
423
                         Bitmap bit = new Bitmap(memoryStream);
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
                             Img = bit;
440
                             Img = bit;
434
                         }
441
                         }
439
                             //FileToolsCommon.DeleteFile(filePathName);
446
                             //FileToolsCommon.DeleteFile(filePathName);
440
                             //bitmap.Save(filePathName);
447
                             //bitmap.Save(filePathName);
441
                             //bitmap.Dispose();
448
                             //bitmap.Dispose();
449
+                            memoryStream.Dispose();
442
                             Img.Dispose();
450
                             Img.Dispose();
443
                             bit.Dispose();
451
                             bit.Dispose();
444
                         }))).Start();
452
                         }))).Start();

+ 5
- 2
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs View File

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

Loading…
Cancel
Save