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 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; } }