|
@@ -36,7 +36,7 @@ namespace Common.system
|
36
|
36
|
string Path = FileToolsCommon.GetDirectoryName(FilePath);
|
37
|
37
|
string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
|
38
|
38
|
//文件保存路径
|
39
|
|
- string PathName = GetFilePathName(FilePath);
|
|
39
|
+ string PathName = GetRSFilePathName(FilePath);
|
40
|
40
|
Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
|
41
|
41
|
foreach (var KillProcess in KillProcessArray)
|
42
|
42
|
{
|
|
@@ -44,7 +44,21 @@ namespace Common.system
|
44
|
44
|
}
|
45
|
45
|
myProcess = new Process();
|
46
|
46
|
LogPath = CreateffmpegLog();
|
47
|
|
- string MicrophoneName = GetMicrophone();
|
|
47
|
+ string MicrophoneName = null;
|
|
48
|
+ string audioTestPath = FileToolsCommon.GetFileAbsolutePath("ado.m");
|
|
49
|
+ try
|
|
50
|
+ {
|
|
51
|
+ FileToolsCommon.DeleteFile(audioTestPath);
|
|
52
|
+ }
|
|
53
|
+ catch (Exception)
|
|
54
|
+ {
|
|
55
|
+
|
|
56
|
+ }
|
|
57
|
+ if (StartRecordAudio(audioTestPath))
|
|
58
|
+ {
|
|
59
|
+ MicrophoneName = GetMicrophone();
|
|
60
|
+ }
|
|
61
|
+ StopRecordAudio();
|
48
|
62
|
myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
49
|
63
|
switch (Extension.ToUpper())
|
50
|
64
|
{
|
|
@@ -102,6 +116,8 @@ namespace Common.system
|
102
|
116
|
{
|
103
|
117
|
Thread.Sleep(100);
|
104
|
118
|
}
|
|
119
|
+ //路径
|
|
120
|
+ string Path = FileToolsCommon.GetDirectoryName(Mp3Path);
|
105
|
121
|
//文件保存路径
|
106
|
122
|
string PathName = GetFilePathName(Mp3Path);
|
107
|
123
|
Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
|
|
@@ -112,7 +128,21 @@ namespace Common.system
|
112
|
128
|
myProcess = new Process();
|
113
|
129
|
LogPath = CreateffmpegLog();
|
114
|
130
|
this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
115
|
|
- string MicrophoneName = GetMicrophone();
|
|
131
|
+ string MicrophoneName = null;
|
|
132
|
+ string audioTestPath = FileToolsCommon.GetFileAbsolutePath("ado.m");
|
|
133
|
+ try
|
|
134
|
+ {
|
|
135
|
+ FileToolsCommon.DeleteFile(audioTestPath);
|
|
136
|
+ }
|
|
137
|
+ catch (Exception)
|
|
138
|
+ {
|
|
139
|
+
|
|
140
|
+ }
|
|
141
|
+ if (StartRecordAudio(audioTestPath))
|
|
142
|
+ {
|
|
143
|
+ MicrophoneName = GetMicrophone();
|
|
144
|
+ }
|
|
145
|
+ StopRecordAudio();
|
116
|
146
|
if (string.IsNullOrWhiteSpace(MicrophoneName))
|
117
|
147
|
{
|
118
|
148
|
myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" " + PathName;
|
|
@@ -205,86 +235,88 @@ namespace Common.system
|
205
|
235
|
/// <param name="VideoHeight">视频高度</param>
|
206
|
236
|
public void SynthesisVideo(string ImageListPath, string Mp3Path, string VideoSavePath, int Frequency, int VideoWidth, int VideoHeight)
|
207
|
237
|
{
|
208
|
|
- new Thread(new ThreadStart(new Action(() =>
|
|
238
|
+ //new Thread(new ThreadStart(new Action(() =>
|
|
239
|
+ //{
|
|
240
|
+
|
|
241
|
+ //}))).Start();
|
|
242
|
+ while (myProcess != null)
|
|
243
|
+ {
|
|
244
|
+ Thread.Sleep(100);
|
|
245
|
+ }
|
|
246
|
+ string Extension = FileToolsCommon.GetIOExtension(VideoSavePath);//扩展名
|
|
247
|
+ Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
|
|
248
|
+ //Debug.WriteLine(KillProcessArray.Length.ToString());
|
|
249
|
+ foreach (var KillProcess in KillProcessArray)
|
|
250
|
+ {
|
|
251
|
+ KillProcess.Kill();
|
|
252
|
+ }
|
|
253
|
+ myProcess = new Process();
|
|
254
|
+ LogPath = CreateffmpegLog();
|
|
255
|
+ this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
|
256
|
+ switch (Extension.ToUpper())
|
209
|
257
|
{
|
210
|
|
- Thread.Sleep(500);
|
211
|
|
- while (myProcess != null)
|
|
258
|
+ case "MP4":
|
|
259
|
+ myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
|
|
260
|
+ ImageListPath + @"%d.png -i " +
|
|
261
|
+ Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
|
|
262
|
+ VideoSavePath;
|
|
263
|
+ break;
|
|
264
|
+ case "AVI":
|
|
265
|
+ myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
|
|
266
|
+ ImageListPath + @"%d.png -i " +
|
|
267
|
+ Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -f AVI " +
|
|
268
|
+ VideoSavePath;
|
|
269
|
+ break;
|
|
270
|
+ case "FLV":
|
|
271
|
+ myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
|
|
272
|
+ ImageListPath + @"%d.png -i " +
|
|
273
|
+ Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -f FLV " +
|
|
274
|
+ VideoSavePath;
|
|
275
|
+ break;
|
|
276
|
+ default:
|
|
277
|
+ myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
|
|
278
|
+ ImageListPath + @"%d.png -i " +
|
|
279
|
+ Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
|
|
280
|
+ VideoSavePath;
|
|
281
|
+ break;
|
|
282
|
+ }
|
|
283
|
+ myProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
|
|
284
|
+ myProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
|
|
285
|
+ myProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
|
|
286
|
+ myProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
|
|
287
|
+ //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
|
|
288
|
+ myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
|
|
289
|
+ myProcess.Start(); //启动线程
|
|
290
|
+ myProcess.BeginErrorReadLine(); //开始异步读取
|
|
291
|
+ myProcess.WaitForExit(); //阻塞等待进程结束
|
|
292
|
+ myProcess.Close(); //关闭进程
|
|
293
|
+ myProcess.Dispose(); //释放资源
|
|
294
|
+ #region 进程是否已经释放
|
|
295
|
+ bool IsRunning = true;
|
|
296
|
+ while (IsRunning)
|
|
297
|
+ {
|
|
298
|
+ IsRunning = false;
|
|
299
|
+ Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
|
|
300
|
+ foreach (var KillProcess in ProcessArray)
|
212
|
301
|
{
|
|
302
|
+ IsRunning = true;
|
213
|
303
|
Thread.Sleep(100);
|
214
|
304
|
}
|
215
|
|
- string Extension = FileToolsCommon.GetIOExtension(VideoSavePath);//扩展名
|
216
|
|
- Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
|
217
|
|
- //Debug.WriteLine(KillProcessArray.Length.ToString());
|
218
|
|
- foreach (var KillProcess in KillProcessArray)
|
219
|
|
- {
|
220
|
|
- KillProcess.Kill();
|
221
|
|
- }
|
222
|
|
- myProcess = new Process();
|
223
|
|
- LogPath = CreateffmpegLog();
|
224
|
|
- this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
225
|
|
- switch (Extension.ToUpper())
|
226
|
|
- {
|
227
|
|
- case "MP4":
|
228
|
|
- myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
|
229
|
|
- ImageListPath + @"%d.png -i " +
|
230
|
|
- Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
|
231
|
|
- VideoSavePath;
|
232
|
|
- break;
|
233
|
|
- case "AVI":
|
234
|
|
- myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
|
235
|
|
- ImageListPath + @"%d.png -i " +
|
236
|
|
- Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -f AVI " +
|
237
|
|
- VideoSavePath;
|
238
|
|
- break;
|
239
|
|
- case "FLV":
|
240
|
|
- myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
|
241
|
|
- ImageListPath + @"%d.png -i " +
|
242
|
|
- Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -f FLV " +
|
243
|
|
- VideoSavePath;
|
244
|
|
- break;
|
245
|
|
- default:
|
246
|
|
- myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
|
247
|
|
- ImageListPath + @"%d.png -i " +
|
248
|
|
- Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
|
249
|
|
- VideoSavePath;
|
250
|
|
- break;
|
251
|
|
- }
|
252
|
|
- myProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
|
253
|
|
- myProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
|
254
|
|
- myProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
|
255
|
|
- myProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
|
256
|
|
- //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
|
257
|
|
- myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
|
258
|
|
- myProcess.Start(); //启动线程
|
259
|
|
- myProcess.BeginErrorReadLine(); //开始异步读取
|
260
|
|
- myProcess.WaitForExit(); //阻塞等待进程结束
|
261
|
|
- myProcess.Close(); //关闭进程
|
262
|
|
- myProcess.Dispose(); //释放资源
|
263
|
|
- #region 进程是否已经释放
|
264
|
|
- bool IsRunning = true;
|
265
|
|
- while (IsRunning)
|
266
|
|
- {
|
267
|
|
- IsRunning = false;
|
268
|
|
- Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
|
269
|
|
- foreach (var KillProcess in ProcessArray)
|
270
|
|
- {
|
271
|
|
- IsRunning = true;
|
272
|
|
- Thread.Sleep(100);
|
273
|
|
- }
|
274
|
|
- }
|
275
|
|
- #endregion
|
276
|
|
- myProcess = null;
|
277
|
|
- //生成视频后删除图片和音频保存列表
|
278
|
|
- //FileToolsCommon.DeleteDirectory(ImageListPath);
|
279
|
|
- //FileToolsCommon.DeleteDirectory(FileToolsCommon.GetDirectoryName(Mp3Path));
|
280
|
|
- FileToolsCommon.DeleteDirectory(FileToolsCommon.GetDirectoryName(VideoSavePath) + "temp/");
|
|
305
|
+ }
|
|
306
|
+ #endregion
|
|
307
|
+ myProcess = null;
|
|
308
|
+ //生成视频后删除图片和音频保存列表
|
|
309
|
+ //FileToolsCommon.DeleteDirectory(ImageListPath);
|
|
310
|
+ //FileToolsCommon.DeleteDirectory(FileToolsCommon.GetDirectoryName(Mp3Path));
|
|
311
|
+
|
|
312
|
+ Thread.Sleep(100);
|
|
313
|
+ FileToolsCommon.DeleteDirectory(FileToolsCommon.GetDirectoryName(VideoSavePath) + "temp");
|
281
|
314
|
|
282
|
|
- //Dispatcher.Invoke(() =>
|
283
|
|
- //{
|
284
|
|
- //});
|
285
|
|
- //// 允许不同线程间的调用
|
286
|
|
- //Control.CheckForIllegalCrossThreadCalls = false;
|
287
|
|
- }))).Start();
|
|
315
|
+ //Dispatcher.Invoke(() =>
|
|
316
|
+ //{
|
|
317
|
+ //});
|
|
318
|
+ //// 允许不同线程间的调用
|
|
319
|
+ //Control.CheckForIllegalCrossThreadCalls = false;
|
288
|
320
|
}
|
289
|
321
|
|
290
|
322
|
/// <summary>
|
|
@@ -307,15 +339,24 @@ namespace Common.system
|
307
|
339
|
//路径
|
308
|
340
|
string FilePath = (string)FilePathobj;
|
309
|
341
|
string Path = FileToolsCommon.GetDirectoryName(FilePath);
|
310
|
|
- Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
|
311
|
|
- foreach (var KillProcess in KillProcessArray)
|
312
|
|
- {
|
313
|
|
- KillProcess.Kill();
|
314
|
|
- }
|
|
342
|
+ string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
|
|
343
|
+ //Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
|
|
344
|
+ //foreach (var KillProcess in KillProcessArray)
|
|
345
|
+ //{
|
|
346
|
+ // KillProcess.Kill();
|
|
347
|
+ //}
|
315
|
348
|
myProcess = new Process();
|
316
|
349
|
LogPath = CreateffmpegLog();
|
317
|
350
|
this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
318
|
|
- myProcess.StartInfo.Arguments = "-f concat -safe 0 -i " + Path + "temp/filelist.d -c copy " + FilePath;
|
|
351
|
+ if (Extension.ToUpper() == ".MP3")
|
|
352
|
+ {
|
|
353
|
+ myProcess.StartInfo.Arguments = "-f concat -safe 0 -i " + Path + "temp/filelist.d -c copy " + FilePath;
|
|
354
|
+ }
|
|
355
|
+ else
|
|
356
|
+ {
|
|
357
|
+
|
|
358
|
+ myProcess.StartInfo.Arguments = "-f concat -safe 0 -i " + Path + "temprs/filelist.d -c copy " + FilePath;
|
|
359
|
+ }
|
319
|
360
|
myProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
|
320
|
361
|
myProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
|
321
|
362
|
myProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
|
|
@@ -341,11 +382,16 @@ namespace Common.system
|
341
|
382
|
}
|
342
|
383
|
#endregion
|
343
|
384
|
myProcess = null;
|
344
|
|
- FileToolsCommon.DeleteDirectory(Path + "temp/");
|
|
385
|
+ if (Extension.ToUpper() == ".MP3")
|
|
386
|
+ {
|
|
387
|
+ FileToolsCommon.DeleteDirectory(Path + "temp/");
|
|
388
|
+ }
|
|
389
|
+ else
|
|
390
|
+ FileToolsCommon.DeleteDirectory(Path + "temprs/");
|
345
|
391
|
}
|
346
|
392
|
|
347
|
393
|
/// <summary>
|
348
|
|
- /// 获取文件完整路径
|
|
394
|
+ /// 获取文件完整路径 音频
|
349
|
395
|
/// </summary>
|
350
|
396
|
/// <param name="FilePath">文件路径</param>
|
351
|
397
|
/// <returns></returns>
|
|
@@ -374,6 +420,35 @@ namespace Common.system
|
374
|
420
|
return CompleteFilePath;
|
375
|
421
|
}
|
376
|
422
|
|
|
423
|
+ /// <summary>
|
|
424
|
+ /// 获取文件完整路径 录屏
|
|
425
|
+ /// </summary>
|
|
426
|
+ /// <param name="FilePath">文件路径</param>
|
|
427
|
+ /// <returns></returns>
|
|
428
|
+ string GetRSFilePathName(string FilePath)
|
|
429
|
+ {
|
|
430
|
+ //路径
|
|
431
|
+ string Path = FileToolsCommon.GetDirectoryName(FilePath);
|
|
432
|
+ //Path.GetFileName(FilePath);//获取文件名
|
|
433
|
+ string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
|
|
434
|
+ string tempFilePath = Path + "temprs/";
|
|
435
|
+ //创建临时目录
|
|
436
|
+ FileToolsCommon.CreateDirectory(tempFilePath);
|
|
437
|
+ //创建记录文件
|
|
438
|
+ if (!FileToolsCommon.IsExistFile(tempFilePath + "filelist.d"))
|
|
439
|
+ {
|
|
440
|
+ FileToolsCommon.CreateFile(tempFilePath + "filelist.d");
|
|
441
|
+ }
|
|
442
|
+ int num = 1;
|
|
443
|
+ string CompleteFilePath = tempFilePath + num + Extension;
|
|
444
|
+ while (FileToolsCommon.IsExistFile(CompleteFilePath))
|
|
445
|
+ {
|
|
446
|
+ num++;
|
|
447
|
+ CompleteFilePath = tempFilePath + num + Extension;
|
|
448
|
+ }
|
|
449
|
+ FileToolsCommon.AppendText(tempFilePath + "filelist.d", "file ./" + num + Extension + "\r\n");
|
|
450
|
+ return CompleteFilePath;
|
|
451
|
+ }
|
377
|
452
|
/// <summary>
|
378
|
453
|
/// 生成缩略图
|
379
|
454
|
/// </summary>
|
|
@@ -381,45 +456,45 @@ namespace Common.system
|
381
|
456
|
/// <param name="ImagePath">图片地址</param>
|
382
|
457
|
public void GenerateThumbnails(string VideoPath, string ImagePath)
|
383
|
458
|
{
|
384
|
|
- while (myProcess != null)
|
|
459
|
+ while (myProcess != null)
|
|
460
|
+ {
|
|
461
|
+ Thread.Sleep(100);
|
|
462
|
+ }
|
|
463
|
+ Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
|
|
464
|
+ foreach (var KillProcess in KillProcessArray)
|
|
465
|
+ {
|
|
466
|
+ KillProcess.Kill();
|
|
467
|
+ }
|
|
468
|
+ myProcess = new Process();
|
|
469
|
+ LogPath = CreateffmpegLog();
|
|
470
|
+ this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
|
471
|
+ //myProcess.StartInfo.Arguments = "-i \"" + VideoPath + "\" -ss 1 -vframes 1 -r 1 -ac 1 -ab 2 -s " + thubWidth + "*" + thubHeight + " -f image2 \"" + ImagePath + "\"";
|
|
472
|
+ myProcess.StartInfo.Arguments = "-i \"" + VideoPath + "\" -ss 1 -vframes 1 -r 1 -ac 1 -ab 2 -f image2 \"" + ImagePath + "\"";
|
|
473
|
+ myProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
|
|
474
|
+ myProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
|
|
475
|
+ myProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
|
|
476
|
+ myProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
|
|
477
|
+ //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
|
|
478
|
+ myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
|
|
479
|
+ myProcess.Start(); //启动线程
|
|
480
|
+ myProcess.BeginErrorReadLine(); //开始异步读取
|
|
481
|
+ myProcess.WaitForExit(); //阻塞等待进程结束
|
|
482
|
+ myProcess.Close(); //关闭进程
|
|
483
|
+ myProcess.Dispose(); //释放资源
|
|
484
|
+ #region 进程是否已经释放
|
|
485
|
+ bool IsRunning = true;
|
|
486
|
+ while (IsRunning)
|
|
487
|
+ {
|
|
488
|
+ IsRunning = false;
|
|
489
|
+ Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
|
|
490
|
+ foreach (var KillProcess in ProcessArray)
|
385
|
491
|
{
|
|
492
|
+ IsRunning = true;
|
386
|
493
|
Thread.Sleep(100);
|
387
|
494
|
}
|
388
|
|
- Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
|
389
|
|
- foreach (var KillProcess in KillProcessArray)
|
390
|
|
- {
|
391
|
|
- KillProcess.Kill();
|
392
|
|
- }
|
393
|
|
- myProcess = new Process();
|
394
|
|
- LogPath = CreateffmpegLog();
|
395
|
|
- this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
396
|
|
- //myProcess.StartInfo.Arguments = "-i \"" + VideoPath + "\" -ss 1 -vframes 1 -r 1 -ac 1 -ab 2 -s " + thubWidth + "*" + thubHeight + " -f image2 \"" + ImagePath + "\"";
|
397
|
|
- myProcess.StartInfo.Arguments = "-i \"" + VideoPath + "\" -ss 1 -vframes 1 -r 1 -ac 1 -ab 2 -f image2 \"" + ImagePath + "\"";
|
398
|
|
- myProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
|
399
|
|
- myProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
|
400
|
|
- myProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
|
401
|
|
- myProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
|
402
|
|
- //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
|
403
|
|
- myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
|
404
|
|
- myProcess.Start(); //启动线程
|
405
|
|
- myProcess.BeginErrorReadLine(); //开始异步读取
|
406
|
|
- myProcess.WaitForExit(); //阻塞等待进程结束
|
407
|
|
- myProcess.Close(); //关闭进程
|
408
|
|
- myProcess.Dispose(); //释放资源
|
409
|
|
- #region 进程是否已经释放
|
410
|
|
- bool IsRunning = true;
|
411
|
|
- while (IsRunning)
|
412
|
|
- {
|
413
|
|
- IsRunning = false;
|
414
|
|
- Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
|
415
|
|
- foreach (var KillProcess in ProcessArray)
|
416
|
|
- {
|
417
|
|
- IsRunning = true;
|
418
|
|
- Thread.Sleep(100);
|
419
|
|
- }
|
420
|
|
- }
|
421
|
|
- #endregion
|
422
|
|
- myProcess = null;
|
|
495
|
+ }
|
|
496
|
+ #endregion
|
|
497
|
+ myProcess = null;
|
423
|
498
|
}
|
424
|
499
|
|
425
|
500
|
/// <summary>
|
|
@@ -555,6 +630,52 @@ namespace Common.system
|
555
|
630
|
return devs;
|
556
|
631
|
}
|
557
|
632
|
|
|
633
|
+ //录制麦克风的声音
|
|
634
|
+ WaveInEvent waveIn = null; //new WaveInEvent();
|
|
635
|
+ /// <summary>
|
|
636
|
+ /// 开始录制
|
|
637
|
+ /// </summary>
|
|
638
|
+ public bool StartRecordAudio(string audioFile)
|
|
639
|
+ {
|
|
640
|
+ try
|
|
641
|
+ {
|
|
642
|
+ waveIn = new WaveInEvent();
|
|
643
|
+ //生成音频文件的对象
|
|
644
|
+ WaveFileWriter writer = new WaveFileWriter(audioFile, waveIn.WaveFormat);
|
|
645
|
+ //开始录音,写数据
|
|
646
|
+ waveIn.DataAvailable += (s, a) =>
|
|
647
|
+ {
|
|
648
|
+ writer.Write(a.Buffer, 0, a.BytesRecorded);
|
|
649
|
+ };
|
|
650
|
+
|
|
651
|
+ //结束录音
|
|
652
|
+ waveIn.RecordingStopped += (s, a) =>
|
|
653
|
+ {
|
|
654
|
+ writer.Dispose();
|
|
655
|
+ writer = null;
|
|
656
|
+ waveIn.Dispose();
|
|
657
|
+ };
|
|
658
|
+ waveIn.StartRecording();
|
|
659
|
+ return true;
|
|
660
|
+ }
|
|
661
|
+ catch (Exception ex)
|
|
662
|
+ {
|
|
663
|
+ LogHelper.WriteErrLog("【麦克风】麦克风不可用:" + ex.Message, ex);
|
|
664
|
+ return false;
|
|
665
|
+ }
|
|
666
|
+ }
|
558
|
667
|
|
|
668
|
+ //结束录制
|
|
669
|
+ public void StopRecordAudio()
|
|
670
|
+ {
|
|
671
|
+ try
|
|
672
|
+ {
|
|
673
|
+ waveIn.StopRecording();
|
|
674
|
+ }
|
|
675
|
+ catch (Exception ex)
|
|
676
|
+ {
|
|
677
|
+ LogHelper.WriteErrLog("【麦克风】麦克风不可用:" + ex.Message, ex);
|
|
678
|
+ }
|
|
679
|
+ }
|
559
|
680
|
}
|
560
|
681
|
}
|