public void BluRaySupWriteAndReadTwoBitmaps()
        {
            var fileName = Guid.NewGuid() + ".sup";

            using (var binarySubtitleFile = new FileStream(fileName, FileMode.Create))
            {
                var brSub = new BluRaySupPicture
                {
                    StartTime = 0,
                    EndTime   = 1000,
                    Width     = 1080,
                    Height    = 720
                };
                var buffer = BluRaySupPicture.CreateSupFrame(brSub, new Bitmap(100, 20), 10, 25, 10, ContentAlignment.BottomCenter);
                binarySubtitleFile.Write(buffer, 0, buffer.Length);
                brSub.StartTime = 2000;
                brSub.EndTime   = 3000;
                buffer          = BluRaySupPicture.CreateSupFrame(brSub, new Bitmap(100, 20), 10, 25, 10, ContentAlignment.BottomCenter);
                binarySubtitleFile.Write(buffer, 0, buffer.Length);
            }

            var log       = new StringBuilder();
            var subtitles = BluRaySupParser.ParseBluRaySup(fileName, log);

            Assert.AreEqual(2, subtitles.Count);
        }
        public static void ConvertFromBluRaySupToBluRaySup(string fileName, List <BluRaySupParser.PcsData> sub, Point?resolution)
        {
            var screenWidth  = 1920;
            var screenHeight = 1080;

            if (sub.Count > 0 && sub[0].Size.Width > 0 && sub[0].Size.Height > 0)
            {
                screenWidth  = sub[0].Size.Width;
                screenHeight = sub[0].Size.Height;
            }
            var leftRightMargin = (int)Math.Round(screenWidth * 4.0 / 100.0);
            var bottomMargin    = (int)Math.Round(screenHeight * 4.0 / 100.0);

            using (var binarySubtitleFile = new FileStream(fileName, FileMode.Create))
            {
                for (int index = 0; index < sub.Count; index++)
                {
                    var p     = sub[index];
                    var brSub = new BluRaySupPicture
                    {
                        StartTime         = (long)p.StartTimeCode.TotalMilliseconds,
                        EndTime           = (long)p.EndTimeCode.TotalMilliseconds,
                        Width             = screenWidth,
                        Height            = screenHeight,
                        IsForced          = p.IsForced,
                        CompositionNumber = (index + 1) * 2
                    };
                    var bitmap      = p.GetBitmap();
                    var pos         = p.GetPosition();
                    var overridePos = new Point(pos.Left, pos.Top);
                    var buffer      = BluRaySupPicture.CreateSupFrame(brSub, bitmap, Configuration.Settings.General.CurrentFrameRate, bottomMargin, leftRightMargin, ContentAlignment.BottomCenter, overridePos);
                    binarySubtitleFile.Write(buffer, 0, buffer.Length);
                    bitmap?.Dispose();
                }
            }
        }
示例#3
0
        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();
        }
示例#4
0
        private void saveFileAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Title        = Configuration.Settings.Language.ExportPngXml.SaveBluRraySupAs;
            saveFileDialog1.DefaultExt   = "*.sup";
            saveFileDialog1.AddExtension = true;
            saveFileDialog1.Filter       = "Blu-Ray sup|*.sup";

            if (saveFileDialog1.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            progressBar1.Value   = 0;
            progressBar1.Maximum = _subtitle.Paragraphs.Count;
            progressBar1.Visible = true;
            if (_bluRaySubtitles != null)
            {
                Cursor = Cursors.WaitCursor;
                var bw = new BackgroundWorker {
                    WorkerReportsProgress = true
                };
                bw.RunWorkerCompleted += (o, args) =>
                {
                    Cursor = Cursors.Default;
                    progressBar1.Visible = false;
                };
                bw.ProgressChanged += (o, args) =>
                {
                    progressBar1.Value = args.ProgressPercentage;
                };
                bw.DoWork += (o, args) =>
                {
                    using (var binarySubtitleFile = new FileStream(args.Argument.ToString(), FileMode.Create))
                    {
                        for (var index = 0; index < _subtitle.Paragraphs.Count; index++)
                        {
                            bw.ReportProgress(index);
                            var p     = _subtitle.Paragraphs[index];
                            var bd    = _bluRaySubtitles[index];
                            var extra = _extra[index];
                            var bmp   = extra.Bitmap ?? bd.GetBitmap();
                            var brSub = new BluRaySupPicture
                            {
                                StartTime         = (long)p.StartTime.TotalMilliseconds,
                                EndTime           = (long)p.EndTime.TotalMilliseconds,
                                Width             = (int)numericUpDownScreenWidth.Value,
                                Height            = (int)numericUpDownScreenHeight.Value,
                                CompositionNumber = p.Number * 2,
                                IsForced          = extra.Forced,
                            };
                            var buffer = BluRaySupPicture.CreateSupFrame(brSub, bmp, 25, 0, 0, 0, new Point(extra.X, extra.Y));
                            if (extra.Bitmap == null)
                            {
                                bmp.Dispose();
                            }

                            binarySubtitleFile.Write(buffer, 0, buffer.Length);
                        }
                    }
                };
                bw.RunWorkerAsync(saveFileDialog1.FileName);
            }
        }