Browse Source

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

master
张剑 1 year ago
parent
commit
d6b74838dd

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

9
     <!--参数是否加密 0不加密 1加密-->
9
     <!--参数是否加密 0不加密 1加密-->
10
     <add key="IsParameterEncryption" value="0" />
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
     <!--皮肤样式 0白 1蓝 2黑色 -->
14
     <!--皮肤样式 0白 1蓝 2黑色 -->
15
     <add key="SkinStyle" value="0" />
15
     <add key="SkinStyle" value="0" />
16
     <!--是否输出视频记录日志:0否-->
16
     <!--是否输出视频记录日志:0否-->

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

1379
         /// </param>
1379
         /// </param>
1380
         private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
1380
         private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
1381
         {
1381
         {
1382
+            if (_recordType == 4)
1383
+            {
1384
+                return;
1385
+            }
1382
             JietuAction();
1386
             JietuAction();
1383
         }
1387
         }
1384
 
1388
 
2765
                             killProcess.Kill();
2769
                             killProcess.Kill();
2766
                         }
2770
                         }
2767
                         FFMpegConverter ffMpeg = new FFMpegConverter();
2771
                         FFMpegConverter ffMpeg = new FFMpegConverter();
2768
-                        FFMpegInput[] input = new FFMpegInput[]
2772
+                        FFMpegInput[] input =
2769
                         {
2773
                         {
2770
                             new FFMpegInput(_tempVideoPathName),
2774
                             new FFMpegInput(_tempVideoPathName),
2771
                             new FFMpegInput(_tempAudioPathName)
2775
                             new FFMpegInput(_tempAudioPathName)
2794
                         _videoInfo.Uploaded = 0;
2798
                         _videoInfo.Uploaded = 0;
2795
                         try
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
                         catch (Exception ex)
2803
                         catch (Exception ex)
2806
                         {
2804
                         {

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

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

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

1
 using System;
1
 using System;
2
+using System.Drawing.Imaging;
3
+using System.Drawing;
2
 using System.Runtime.InteropServices;
4
 using System.Runtime.InteropServices;
3
-
4
 using Accord.Video;
5
 using Accord.Video;
5
 using Accord.Video.FFMPEG;
6
 using Accord.Video.FFMPEG;
6
 
7
 
7
 namespace XHWK.WKTool.Utils
8
 namespace XHWK.WKTool.Utils
8
 {
9
 {
10
+    using System.Linq;
11
+
9
     public class ZVideoRecordHelper
12
     public class ZVideoRecordHelper
10
     {
13
     {
11
         public enum RecordState
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
         private int _rate = 5;
28
         private int _rate = 5;
40
             _rate = rate;
43
             _rate = rate;
41
             _quality = quality;
44
             _quality = quality;
42
             _captureMouse = captureMouse;
45
             _captureMouse = captureMouse;
43
-
44
-            _state = RecordState.pause;
46
+            _state = RecordState.Pause;
45
             try
47
             try
46
             {
48
             {
47
                 // 打开写入
49
                 // 打开写入
72
         /// </summary>
74
         /// </summary>
73
         public bool StartRecordVideo()
75
         public bool StartRecordVideo()
74
         {
76
         {
75
-            _state = RecordState.start;
77
+            _state = RecordState.Start;
76
             return true;
78
             return true;
77
         }
79
         }
78
 
80
 
98
         // 帧返回时绘制上鼠标
100
         // 帧返回时绘制上鼠标
99
         private void VideoNewFrame(object sender, NewFrameEventArgs e)
101
         private void VideoNewFrame(object sender, NewFrameEventArgs e)
100
         {
102
         {
101
-            if (_state == RecordState.start)
103
+            if (_state == RecordState.Start)
102
             {
104
             {
103
                 if (_captureMouse)
105
                 if (_captureMouse)
104
                 {
106
                 {
109
                     try
111
                     try
110
                     {
112
                     {
111
                         System.Windows.Forms.Cursor cur = new System.Windows.Forms.Cursor(pci.hCursor);
113
                         System.Windows.Forms.Cursor cur = new System.Windows.Forms.Cursor(pci.hCursor);
112
-                        cur.Draw(
114
+                        cur.Draw
115
+                        (
113
                             g,
116
                             g,
114
-                            new System.Drawing.Rectangle(
117
+                            new System.Drawing.Rectangle
118
+                            (
115
                                 System.Windows.Forms.Cursor.Position.X - 10,
119
                                 System.Windows.Forms.Cursor.Position.X - 10,
116
                                 System.Windows.Forms.Cursor.Position.Y - 10,
120
                                 System.Windows.Forms.Cursor.Position.Y - 10,
117
                                 cur.Size.Width,
121
                                 cur.Size.Width,
119
                             )
123
                             )
120
                         );
124
                         );
121
                     }
125
                     }
122
-                    catch { }//打开任务管理器时会导致异常
126
+                    catch { } //打开任务管理器时会导致异常
123
                 }
127
                 }
124
                 videoWriter.WriteVideoFrame(e.Frame);
128
                 videoWriter.WriteVideoFrame(e.Frame);
125
             }
129
             }
130
         /// </summary>
134
         /// </summary>
131
         public void StopRecordVideo()
135
         public void StopRecordVideo()
132
         {
136
         {
133
-            _state = RecordState.stop;
137
+            _state = RecordState.Stop;
134
             // 停止
138
             // 停止
135
             videoStreamer.Stop();
139
             videoStreamer.Stop();
136
 
140
 
144
         /// </summary>
148
         /// </summary>
145
         public void PauseRecordVideo()
149
         public void PauseRecordVideo()
146
         {
150
         {
147
-            _state = RecordState.pause;
151
+            _state = RecordState.Pause;
148
         }
152
         }
149
 
153
 
150
         /// <summary>
154
         /// <summary>
152
         /// </summary>
156
         /// </summary>
153
         public void ResumeRecordVideo()
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
 
3
 
4
 #define MyAppName "星火微课测试版"  
4
 #define MyAppName "星火微课测试版"  
5
 #define MyAppDir "xhwk_test"
5
 #define MyAppDir "xhwk_test"
6
-#define MyAppVersion "3.9.3"
6
+#define MyAppVersion "3.9.4"
7
 #define MyAppPublisher "河南星火燎原软件科技有限公司"
7
 #define MyAppPublisher "河南星火燎原软件科技有限公司"
8
 #define MyAppURL "http://www.xhkjedu.com/"
8
 #define MyAppURL "http://www.xhkjedu.com/"
9
 #define MySourcePath "D:\Project\CSharp\xh-wkclient\XHWK.WKTool\bin\x86\Debug\"
9
 #define MySourcePath "D:\Project\CSharp\xh-wkclient\XHWK.WKTool\bin\x86\Debug\"

Loading…
Cancel
Save