Browse Source

更换获取缩略图的方式,解决部分电脑无法生成缩略图的问题

master
张剑 1 year ago
parent
commit
d6b74838dd

+ 2
- 2
XHWK.WKTool/App.config View File

@@ -9,8 +9,8 @@
9 9
     <!--参数是否加密 0不加密 1加密-->
10 10
     <add key="IsParameterEncryption" value="0" />
11 11
     <!--版本号-->
12
-    <add key="VersionCode" value="120" />
13
-    <add key="VersionName" value="3.9.3" />
12
+    <add key="VersionCode" value="121" />
13
+    <add key="VersionName" value="3.9.4" />
14 14
     <!--皮肤样式 0白 1蓝 2黑色 -->
15 15
     <add key="SkinStyle" value="0" />
16 16
     <!--是否输出视频记录日志:0否-->

+ 6
- 8
XHWK.WKTool/MainWindow.xaml.cs View File

@@ -1379,6 +1379,10 @@ namespace XHWK.WKTool
1379 1379
         /// </param>
1380 1380
         private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
1381 1381
         {
1382
+            if (_recordType == 4)
1383
+            {
1384
+                return;
1385
+            }
1382 1386
             JietuAction();
1383 1387
         }
1384 1388
 
@@ -2765,7 +2769,7 @@ namespace XHWK.WKTool
2765 2769
                             killProcess.Kill();
2766 2770
                         }
2767 2771
                         FFMpegConverter ffMpeg = new FFMpegConverter();
