private void buttonStart_Click(object sender, EventArgs e) { radioButtonBluRaySup.Enabled = false; buttonStart.Enabled = false; var cdgToImageList = new CdgToImageList(); int total = (int)Math.Round(_cdgGraphics.DurationInMilliseconds / CdgGraphics.TimeMsFactor); var bw = new BackgroundWorker { WorkerReportsProgress = true }; bw.DoWork += (o, args) => { _imageList = cdgToImageList.MakeImageList(_cdgGraphics, _subtitle, (number, unique) => { bw.ReportProgress(number, unique); }); }; bw.RunWorkerCompleted += (o, args) => { using (var exportBdnXmlPng = new ExportPngXml()) { var old = Configuration.Settings.Tools.ExportBluRayRemoveSmallGaps; Configuration.Settings.Tools.ExportBluRayRemoveSmallGaps = false; // Hm, not really sure if a 'true' is needed here - seems to give a small blink once in a while!? exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), ExportPngXml.ExportFormats.BluraySup, FileName, this, "Test123"); exportBdnXmlPng.ShowDialog(this); Configuration.Settings.Tools.ExportBluRayRemoveSmallGaps = old; DialogResult = DialogResult.OK; } }; bw.ProgressChanged += (o, args) => { labelProgress.Text = $"Frame {args.ProgressPercentage:#,###,##0} of {total:#,###,##0}"; labelProgress.Refresh(); labelProgress2.Text = $"Unique images {(int)args.UserState:#,###,##0}"; labelProgress2.Refresh(); }; bw.RunWorkerAsync(); }
private void buttonStart_Click(object sender, EventArgs e) { var finalMkv = string.Empty; if (radioButtonVideo.Checked) { if (string.IsNullOrEmpty(_audioFileName) || !File.Exists(_audioFileName)) { MessageBox.Show("Please select an audio file!"); return; } if (_originalBackgroundImage == null) { MessageBox.Show("Please select a background image file!"); return; } if (Configuration.IsRunningOnWindows && (string.IsNullOrEmpty(textBoxFFmpegPath.Text) || !File.Exists(textBoxFFmpegPath.Text))) { MessageBox.Show("mkvmerge.exe not found!"); return; } if (Configuration.IsRunningOnWindows && (string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) || !File.Exists(Configuration.Settings.General.FFmpegLocation))) { MessageBox.Show("ffmpeg not configured!"); return; } saveFileDialog1.Filter = "Matroska (*.mkv)|*.mkv"; saveFileDialog1.FileName = FileName.Substring(0, FileName.Length - 3) + "mkv"; if (saveFileDialog1.ShowDialog(this) != DialogResult.OK) { return; } finalMkv = saveFileDialog1.FileName; } radioButtonBluRaySup.Enabled = false; radioButtonVideo.Enabled = false; buttonStart.Enabled = false; var cdgToImageList = new CdgToImageList(); var bw = new BackgroundWorker { WorkerReportsProgress = true }; bw.DoWork += (o, args) => { _imageList = cdgToImageList.MakeImageList(_cdgGraphics, _subtitle, (number, unique) => { bw.ReportProgress(number, unique); }); }; bw.RunWorkerCompleted += (o, args) => { if (radioButtonBluRaySup.Checked) { using (var exportBdnXmlPng = new ExportPngXml()) { exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), ExportPngXml.ExportFormats.BluraySup, FileName, this, "Test123"); exportBdnXmlPng.ShowDialog(this); } DialogResult = DialogResult.OK; } else { var tempFolder = Path.GetTempPath(); var supFileName = Path.Combine(tempFolder, Guid.NewGuid() + ".sup"); using (var binarySubtitleFile = new FileStream(supFileName, FileMode.Create)) { labelStatus.Text = "Generating Blu-ray sup file..."; labelStatus.Refresh(); var bottomMargin = comboBoxBottomMargin.SelectedIndex; var leftMargin = comboBoxLeftRightMargin.SelectedIndex; for (var index = 0; index < _subtitle.Paragraphs.Count; index++) { var p = _subtitle.Paragraphs[index]; var image = _imageList[index].GetBitmap(); var brSub = new BluRaySupPicture { StartTime = (long)p.StartTime.TotalMilliseconds, EndTime = (long)p.EndTime.TotalMilliseconds, Width = VideoWidth, Height = VideoHeight, CompositionNumber = p.Number * 2 }; var buffer = BluRaySupPicture.CreateSupFrame(brSub, image, 25, bottomMargin, leftMargin, ContentAlignment.BottomLeft); binarySubtitleFile.Write(buffer, 0, buffer.Length); } } if (!string.IsNullOrEmpty(supFileName) && File.Exists(supFileName)) { labelStatus.Text = "Generating video..."; labelStatus.Refresh(); var tempImageFileName = Path.Combine(tempFolder, Guid.NewGuid() + ".png"); _resizedBackgroundImage.Save(tempImageFileName, ImageFormat.Png); var tempMkv = Path.Combine(tempFolder, Guid.NewGuid() + ".mkv"); var processMakeVideo = GetFFmpegProcess(tempImageFileName, _audioFileName, tempMkv); processMakeVideo.Start(); processMakeVideo.WaitForExit(); labelStatus.Text = "Adding subtitles to video..."; labelStatus.Refresh(); var processAddSubtitles = GetMkvMergeProcess(tempMkv, supFileName, finalMkv); processAddSubtitles.Start(); processAddSubtitles.WaitForExit(); labelStatus.Text = string.Empty; UiUtil.OpenFolderFromFileName(finalMkv); try { File.Delete(supFileName); File.Delete(tempImageFileName); } catch { // ignore } } DialogResult = DialogResult.OK; } }; labelStatus.Text = "Extracting images..."; labelStatus.Refresh(); bw.RunWorkerAsync(); }