Browse Source

zhao:1优化日志,完善ffmpeg日志。2解决部分播放器无法解码播放录屏

tags/录制修改前
耀 4 years ago
parent
commit
2bb492128a
1 changed files with 35 additions and 27 deletions
  1. 35
    27
      Common/system/FFMpeg.cs

+ 35
- 27
Common/system/FFMpeg.cs View File

116
             switch (Extension.ToUpper())
116
             switch (Extension.ToUpper())
117
             {
117
             {
118
                 case ".MP4":
118
                 case ".MP4":
119
-                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
119
+                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f gdigrab -i desktop -pix_fmt yuv420p -vf scale=trunc(iw/2)*2:trunc(ih/2)*2 -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
120
                     //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;
120
                     //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;
121
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
121
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
122
                     //{
122
                     //{
130
                     break;
130
                     break;
131
                 case ".AVI":
131
                 case ".AVI":
132
                 case ".FLV":
132
                 case ".FLV":
133
-                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac -f " + Extension.ToLower().Replace(".", "") + " " + PathName;
133
+                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f gdigrab -i desktop -pix_fmt yuv420p -vf scale=trunc(iw/2)*2:trunc(ih/2)*2 -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac -f " + Extension.ToLower().Replace(".", "") + " " + PathName;
134
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
134
                     //if (string.IsNullOrWhiteSpace(MicrophoneName))
135
                     //{
135
                     //{
136
                     //    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的参数
136
                     //    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的参数
142
                     //}
142
                     //}
143
                     break;
143
                     break;
144
                 default:
144
                 default:
145
-                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
145
+                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f gdigrab -i desktop -pix_fmt yuv420p -vf scale=trunc(iw/2)*2:trunc(ih/2)*2 -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
146
                     break;
146
                     break;
147
             }
147
             }
148
             if (OutputVideoLog)
148
             if (OutputVideoLog)
149
             {
149
             {
150
                 LogHelper.WriteInfoLog("【录屏】:" + myProcess.StartInfo.Arguments);
150
                 LogHelper.WriteInfoLog("【录屏】:" + myProcess.StartInfo.Arguments);
151
             }
151
             }
152
+            FileToolsCommon.AppendText(LogPath, "【录屏】:" + myProcess.StartInfo.Arguments + "\r\n");
152
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
153
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
153
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
154
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
154
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
155
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
222
             myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
223
             myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
223
             if (IsRecordSpeaker && IsRecordMicrophone)
224
             if (IsRecordSpeaker && IsRecordMicrophone)
224
             {
225
             {
225
-                myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\"  -f dshow -i audio=\"" +
226
+                myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
226
                         MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 " + PathName;
227
                         MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 " + PathName;
227
             }
228
             }
228
             else if (IsRecordSpeaker)
229
             else if (IsRecordSpeaker)
240
             }
241
             }
241
             if (OutputVideoLog)
242
             if (OutputVideoLog)
242
                 LogHelper.WriteInfoLog("【录音】:" + myProcess.StartInfo.Arguments);
243
                 LogHelper.WriteInfoLog("【录音】:" + myProcess.StartInfo.Arguments);
244
+            FileToolsCommon.AppendText(LogPath, "【录音】:" + myProcess.StartInfo.Arguments + "\r\n");
243
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
245
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
244
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
246
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
245
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
247
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
384
                 }
386
                 }
385
                 if (OutputVideoLog)
387
                 if (OutputVideoLog)
386
                     LogHelper.WriteInfoLog("【图片音频合成视频】:" + myProcess.StartInfo.Arguments);
388
                     LogHelper.WriteInfoLog("【图片音频合成视频】:" + myProcess.StartInfo.Arguments);
389
+                FileToolsCommon.AppendText(LogPath, "【图片音频合成视频】:" + myProcess.StartInfo.Arguments + "\r\n");
387
                 myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
390
                 myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
388
                 myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
391
                 myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
389
                 myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
392
                 myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
486
             }
489
             }
487
             if (OutputVideoLog)
490
             if (OutputVideoLog)
488
                 LogHelper.WriteInfoLog("【音视频合成】:" + myProcess.StartInfo.Arguments);
491
                 LogHelper.WriteInfoLog("【音视频合成】:" + myProcess.StartInfo.Arguments);
