private void btnStart_Click(object sender, EventArgs e) { if (m_NeedToStopAll) { return; } if (ckbAutoRestart.Enabled && !ckbAutoRestart.Checked) { if (MessageBox.Show("Do you want to enable 'auto-restart' at the same time ?", this.Text, MessageBoxButtons.YesNo) == DialogResult.Yes) { ckbAutoRestart.Checked = true; } } List <string> input = new List <string>(); string outputVideo = ""; string outputAudio = ""; input = GenInputPart(); if (input.Count <= 0) { return; } outputVideo = CommandGenerator.GenVideoOutputPart(m_VideoOutputTaskGroup.Tasks); outputAudio = CommandGenerator.GenAudioOutputPart(m_AudioOutputTaskGroup.Tasks, m_EncoderAAC); if (outputVideo.Length <= 0 && outputAudio.Length <= 0) { return; } if (input.Count <= 1) { m_VideoArgs = input[0] + " " + outputVideo + " " + outputAudio; m_AudioArgs = ""; } else { var mpegItemCount = 0; foreach (var taskItem in m_VideoOutputTaskGroup.Tasks) { if (taskItem.VideoType == "mpeg") { mpegItemCount++; } } if (mpegItemCount > 0 && mpegItemCount == m_VideoOutputTaskGroup.Tasks.Count) { m_VideoArgs = input[0] + " " + input[1] + " " + outputVideo; } else { m_VideoArgs = outputVideo.Trim().Length <= 0 ? "" : (input[0].Trim().Length > 0 ? input[0] + " " + outputVideo : ""); } m_AudioArgs = outputAudio.Trim().Length <= 0 ? "" : (input[1].Trim().Length > 0 ? input[1] + " " + outputAudio : ""); } m_VideoArgs = m_VideoArgs.Trim(); m_AudioArgs = m_AudioArgs.Trim(); //MessageBox.Show(args); Console.WriteLine(m_VideoArgs); Console.WriteLine(m_AudioArgs); gbMediaSource.Enabled = false; gbVideoTask.Enabled = false; gbAudioTask.Enabled = false; btnStart.Enabled = false; m_UpdatedUI4Start = false; try { StopRunningProcesses(); mmVideoLogger.Clear(); mmAudioLogger.Clear(); if (m_VideoArgs.Length > 0) { if (m_VideoArgs.Contains("-f nut pipe:1")) { // in this case, Process.Kill() will just kill "cmd", but not "ffmpeg" ... m_VideoProcess = new ProcessIoWrapper("cmd", "/C ffmpeg " + m_VideoArgs, ProcessIoWrapper.FLAG_INPUT | ProcessIoWrapper.FLAG_ERROR); } else { m_VideoProcess = new ProcessIoWrapper("ffmpeg", m_VideoArgs, ProcessIoWrapper.FLAG_INPUT | ProcessIoWrapper.FLAG_ERROR); } m_LastVideoTime = DateTime.Now; //m_ProcessIoWrapper.OnStandardOutputTextRead = new Action<string>((text) => { OnStderrTextRead(text); }); m_VideoProcess.OnStandardErrorTextRead = new Action <string>((text) => { OnVideoStderrTextRead(text); }); m_VideoProcess.OnProcessExited = new Action(() => { OnVideoProcessExited(); }); m_VideoProcess.StartProcess(); } if (m_AudioArgs.Length > 0) { if (m_AudioArgs.Contains("-f nut pipe:1")) { // in this case, Process.Kill() will just kill "cmd", but not "ffmpeg" ... m_AudioProcess = new ProcessIoWrapper("cmd", "/C ffmpeg " + m_AudioArgs, ProcessIoWrapper.FLAG_INPUT | ProcessIoWrapper.FLAG_ERROR); } else { m_AudioProcess = new ProcessIoWrapper("ffmpeg", m_AudioArgs, ProcessIoWrapper.FLAG_INPUT | ProcessIoWrapper.FLAG_ERROR); } m_LastAudioTime = DateTime.Now; //m_ProcessIoWrapper.OnStandardOutputTextRead = new Action<string>((text) => { OnStderrTextRead(text); }); m_AudioProcess.OnStandardErrorTextRead = new Action <string>((text) => { OnAudioStderrTextRead(text); }); m_AudioProcess.OnProcessExited = new Action(() => { OnAudioProcessExited(); }); m_AudioProcess.StartProcess(); } btnStop.Enabled = true; notifyIconMain.Icon = notifyIconStart.Icon; notifyIconMain.Text = this.Text + " (" + notifyIconStart.Text + ")"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); m_UpdatedUI4Start = true; gbMediaSource.Enabled = true; gbVideoTask.Enabled = true; gbAudioTask.Enabled = true; btnStart.Enabled = true; } }
public List <string> GenInputPart() { List <string> inputList = new List <string>(); if (rbtnFromDevice.Checked) { if (cbbCams.SelectedIndex < 0 && cbbMics.SelectedIndex < 0) { MessageBox.Show("Please select a device."); return(inputList); } else { string videoDevice = (cbbCams.Visible && cbbCams.Enabled && cbbCams.SelectedIndex >= 0) ? cbbCams.Items[cbbCams.SelectedIndex].ToString() : ""; string audioDevice = (cbbMics.Visible && cbbMics.Enabled && cbbMics.SelectedIndex >= 0) ? cbbMics.Items[cbbMics.SelectedIndex].ToString() : ""; string videoOptions = (videoDevice.Length > 0 && edtVideoOption.Enabled) ? edtVideoOption.Text : ""; string audioOptions = (audioDevice.Length > 0 && edtAudioOption.Enabled) ? edtAudioOption.Text : ""; //input = CommandGenerator.GenInputPart(videoDevice, audioDevice, videoOptions, audioOptions); var videoInput = CommandGenerator.GenInputPart(videoDevice, "", videoOptions, ""); var audioInput = CommandGenerator.GenInputPart("", audioDevice, "", audioOptions); inputList.Add(videoInput.Trim()); inputList.Add(audioInput.Trim()); } } if (rbtnFromUrl.Checked) { if (edtVideoUrlSource.Text.Trim().Length <= 0 && edtAudioUrlSource.Text.Trim().Length <= 0) { MessageBox.Show("Please input the URL source."); return(inputList); } else { if (edtVideoUrlSource.Text.Trim().Length > 0) { var input = CommandGenerator.GenInputPart(edtVideoUrlSource.Text.Trim()); inputList.Add(input.Trim()); } else { inputList.Add(""); } if (edtAudioUrlSource.Text.Trim().Length > 0) { var input = CommandGenerator.GenInputPart(edtAudioUrlSource.Text.Trim()); inputList.Add(input.Trim()); } } } return(inputList); }