2768
-                        FFMpegInput[] input = new FFMpegInput[]
2772
+                        FFMpegInput[] input =
2769 2773
                         {
2770 2774
                             new FFMpegInput(_tempVideoPathName),
2771 2775
                             new FFMpegInput(_tempAudioPathName)
@@ -2794,13 +2798,7 @@ namespace XHWK.WKTool
2794 2798
                         _videoInfo.Uploaded = 0;
2795 2799
                         try
2796 2800
                         {
2797
-                            App.FFmpeg.GenerateThumbnails
2798
-                            (
2799
-                                _tempVideoPathName,
2800
-                                thumbnailPathName,
2801
-                                200,
2802
-                                130
2803
-                            );
2801
+                            ZVideoRecordHelper.GetVideoPic(_tempVideoPathName, thumbnailPathName);
2804 2802
                         }
2805 2803
                         catch (Exception ex)
2806 2804
                         {

+ 1
- 7
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs View File

@@ -488,13 +488,7 @@ namespace XHWK.WKTool
488 488
                             _videoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
489 489
                             _videoInfo.VideoPath = _videoSavePathName;
490 490
                             _videoInfo.ThumbnailPath = thumbnailPathName;
491
-                            App.FFmpeg.GenerateThumbnails
492
-                            (
493
-                                _videoSavePathName,
494
-                                thumbnailPathName,
495
-                                200,
496
-                                130
497
-                            );
491
+                            ZVideoRecordHelper.GetVideoPic(_tempVideoPathName, thumbnailPathName);
498 492
                             _videoInfo.FileGuid = Guid.NewGuid().ToString();
499 493
                             _videoInfo.IsUpload = false;
500 494
                             _videoInfo.Uploaded = 0;

+ 66
- 19
XHWK.WKTool/Utils/ZVideoRecordHelper.cs View File

@@ -1,25 +1,28 @@
1 1
 using System;
2
+using System.Drawing.Imaging;
3
+using System.Drawing;
2 4
 using System.Runtime.InteropServices;
3
-
4 5
 using Accord.Video;
5 6
 using Accord.Video.FFMPEG;
6 7
 
7 8
 namespace XHWK.WKTool.Utils
8 9
 {
10
+    using System.Linq;
11
+
9 12
     public class ZVideoRecordHelper
10 13
     {
11 14
         public enum RecordState
12 15
         {
13
-            stop = 0,
14
-            start = 1,
15
-            pause = 2
16
+            Stop = 0,
17
+            Start = 1,
18
+            Pause = 2
16 19
         }
17 20
 
18
-        private RecordState _state = RecordState.stop;
21
+        private RecordState _state = RecordState.Stop;
19 22
 
20
-        private string _filePath = "";
21
-        private int _width = 0;
22
-        private int _height = 0;
23
+        private string _filePath;
24
+        private int _width;
25
+        private int _height;
23 26
 
24 27
         //录制帧率
25 28
         private int _rate = 5;
@@ -40,8 +43,7 @@ namespace XHWK.WKTool.Utils
40 43
             _rate = rate;
41 44
             _quality = quality;
42 45
             _captureMouse = captureMouse;
43
-
44
-            _state = RecordState.pause;
46
+            _state = RecordState.Pause;
45 47
             try
46 48
             {
47 49
                 // 打开写入
@@ -72,7 +74,7 @@ namespace XHWK.WKTool.Utils
72 74
         /// </summary>
73 75
         public bool StartRecordVideo()
74 76
         {
75
-            _state = RecordState.start;
77
+            _state = RecordState.Start;
76 78
             return true;
77 79
         }
78 80
 
@@ -98,7 +100,7 @@ namespace XHWK.WKTool.Utils
98 100
         // 帧返回时绘制上鼠标
99 101
         private void VideoNewFrame(object sender, NewFrameEventArgs e)
100 102
         {
101
-            if (_state == RecordState.start)
103
+            if (_state == RecordState.Start)
102 104
             {
103 105
                 if (_captureMouse)
104 106
                 {
@@ -109,9 +111,11 @@ namespace XHWK.WKTool.Utils
109 111
                     try
110 112
                     {
111 113
                         System.Windows.Forms.Cursor cur = new System.Windows.Forms.Cursor(pci.hCursor);
112
-                        cur.Draw(
114
+                        cur.Draw
115
+                        (
113 116
                             g,
114
-                            new System.Drawing.Rectangle(
117
+                            new System.Drawing.Rectangle
118
+                            (
115 119
                                 System.Windows.Forms.Cursor.Position.X - 10,
116 120
                                 System.Windows.Forms.Cursor.Position.Y - 10,
117 121
                                 cur.Size.Width,
@@ -119,7 +123,7 @@ namespace XHWK.WKTool.Utils
119 123
                             )
120 124
                         );
121 125
                     }
122
-                    catch { }//打开任务管理器时会导致异常
126
+                    catch { } //打开任务管理器时会导致异常
123 127
                 }
124 128
                 videoWriter.WriteVideoFrame(e.Frame);
125 129
             }
@@ -130,7 +134,7 @@ namespace XHWK.WKTool.Utils
130 134
         /// </summary>
131 135
         public void StopRecordVideo()
132 136
         {
133
-            _state = RecordState.stop;
137
+            _state = RecordState.Stop;
134 138
             // 停止
135 139
             videoStreamer.Stop();
136 140
 
@@ -144,7 +148,7 @@ namespace XHWK.WKTool.Utils
144 148
         /// </summary>
145 149
         public void PauseRecordVideo()
146 150
         {
147
-            _state = RecordState.pause;
151
+            _state = RecordState.Pause;
148 152
         }
149 153
 
150 154
         /// <summary>
@@ -152,7 +156,50 @@ namespace XHWK.WKTool.Utils
152 156
         /// </summary>
153 157
         public void ResumeRecordVideo()
154 158
         {
155
-            _state = RecordState.start;
159
+            _state = RecordState.Start;
160
+        }
161
+
162
+        /// <summary>
163
+        /// 生成缩略图
164
+        /// </summary>
165
+        /// <param name="mp4Path"></param>
166
+        /// <param name="picPath"></param>
167
+        public static void GetVideoPic(string mp4Path, string picPath)
168
+        {
169
+            using (var video = new VideoFileReader())
170
+            {
171
+                video.Open(mp4Path);
172
+                int frameNum = video.FrameCount > 3 ? 3 : 0;
173
+                using (var bmp = video.ReadVideoFrame(frameNum))
174
+                {
175
+                    SaveAsJpeg
176
+                    (
177
+                        bmp,
178
+                        picPath,
179
+                        90
180
+                    );
181
+                }
182
+                video.Close();
183
+            }
184
+        }
185
+
186
+        // 保存为jpeg格式,quality为图像质量(0-100)
187
+        public static void SaveAsJpeg
188
+        (
189
+            Bitmap bitmap,
190
+            string fileName,
191
+            int quality
192
+        )
193
+        {
194
+            var jpegEncoder = ImageCodecInfo.GetImageEncoders().First(codec => codec.FormatID == ImageFormat.Jpeg.Guid);
195
+            var encoderParameters = new EncoderParameters(1);
196
+            encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, quality);
197
+            bitmap.Save
198
+            (
199
+                fileName,
200
+                jpegEncoder,
201
+                encoderParameters
202
+            );
156 203
         }
157 204
     }
158
-}
205
+}

+ 1
- 1
星火微课/星火微课-测试.iss View File

@@ -3,7 +3,7 @@
3 3
 
4 4
 #define MyAppName "星火微课测试版"  
5 5
 #define MyAppDir "xhwk_test"
6
-#define MyAppVersion "3.9.3"
6
+#define MyAppVersion "3.9.4"
7 7
 #define MyAppPublisher "河南星火燎原软件科技有限公司"
8 8
 #define MyAppURL "http://www.xhkjedu.com/"
9 9
 #define MySourcePath "D:\Project\CSharp\xh-wkclient\XHWK.WKTool\bin\x86\Debug\"

Loading…
Cancel
Save