private void buttonOK_Click(object sender, EventArgs e) { buttonOK.Enabled = false; var fileName = radioButtonColor.Checked ? "blank_video_solid" : "blank_video_checkered"; using (var saveDialog = new SaveFileDialog { FileName = fileName, Filter = "Matroska|*.mkv" }) { if (saveDialog.ShowDialog(this) != DialogResult.OK) { return; } VideoFileName = saveDialog.FileName; } if (File.Exists(VideoFileName)) { File.Delete(VideoFileName); } progressBar1.Style = ProgressBarStyle.Marquee; progressBar1.Visible = true; labelPleaseWait.Visible = true; var process = VideoPreviewGenerator.GenerateVideoFile( VideoFileName, (int)Math.Round(numericUpDownDurationMinutes.Value * 60), (int)numericUpDownWidth.Value, (int)numericUpDownHeight.Value, panelColor.BackColor, radioButtonCheckeredImage.Checked, decimal.Parse(comboBoxFrameRate.Text) ); process.Start(); while (!process.HasExited) { System.Threading.Thread.Sleep(100); Application.DoEvents(); if (_abort) { process.Kill(); } } progressBar1.Visible = false; labelPleaseWait.Visible = false; DialogResult = _abort ? DialogResult.Cancel : DialogResult.OK; }
private void buttonPreview_Click(object sender, EventArgs e) { try { buttonPreview.Enabled = false; labelPreviewPleaseWait.Visible = true; Cursor = Cursors.WaitCursor; // generate blank video var tempVideoFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".mkv"); var process = VideoPreviewGenerator.GenerateVideoFile( tempVideoFileName, 2, (int)numericUpDownWidth.Value, (int)numericUpDownHeight.Value, Color.Black, true, 25, null); process.Start(); while (!process.HasExited) { System.Threading.Thread.Sleep(100); Application.DoEvents(); } // make temp assa file with font var assaTempFileName = GetAssaFileName(tempVideoFileName); var sub = new Subtitle(); sub.Header = _assaSubtitle.Header; sub.Paragraphs.Add(new Paragraph(GetPreviewParagraph())); if (!_isAssa) { SetStyleForNonAssa(sub); } FixRightToLeft(sub); FileUtil.WriteAllText(assaTempFileName, new AdvancedSubStationAlpha().ToText(sub, string.Empty), new TextEncoding(Encoding.UTF8, "UTF8")); // hardcode subtitle var outputVideoFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".mp4"); process = GetFfmpegProcess(tempVideoFileName, outputVideoFileName, assaTempFileName); process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); while (!process.HasExited) { System.Threading.Thread.Sleep(100); Application.DoEvents(); } string bmpFileName; try { bmpFileName = VideoPreviewGenerator.GetScreenShot(outputVideoFileName, "00:00:01"); using (var bmp = new Bitmap(bmpFileName)) { using (var form = new ExportPngXmlPreview(bmp)) { form.AllowNext = false; form.AllowPrevious = false; labelPreviewPleaseWait.Visible = false; form.ShowDialog(this); } } } catch { if (comboBoxVideoEncoding.Text.EndsWith("_amf")) { MessageBox.Show("Unable to generate video with AMD hardware acceleration!"); } else if (comboBoxVideoEncoding.Text.EndsWith("_nvenc")) { MessageBox.Show("Unable to generate video with Nvidia hardware acceleration!"); } else { MessageBox.Show("Unable to generate video!"); } Cursor = Cursors.Default; buttonPreview.Enabled = true; labelPreviewPleaseWait.Visible = false; return; } try { File.Delete(tempVideoFileName); File.Delete(assaTempFileName); File.Delete(outputVideoFileName); File.Delete(bmpFileName); } catch { // ignore } } finally { Cursor = Cursors.Default; buttonPreview.Enabled = true; labelPreviewPleaseWait.Visible = false; } }
private void buttonOK_Click(object sender, EventArgs e) { EnableDisableControls(false); var fileName = radioButtonColor.Checked ? "blank_video_solid" : (radioButtonCheckeredImage.Checked ? "blank_video_checkered" : "blank_video_image"); using (var saveDialog = new SaveFileDialog { FileName = fileName, Filter = "MP4|*.mp4|Matroska|*.mkv|WebM|*.webm" }) { if (saveDialog.ShowDialog(this) != DialogResult.OK) { EnableDisableControls(true); return; } VideoFileName = saveDialog.FileName; } if (File.Exists(VideoFileName)) { File.Delete(VideoFileName); } progressBar1.Visible = true; labelPleaseWait.Visible = true; var process = VideoPreviewGenerator.GenerateVideoFile( VideoFileName, (int)Math.Round(numericUpDownDurationMinutes.Value * 60), (int)numericUpDownWidth.Value, (int)numericUpDownHeight.Value, panelColor.BackColor, radioButtonCheckeredImage.Checked, decimal.Parse(comboBoxFrameRate.Text), radioButtonImage.Checked ? _backgroundImage : null, OutputHandler); process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); _totalFrames = (long)Math.Round(float.Parse(comboBoxFrameRate.Text, CultureInfo.CurrentCulture) * (float)numericUpDownDurationMinutes.Value * 60.0f); progressBar1.Maximum = (int)_totalFrames; _startTicks = DateTime.UtcNow.Ticks; timer1.Start(); while (!process.HasExited) { var v = (int)_processedFrames; if (v >= progressBar1.Minimum && v <= progressBar1.Maximum) { progressBar1.Value = v; } System.Threading.Thread.Sleep(100); Application.DoEvents(); if (_abort) { process.Kill(); } } progressBar1.Visible = false; labelPleaseWait.Visible = false; timer1.Stop(); labelProgress.Text = string.Empty; DialogResult = _abort ? DialogResult.Cancel : DialogResult.OK; }
private void buttonPreview_Click(object sender, EventArgs e) { try { buttonPreview.Enabled = false; labelPreviewPleaseWait.Visible = true; Cursor = Cursors.WaitCursor; // generate blank video var tempVideoFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".mkv"); var process = VideoPreviewGenerator.GenerateVideoFile( tempVideoFileName, 2, (int)numericUpDownWidth.Value, (int)numericUpDownHeight.Value, Color.Black, true, 25); process.Start(); while (!process.HasExited) { System.Threading.Thread.Sleep(100); Application.DoEvents(); } // make temp assa file with font var assaTempFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".ass"); var sub = new Subtitle(); sub.Header = _assaSubtitle.Header; sub.Paragraphs.Add(new Paragraph(GetPreviewText(), 0, 10_000)); if (numericUpDownFontSize.Visible) // not ASSA format { SetStyleForNonAssa(sub); } FixRightToLeft(sub); File.WriteAllText(assaTempFileName, new AdvancedSubStationAlpha().ToText(sub, string.Empty)); // hardcode subtitle var outputVideoFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".mp4"); process = GetFfmpegProcess(tempVideoFileName, outputVideoFileName, assaTempFileName); process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); while (!process.HasExited) { System.Threading.Thread.Sleep(100); Application.DoEvents(); } Cursor = Cursors.Default; var bmpFileName = VideoPreviewGenerator.GetScreenShot(outputVideoFileName, "00:00:01"); using (var bmp = new Bitmap(bmpFileName)) { using (var form = new ExportPngXmlPreview(bmp)) { form.AllowNext = false; form.AllowPrevious = false; labelPreviewPleaseWait.Visible = false; form.ShowDialog(this); } } try { File.Delete(tempVideoFileName); File.Delete(assaTempFileName); File.Delete(outputVideoFileName); File.Delete(bmpFileName); } catch { // ignore } } finally { Cursor = Cursors.Default; buttonPreview.Enabled = true; labelPreviewPleaseWait.Visible = false; } }