|
@@ -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;
|
|
@@ -277,7 +307,7 @@ namespace Common.system
|
277
|
307
|
//生成视频后删除图片和音频保存列表
|
278
|
308
|
//FileToolsCommon.DeleteDirectory(ImageListPath);
|
279
|
309
|
//FileToolsCommon.DeleteDirectory(FileToolsCommon.GetDirectoryName(Mp3Path));
|
280
|
|
- FileToolsCommon.DeleteDirectory(FileToolsCommon.GetDirectoryName(VideoSavePath) + "temp/");
|
|
310
|
+ FileToolsCommon.DeleteDirectory(FileToolsCommon.GetDirectoryName(VideoSavePath) + "temp");
|
281
|
311
|
|
282
|
312
|
//Dispatcher.Invoke(() =>
|
283
|
313
|
//{
|
|
@@ -307,6 +337,7 @@ namespace Common.system
|
307
|
337
|
//路径
|
308
|
338
|
string FilePath = (string)FilePathobj;
|
309
|
339
|
string Path = FileToolsCommon.GetDirectoryName(FilePath);
|
|
340
|
+ string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
|
310
|
341
|
Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
|
311
|
342
|
foreach (var KillProcess in KillProcessArray)
|
312
|
343
|
{
|
|
@@ -315,7 +346,15 @@ namespace Common.system
|
315
|
346
|
myProcess = new Process();
|
316
|
347
|
LogPath = CreateffmpegLog();
|
317
|
348
|
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;
|
|
349
|
+ if (Extension.ToUpper() == ".MP3")
|
|
350
|
+ {
|
|
351
|
+ myProcess.StartInfo.Arguments = "-f concat -safe 0 -i " + Path + "temp/filelist.d -c copy " + FilePath;
|
|
352
|
+ }
|
|
353
|
+ else
|
|
354
|
+ {
|
|
355
|
+
|
|
356
|
+ myProcess.StartInfo.Arguments = "-f concat -safe 0 -i " + Path + "temprs/filelist.d -c copy " + FilePath;
|
|
357
|
+ }
|
319
|
358
|
myProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
|
320
|
359
|
myProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
|
321
|
360
|
myProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
|
|
@@ -341,11 +380,14 @@ namespace Common.system
|
341
|
380
|
}
|
342
|
381
|
#endregion
|
343
|
382
|
myProcess = null;
|
344
|
|
- FileToolsCommon.DeleteDirectory(Path + "temp/");
|
|
383
|
+ if (Extension.ToUpper() == ".MP3")
|
|
384
|
+ FileToolsCommon.DeleteDirectory(Path + "temp/");
|
|
385
|
+ else
|
|
386
|
+ FileToolsCommon.DeleteDirectory(Path + "temprs/");
|
345
|
387
|
}
|
346
|
388
|
|
347
|
389
|
/// <summary>
|
348
|
|
- /// 获取文件完整路径
|
|
390
|
+ /// 获取文件完整路径 音频
|
349
|
391
|
/// </summary>
|
350
|
392
|
/// <param name="FilePath">文件路径</param>
|
351
|
393
|
/// <returns></returns>
|
|
@@ -374,6 +416,35 @@ namespace Common.system
|
374
|
416
|
return CompleteFilePath;
|
375
|
417
|
}
|
376
|
418
|
|
|
419
|
+ /// <summary>
|
|
420
|
+ /// 获取文件完整路径 录屏
|
|
421
|
+ /// </summary>
|
|
422
|
+ /// <param name="FilePath">文件路径</param>
|
|
423
|
+ /// <returns></returns>
|
|
424
|
+ string GetRSFilePathName(string FilePath)
|
|
425
|
+ {
|
|
426
|
+ //路径
|
|
427
|
+ string Path = FileToolsCommon.GetDirectoryName(FilePath);
|
|
428
|
+ //Path.GetFileName(FilePath);//获取文件名
|
|
429
|
+ string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
|
|
430
|
+ string tempFilePath = Path + "temprs/";
|
|
431
|
+ //创建临时目录
|
|
432
|
+ FileToolsCommon.CreateDirectory(tempFilePath);
|
|
433
|
+ //创建记录文件
|
|
434
|
+ if (!FileToolsCommon.IsExistFile(tempFilePath + "filelist.d"))
|
|
435
|
+ {
|
|
436
|
+ FileToolsCommon.CreateFile(tempFilePath + "filelist.d");
|
|
437
|
+ }
|
|
438
|
+ int num = 1;
|
|
439
|
+ string CompleteFilePath = tempFilePath + num + Extension;
|
|
440
|
+ while (FileToolsCommon.IsExistFile(CompleteFilePath))
|
|
441
|
+ {
|
|
442
|
+ num++;
|
|
443
|
+ CompleteFilePath = tempFilePath + num + Extension;
|
|
444
|
+ }
|
|
445
|
+ FileToolsCommon.AppendText(tempFilePath + "filelist.d", "file ./" + num + Extension + "\r\n");
|
|
446
|
+ return CompleteFilePath;
|
|
447
|
+ }
|
377
|
448
|
/// <summary>
|
378
|
449
|
/// 生成缩略图
|
379
|
450
|
/// </summary>
|
|
@@ -381,45 +452,45 @@ namespace Common.system
|
381
|
452
|
/// <param name="ImagePath">图片地址</param>
|
382
|
453
|
public void GenerateThumbnails(string VideoPath, string ImagePath)
|
383
|
454
|
{
|
384
|
|
- while (myProcess != null)
|
|
455
|
+ while (myProcess != null)
|
|
456
|
+ {
|
|
457
|
+ Thread.Sleep(100);
|
|
458
|
+ }
|
|
459
|
+ Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
|
|
460
|
+ foreach (var KillProcess in KillProcessArray)
|
|
461
|
+ {
|
|
462
|
+ KillProcess.Kill();
|
|
463
|
+ }
|
|
464
|
+ myProcess = new Process();
|
|
465
|
+ LogPath = CreateffmpegLog();
|
|
466
|
+ this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe"); //ffmpeg.exe的绝对路径
|
|
467
|
+ //myProcess.StartInfo.Arguments = "-i \"" + VideoPath + "\" -ss 1 -vframes 1 -r 1 -ac 1 -ab 2 -s " + thubWidth + "*" + thubHeight + " -f image2 \"" + ImagePath + "\"";
|
|
468
|
+ myProcess.StartInfo.Arguments = "-i \"" + VideoPath + "\" -ss 1 -vframes 1 -r 1 -ac 1 -ab 2 -f image2 \"" + ImagePath + "\"";
|
|
469
|
+ myProcess.StartInfo.UseShellExecute = false; //不使用操作系统外壳程序启动
|
|
470
|
+ myProcess.StartInfo.RedirectStandardError = true; //重定向标准错误输出
|
|
471
|
+ myProcess.StartInfo.CreateNoWindow = true; //不显示程序窗口
|
|
472
|
+ myProcess.StartInfo.RedirectStandardInput = true; //用于模拟该进程控制台的输入
|
|
473
|
+ //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
|
|
474
|
+ myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
|
|
475
|
+ myProcess.Start(); //启动线程
|
|
476
|
+ myProcess.BeginErrorReadLine(); //开始异步读取
|
|
477
|
+ myProcess.WaitForExit(); //阻塞等待进程结束
|
|
478
|
+ myProcess.Close(); //关闭进程
|
|
479
|
+ myProcess.Dispose(); //释放资源
|
|
480
|
+ #region 进程是否已经释放
|
|
481
|
+ bool IsRunning = true;
|
|
482
|
+ while (IsRunning)
|
|
483
|
+ {
|
|
484
|
+ IsRunning = false;
|
|
485
|
+ Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
|
|
486
|
+ foreach (var KillProcess in ProcessArray)
|
385
|
487
|
{
|
|
488
|
+ IsRunning = true;
|
386
|
489
|
Thread.Sleep(100);
|
387
|
490
|
}
|
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;
|
|
491
|
+ }
|
|
492
|
+ #endregion
|
|
493
|
+ myProcess = null;
|
423
|
494
|
}
|
424
|
495
|
|
425
|
496
|
/// <summary>
|
|
@@ -555,6 +626,52 @@ namespace Common.system
|
555
|
626
|
return devs;
|
556
|
627
|
}
|
557
|
628
|
|
|
629
|
+ //录制麦克风的声音
|
|
630
|
+ WaveInEvent waveIn = null; //new WaveInEvent();
|
|
631
|
+ /// <summary>
|
|
632
|
+ /// 开始录制
|
|
633
|
+ /// </summary>
|
|
634
|
+ public bool StartRecordAudio(string audioFile)
|
|
635
|
+ {
|
|
636
|
+ try
|
|
637
|
+ {
|
|
638
|
+ waveIn = new WaveInEvent();
|
|
639
|
+ //生成音频文件的对象
|
|
640
|
+ WaveFileWriter writer = new WaveFileWriter(audioFile, waveIn.WaveFormat);
|
|
641
|
+ //开始录音,写数据
|
|
642
|
+ waveIn.DataAvailable += (s, a) =>
|
|
643
|
+ {
|
|
644
|
+ writer.Write(a.Buffer, 0, a.BytesRecorded);
|
|
645
|
+ };
|
|
646
|
+
|
|
647
|
+ //结束录音
|
|
648
|
+ waveIn.RecordingStopped += (s, a) =>
|
|
649
|
+ {
|
|
650
|
+ writer.Dispose();
|
|
651
|
+ writer = null;
|
|
652
|
+ waveIn.Dispose();
|
|
653
|
+ };
|
|
654
|
+ waveIn.StartRecording();
|
|
655
|
+ return true;
|
|
656
|
+ }
|
|
657
|
+ catch (Exception ex)
|
|
658
|
+ {
|
|
659
|
+ LogHelper.WriteErrLog("【麦克风】麦克风不可用:" + ex.Message, ex);
|
|
660
|
+ return false;
|
|
661
|
+ }
|
|
662
|
+ }
|
558
|
663
|
|
|
664
|
+ //结束录制
|
|
665
|
+ public void StopRecordAudio()
|
|
666
|
+ {
|
|
667
|
+ try
|
|
668
|
+ {
|
|
669
|
+ waveIn.StopRecording();
|
|
670
|
+ }
|
|
671
|
+ catch (Exception ex)
|
|
672
|
+ {
|
|
673
|
+ LogHelper.WriteErrLog("【麦克风】麦克风不可用:" + ex.Message, ex);
|
|
674
|
+ }
|
|
675
|
+ }
|
559
|
676
|
}
|
560
|
677
|
}
|