private void btnAV_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "mp4 File |*.mp4"; saveFileDialog1.Title = "Save High Resolution Video"; saveFileDialog1.ShowDialog(); if (saveFileDialog1.FileName != "") { disableControls(Controls); _mergeFileParam = new MergeAurgumentObj() { AudioFile = string.Format("{0}.audio-file-tmp", saveFileDialog1.FileName), VideoFile = string.Format("{0}.video-file-tmp", saveFileDialog1.FileName), Filename = saveFileDialog1.FileName }; _downloadHighResBg.RunWorkerAsync(new SaveFileArgumentObj() { FileName = saveFileDialog1.FileName }); } }
public void ConvertFileAsync(MergeAurgumentObj param) { // convert audio to aac if (txtResult.InvokeRequired) { txtResult.Invoke(new MethodInvoker(delegate { txtResult.Enabled = true; txtResult.ReadOnly = true; })); } var process = new Process { StartInfo = new ProcessStartInfo { FileName = string.Format("{0}\\ffmpeg\\ffmpeg.exe", Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)), Arguments = string.Format("-hide_banner -stats -i {0} -b:a 192K -vn {1}.aac", param.AudioFile, param.Filename), UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true }, EnableRaisingEvents = true }; process.Start(); string processOutput = null; while ((processOutput = process.StandardError.ReadLine()) != null) { if (txtResult.InvokeRequired) { txtResult.Invoke(new MethodInvoker(delegate { txtResult.Text += "\r\n" + processOutput; txtResult.SelectionStart = txtResult.Text.Length; txtResult.ScrollToCaret(); txtResult.Refresh(); })); } } _downloadHighResBg.ReportProgress(65); // convert video to mp4 process = null; process = new Process { StartInfo = new ProcessStartInfo { FileName = string.Format("{0}\\ffmpeg\\ffmpeg.exe", Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)), Arguments = string.Format("-hide_banner -stats -i {0} {1}.mp4", param.VideoFile, param.Filename), UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true }, EnableRaisingEvents = true }; process.Start(); processOutput = null; while ((processOutput = process.StandardError.ReadLine()) != null) { if (txtResult.InvokeRequired) { txtResult.Invoke(new MethodInvoker(delegate { txtResult.Text += "\r\n" + processOutput; txtResult.SelectionStart = txtResult.Text.Length; txtResult.ScrollToCaret(); txtResult.Refresh(); })); } } _downloadHighResBg.ReportProgress(80); // merge 2 files process = null; process = new Process { StartInfo = new ProcessStartInfo { FileName = string.Format("{0}\\ffmpeg\\ffmpeg.exe", Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)), Arguments = string.Format("-hide_banner -stats -i {0}.mp4 -i {1}.aac -c:v copy -map 0:v:0 -map 1:a:0 {2}", param.Filename, param.Filename, param.Filename), UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, RedirectStandardError = true, WindowStyle = ProcessWindowStyle.Hidden }, EnableRaisingEvents = true }; process.Start(); processOutput = null; while ((processOutput = process.StandardError.ReadLine()) != null) { if (txtResult.InvokeRequired) { txtResult.Invoke(new MethodInvoker(delegate { txtResult.Text += "\r\n" + processOutput; txtResult.SelectionStart = txtResult.Text.Length; txtResult.ScrollToCaret(); txtResult.Refresh(); })); } } _downloadHighResBg.ReportProgress(95); //clean up File.Delete(param.AudioFile); File.Delete(param.VideoFile); File.Delete(string.Format("{0}.aac", param.Filename)); File.Delete(string.Format("{0}.mp4", param.Filename)); _downloadHighResBg.ReportProgress(100); process = new Process() { StartInfo = { FileName = "explorer.exe", Arguments = Path.GetDirectoryName(param.Filename), WindowStyle = ProcessWindowStyle.Normal, CreateNoWindow = true, } }; process.Start(); }