492
+            FileToolsCommon.AppendText(LogPath, "【音视频合成】:" + myProcess.StartInfo.Arguments + "\r\n");
489
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
493
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
490
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
494
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
491
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
495
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
613
 
617
 
614
                 if (OutputVideoLog)
618
                 if (OutputVideoLog)
615
                     LogHelper.WriteInfoLog("【生成缩略图】:" + myProcess.StartInfo.Arguments);
619
                     LogHelper.WriteInfoLog("【生成缩略图】:" + myProcess.StartInfo.Arguments);
620
+                FileToolsCommon.AppendText(LogPath, "【生成缩略图】:" + myProcess.StartInfo.Arguments + "\r\n");
616
                 myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
621
                 myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
617
                 myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
622
                 myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
618
                 myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
623
                 myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
674
 
679
 
675
                 if (OutputVideoLog)
680
                 if (OutputVideoLog)
676
                     LogHelper.WriteInfoLog("【视频转码】:" + myProcess.StartInfo.Arguments);
681
                     LogHelper.WriteInfoLog("【视频转码】:" + myProcess.StartInfo.Arguments);
682
+                FileToolsCommon.AppendText(LogPath,"【视频转码】:" + myProcess.StartInfo.Arguments + "\r\n");
677
                 myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
683
                 myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
678
                 myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
684
                 myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
679
                 myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
685
                 myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
758
         {
764
         {
759
             if (!string.IsNullOrEmpty(output.Data))
765
             if (!string.IsNullOrEmpty(output.Data))
760
             {
766
             {
761
-                FileToolsCommon.AppendText(LogPath, output.Data);
767
+                FileToolsCommon.AppendText(LogPath, "【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff") +"】:");
768
+                FileToolsCommon.AppendText(LogPath, output.Data+"\r\n");
762
             }
769
             }
763
         }
770
         }
764
         #region 麦克风声卡检测
771
         #region 麦克风声卡检测
822
                 try
829
                 try
823
                 {
830
                 {
824
 
831
 
825
-                while (myProcess != null)
826
-                {
827
-                    Thread.Sleep(100);
828
-                }
829
-                myProcess = new Process();
830
-                LogPath = CreateffmpegLog();
831
-                myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
832
-                myProcess.StartInfo.Arguments = " -list_devices true -f dshow -i dummy";
833
-                if (OutputVideoLog)
834
-                    LogHelper.WriteInfoLog("【音视频合成】:" + myProcess.StartInfo.Arguments);
835
-                myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
836
-                myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
837
-                myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
838
-                myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
839
-                                                                       //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
840
-                myProcess.ErrorDataReceived += GetDevInfoData;
841
-                myProcess.Start();                 //启动线程
842
-                myProcess.BeginErrorReadLine();    //开始异步读取
843
-                myProcess.WaitForExit();           //阻塞等待进程结束
844
-                myProcess.Close();                 //关闭进程
845
-                myProcess.Dispose();               //释放资源
846
-                myProcess = null;
832
+                    while (myProcess != null)
833
+                    {
834
+                        Thread.Sleep(100);
835
+                    }
836
+                    myProcess = new Process();
837
+                    LogPath = CreateffmpegLog();
838
+                    myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
839
+                    myProcess.StartInfo.Arguments = " -list_devices true -f dshow -i dummy";
840
+                    if (OutputVideoLog)
841
+                        LogHelper.WriteInfoLog("【获取设备信息】:" + myProcess.StartInfo.Arguments);
842
+                    FileToolsCommon.AppendText(LogPath, "【获取设备信息】:" + myProcess.StartInfo.Arguments + "\r\n");
843
+                    myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
844
+                    myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
845
+                    myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
846
+                    myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
847
+                                                                           //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
848
+                    myProcess.ErrorDataReceived += GetDevInfoData;
849
+                    myProcess.Start();                 //启动线程
850
+                    myProcess.BeginErrorReadLine();    //开始异步读取
851
+                    myProcess.WaitForExit();           //阻塞等待进程结束
852
+                    myProcess.Close();                 //关闭进程
853
+                    myProcess.Dispose();               //释放资源
854
+                    myProcess = null;
847
                 }
855
                 }
848
                 catch (Exception ex)
856
                 catch (Exception ex)
849
                 {
857
                 {

Loading…
Cancel
Save