private void buttonSaveAs_Click(object sender, EventArgs e)
        {
            if (_languages != null && comboBoxLanguages.SelectedIndex >= 0 && comboBoxLanguages.SelectedIndex < _languages.Count)
            {
                SelectedLanguageString = _languages[comboBoxLanguages.SelectedIndex];
            }
            else
            {
                SelectedLanguageString = null;
            }

            var subs = new List <VobSubMergedPack>();

            foreach (var x in listBox1.Items)
            {
                subs.Add((x as SubListBoxItem).SubPack);
            }

            using (var formSubOcr = new VobSubOcr())
            {
                formSubOcr.InitializeQuick(subs, _palette, Configuration.Settings.VobSubOcr, SelectedLanguageString);
                var subtitle = formSubOcr.ReadyVobSubRip();

                using (var exportBdnXmlPng = new ExportPngXml())
                {
                    exportBdnXmlPng.InitializeFromVobSubOcr(subtitle, new Core.SubtitleFormats.SubRip(), "VOBSUB", "DVD", formSubOcr, SelectedLanguageString);
                    exportBdnXmlPng.ShowDialog(this);
                }
            }
        }
Esempio n. 2
0
        private void SetBackgroundImage(Bitmap originalBackgroundImage)
        {
            _resizedBackgroundImage = ExportPngXml.ResizeBitmap(originalBackgroundImage, VideoWidth, VideoHeight);
            var bmp = new Bitmap(_resizedBackgroundImage);

            using (var g = Graphics.FromImage(bmp))
            {
                g.DrawRectangle(Pens.Green, Convert.ToInt32(comboBoxLeftRightMargin.SelectedIndex), VideoHeight - CdgGraphics.FullHeight - Convert.ToInt32(comboBoxBottomMargin.SelectedIndex), CdgGraphics.FullWidth, CdgGraphics.FullHeight);
            }

            var oldBitmap = pictureBoxBackgroundImage.Image as Bitmap;

            pictureBoxBackgroundImage.Image = bmp;
            oldBitmap?.Dispose();
        }
        private void ExportTo(string exportType)
        {
            var subtitles = GetSelectedSubtitles();

            if (subtitles == null)
            {
                return;
            }

            using (var formSubOcr = new VobSubOcr())
            {
                formSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, _fileName);
                using (var exportBdnXmlPng = new ExportPngXml())
                {
                    exportBdnXmlPng.InitializeFromVobSubOcr(formSubOcr.SubtitleFromOcr, new SubRip(), exportType, _fileName, formSubOcr, null);
                    exportBdnXmlPng.ShowDialog(this);
                }
            }
        }
        private void buttonSaveAs_Click(object sender, EventArgs e)
        {
            var subtitles = GetSelectedSubtitles();

            if (subtitles == null)
            {
                return;
            }

            using (var formSubOcr = new VobSubOcr())
            {
                formSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, _fileName);
                var subtitle = formSubOcr.ReadyVobSubRip();
                using (var exportBdnXmlPng = new ExportPngXml())
                {
                    exportBdnXmlPng.InitializeFromVobSubOcr(subtitle, new Core.SubtitleFormats.SubRip(), ExportPngXml.ExportFormats.BluraySup, _fileName, formSubOcr, null);
                    exportBdnXmlPng.ShowDialog(this);
                }
            }
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
 private void toolStripMenuItemExportEdlClick(object sender, EventArgs e)
 {
     using (var exportBdnXmlPng = new ExportPngXml())
     {
         exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "EDL", _fileName, _videoInfo, _videoFileName);
         exportBdnXmlPng.ShowDialog(this);
     }
 }
Esempio n. 7
0
 private void DvdStudioProStl_Click(object sender, EventArgs e)
 {
     using (var exportBdnXmlPng = new ExportPngXml())
     {
         exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "STL", _fileName, _videoInfo, _videoFileName);
         exportBdnXmlPng.ShowDialog(this);
     }
 }
Esempio n. 8
0
 private void AdobeEncoreFabImageScriptToolStripMenuItemClick(object sender, EventArgs e)
 {
     using (var exportBdnXmlPng = new ExportPngXml())
     {
         exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "FAB", _fileName, _videoInfo, _videoFileName);
         exportBdnXmlPng.ShowDialog(this);
     }
 }
Esempio n. 9
0
 private void toolStripMenuItemDost_Click(object sender, EventArgs e)
 {
     var exportBdnXmlPng = new ExportPngXml();
     exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "DOST", _fileName, _videoInfo);
     exportBdnXmlPng.ShowDialog(this);
 }
Esempio n. 10
0
 private void toolStripMenuItem2_Click(object sender, EventArgs e)
 {
     var exportBdnXmlPng = new ExportPngXml();
     exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "SPUMUX", _fileName, _videoInfo);
     _formPositionsAndSizes.SetPositionAndSize(exportBdnXmlPng);
     exportBdnXmlPng.ShowDialog(this);
     _formPositionsAndSizes.SavePositionAndSize(exportBdnXmlPng);
 }
Esempio n. 11
0
 private void toolStripMenuItemExportDcinemaInteropClick(object sender, EventArgs e)
 {
     using (var exportBdnXmlPng = new ExportPngXml())
     {
         exportBdnXmlPng.Initialize(this._subtitle, this.GetCurrentSubtitleFormat(), "DCINEMA_INTEROP", this._fileName, this._videoInfo, this.VideoFileName);
         exportBdnXmlPng.ShowDialog(this);
     }
 }
        private void buttonSaveAs_Click(object sender, EventArgs e)
        {
            if (listBox1.Items.Count > -1)
            {
                if (_languages != null && comboBoxLanguages.SelectedIndex >= 0 && comboBoxLanguages.SelectedIndex < _languages.Count)
                    SelectedLanguageString = _languages[comboBoxLanguages.SelectedIndex];
                else
                    SelectedLanguageString = null;

                var subs = new List<VobSubMergedPack>();
                foreach (var x in listBox1.Items)
                {
                    subs.Add((x as SubListBoxItem).SubPack);
                }

                var formSubOcr = new VobSubOcr();
                formSubOcr.InitializeQuick(subs, _palette, Configuration.Settings.VobSubOcr, SelectedLanguageString);
                var subtitle = formSubOcr.ReadyVobSubRip();
                var exportBdnXmlPng = new ExportPngXml();
                exportBdnXmlPng.InitializeFromVobSubOcr(subtitle, new Nikse.SubtitleEdit.Logic.SubtitleFormats.SubRip(), "VOBSUB", "DVD", formSubOcr, SelectedLanguageString);
                exportBdnXmlPng.ShowDialog(this);
            }

        }
Esempio n. 13
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();
        }
Esempio n. 14
0
 private void ExportToEdlWithClipName(object sender, EventArgs e)
 {
     using (var exportBdnXmlPng = new ExportPngXml())
     {
         exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "EDL_CLIPNAME", _fileName, _videoInfo, _videoFileName);
         exportBdnXmlPng.ShowDialog(this);
     }
 }
Esempio n. 15
0
 private void bluraySupToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var exportBdnXmlPng = new ExportPngXml())
     {
         exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), "BLURAYSUP", FileName, this, _importLanguageString);
         exportBdnXmlPng.ShowDialog(this);
     }
 }
Esempio n. 16
0
 private void ShowBluraySettings()
 {
     using (var properties = new ExportPngXml())
     {
         var s = new Subtitle();
         s.Paragraphs.Add(new Paragraph("Test 123." + Environment.NewLine + "Test 456.", 0, 4000));
         properties.Initialize(s, new SubRip(), "BLURAYSUP", null, null, null);
         properties.DisableSaveButtonAndCheckBoxes();
         properties.ShowDialog(this);
     }
 }
Esempio n. 17
0
        internal static bool BatchConvertSave(string toFormat, string offset, Encoding targetEncoding, string outputFolder, int count, ref int converted, ref int errors, IList<SubtitleFormat> formats, string fileName, Subtitle sub, SubtitleFormat format, bool overwrite, string pacCodePage, double? targetFrameRate)
        {
            double oldFrameRate = Configuration.Settings.General.CurrentFrameRate;
            try
            {
                // adjust offset
                if (!string.IsNullOrEmpty(offset) && (offset.StartsWith("/offset:") || offset.StartsWith("offset:")))
                {
                    string[] parts = offset.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length == 5)
                    {
                        try
                        {
                            var ts = new TimeSpan(0, int.Parse(parts[1].TrimStart('-')), int.Parse(parts[2]), int.Parse(parts[3]), int.Parse(parts[4]));
                            if (parts[1].StartsWith('-'))
                                sub.AddTimeToAllParagraphs(ts.Negate());
                            else
                                sub.AddTimeToAllParagraphs(ts);
                        }
                        catch
                        {
                            Console.Write(" (unable to read offset " + offset + ")");
                        }
                    }
                }

                // adjust frame rate
                if (targetFrameRate.HasValue)
                {
                    sub.ChangeFrameRate(Configuration.Settings.General.CurrentFrameRate, targetFrameRate.Value);
                    Configuration.Settings.General.CurrentFrameRate = targetFrameRate.Value;
                }

                bool targetFormatFound = false;
                string outputFileName;
                foreach (SubtitleFormat sf in formats)
                {
                    if (sf.IsTextBased && (sf.Name.Replace(" ", string.Empty).Equals(toFormat, StringComparison.OrdinalIgnoreCase) || sf.Name.Replace(" ", string.Empty).Equals(toFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase)))
                    {
                        targetFormatFound = true;
                        sf.BatchMode = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, sf.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        if (sf.IsFrameBased && !sub.WasLoadedWithFrameNumbers)
                            sub.CalculateFrameNumbersFromTimeCodesNoCheck(Configuration.Settings.General.CurrentFrameRate);
                        else if (sf.IsTimeBased && sub.WasLoadedWithFrameNumbers)
                            sub.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);

                        if ((sf.GetType() == typeof(WebVTT) || sf.GetType() == typeof(WebVTTFileWithLineNumber)))
                        {
                            targetEncoding = Encoding.UTF8;
                        }

                        if (sf.GetType() == typeof(ItunesTimedText) || sf.GetType() == typeof(ScenaristClosedCaptions) || sf.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
                        {
                            Encoding outputEnc = new UTF8Encoding(false); // create encoding with no BOM
                            using (var file = new StreamWriter(outputFileName, false, outputEnc)) // open file with encoding
                            {
                                file.Write(sub.ToText(sf));
                            } // save and close it
                        }
                        else if (targetEncoding == Encoding.UTF8 && (format.GetType() == typeof(TmpegEncAW5) || format.GetType() == typeof(TmpegEncXml)))
                        {
                            Encoding outputEnc = new UTF8Encoding(false); // create encoding with no BOM
                            using (var file = new StreamWriter(outputFileName, false, outputEnc)) // open file with encoding
                            {
                                file.Write(sub.ToText(sf));
                            } // save and close it
                        }
                        else
                        {
                            try
                            {
                                File.WriteAllText(outputFileName, sub.ToText(sf), targetEncoding);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                errors++;
                                return false;
                            }
                        }

                        if (format.GetType() == typeof(Sami) || format.GetType() == typeof(SamiModern))
                        {
                            var sami = (Sami)format;
                            foreach (string className in Sami.GetStylesFromHeader(sub.Header))
                            {
                                var newSub = new Subtitle();
                                foreach (Paragraph p in sub.Paragraphs)
                                {
                                    if (p.Extra != null && p.Extra.Trim().Equals(className.Trim(), StringComparison.OrdinalIgnoreCase))
                                        newSub.Paragraphs.Add(p);
                                }
                                if (newSub.Paragraphs.Count > 0 && newSub.Paragraphs.Count < sub.Paragraphs.Count)
                                {
                                    string s = fileName;
                                    if (s.LastIndexOf('.') > 0)
                                        s = s.Insert(s.LastIndexOf('.'), "_" + className);
                                    else
                                        s += "_" + className + format.Extension;
                                    outputFileName = FormatOutputFileNameForBatchConvert(s, sf.Extension, outputFolder, overwrite);
                                    File.WriteAllText(outputFileName, newSub.ToText(sf), targetEncoding);
                                }
                            }
                        }
                        Console.WriteLine(" done.");
                        break;
                    }
                }
                if (!targetFormatFound)
                {
                    var ebu = new Ebu();
                    if (ebu.Name.Replace(" ", string.Empty).Equals(toFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, ebu.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        Ebu.Save(outputFileName, sub, true);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    var pac = new Pac();
                    if (pac.Name.Replace(" ", string.Empty).Equals(toFormat, StringComparison.OrdinalIgnoreCase) || toFormat.Equals("pac", StringComparison.OrdinalIgnoreCase) || toFormat.Equals(".pac", StringComparison.OrdinalIgnoreCase))
                    {
                        pac.BatchMode = true;
                        int codePage;
                        if (!string.IsNullOrEmpty(pacCodePage) && int.TryParse(pacCodePage, out codePage))
                            pac.CodePage = codePage;
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, pac.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        pac.Save(outputFileName, sub);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    var cavena890 = new Cavena890();
                    if (cavena890.Name.Replace(" ", string.Empty).Equals(toFormat, StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, cavena890.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        cavena890.Save(outputFileName, sub);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    var cheetahCaption = new CheetahCaption();
                    if (cheetahCaption.Name.Replace(" ", string.Empty).Equals(toFormat, StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, cheetahCaption.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        CheetahCaption.Save(outputFileName, sub);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    var capMakerPlus = new CapMakerPlus();
                    if (capMakerPlus.Name.Replace(" ", string.Empty).Equals(toFormat, StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, capMakerPlus.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        CapMakerPlus.Save(outputFileName, sub);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    if (Configuration.Settings.Language.BatchConvert.PlainText == toFormat || Configuration.Settings.Language.BatchConvert.PlainText.Replace(" ", string.Empty).Equals(toFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, ".txt", outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        File.WriteAllText(outputFileName, ExportText.GeneratePlainText(sub, false, false, false, false, false, false, string.Empty, true, false, true, true, false), targetEncoding);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    if (string.Compare(BatchConvert.BluRaySubtitle, toFormat, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(BatchConvert.BluRaySubtitle.Replace(" ", string.Empty), toFormat, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, ".sup", outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        using (var form = new ExportPngXml())
                        {
                            form.Initialize(sub, format, "BLURAYSUP", fileName, null, null);
                            var binarySubtitleFile = new FileStream(outputFileName, FileMode.Create);
                            int width = 1920;
                            int height = 1080;
                            var parts = Configuration.Settings.Tools.ExportBluRayVideoResolution.Split('x');
                            if (parts.Length == 2 && Utilities.IsInteger(parts[0]) && Utilities.IsInteger(parts[1]))
                            {
                                width = int.Parse(parts[0]);
                                height = int.Parse(parts[1]);
                            }
                            for (int index = 0; index < sub.Paragraphs.Count; index++)
                            {
                                var mp = form.MakeMakeBitmapParameter(index, width, height);
                                mp.LineJoin = Configuration.Settings.Tools.ExportPenLineJoin;
                                mp.Bitmap = ExportPngXml.GenerateImageFromTextWithStyle(mp);
                                ExportPngXml.MakeBluRaySupImage(mp);
                                binarySubtitleFile.Write(mp.Buffer, 0, mp.Buffer.Length);
                            }
                            binarySubtitleFile.Close();
                        }
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    Console.WriteLine("{0}: {1} - target format '{2}' not found!", count, fileName, toFormat);
                    errors++;
                    return false;
                }
                converted++;
                return true;
            }
            finally
            {
                Configuration.Settings.General.CurrentFrameRate = oldFrameRate;
            }
        }
Esempio n. 18
0
 private void dOSTToolStripMenuItem_Click(object sender, EventArgs e)
 {
     var exportBdnXmlPng = new ExportPngXml();
     exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), "DOST", FileName, this, _importLanguageString);
     exportBdnXmlPng.ShowDialog(this);
 }
        internal static bool BatchConvertSave(string targetFormat, string offset, Encoding targetEncoding, string outputFolder, int count, ref int converted, ref int errors, IEnumerable<SubtitleFormat> formats, string fileName, Subtitle sub, SubtitleFormat format, bool overwrite, int pacCodePage, double? targetFrameRate, IEnumerable<string> multipleReplaceImportFiles, bool removeTextForHi, bool fixCommonErrors, bool redoCasing)
        {
            double oldFrameRate = Configuration.Settings.General.CurrentFrameRate;
            try
            {
                // adjust offset
                if (!string.IsNullOrWhiteSpace(offset))
                {
                    var offsetSplitChars = new[] { ':', '.', ',' };
                    var parts = offset.Split(offsetSplitChars, StringSplitOptions.RemoveEmptyEntries);
                    while (parts.Length > 1 && parts.Length < 4)
                    {
                        offset = "0:" + offset;
                        parts = offset.Split(offsetSplitChars, StringSplitOptions.RemoveEmptyEntries);
                    }
                    if (parts.Length == 4)
                    {
                        try
                        {
                            var ts = new TimeSpan(0, int.Parse(parts[0].TrimStart('-')), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3]));
                            if (parts[0].StartsWith('-'))
                                sub.AddTimeToAllParagraphs(ts.Negate());
                            else
                                sub.AddTimeToAllParagraphs(ts);
                            parts = null;
                        }
                        catch
                        {
                            // ignored
                        }
                    }
                    if (parts != null)
                    {
                        Console.Write(" (unable to read offset " + offset + ")");
                    }
                }

                // adjust frame rate
                if (targetFrameRate.HasValue)
                {
                    sub.ChangeFrameRate(Configuration.Settings.General.CurrentFrameRate, targetFrameRate.Value);
                    Configuration.Settings.General.CurrentFrameRate = targetFrameRate.Value;
                }

                if (removeTextForHi)
                {
                    var hiSettings = new Core.Forms.RemoveTextForHISettings();
                    var hiLib = new Core.Forms.RemoveTextForHI(hiSettings);
                    foreach (var p in sub.Paragraphs)
                    {
                        p.Text = hiLib.RemoveTextFromHearImpaired(p.Text);
                    }
                }
                if (fixCommonErrors)
                {
                    using (var fce = new FixCommonErrors { BatchMode = true })
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            fce.RunBatch(sub, format, targetEncoding, Configuration.Settings.Tools.BatchConvertLanguage);
                            sub = fce.FixedSubtitle;
                        }
                    }
                }
                if (redoCasing)
                {
                    using (var changeCasing = new ChangeCasing())
                    {
                        changeCasing.FixCasing(sub, LanguageAutoDetect.AutoDetectGoogleLanguage(sub));
                    }
                    using (var changeCasingNames = new ChangeCasingNames())
                    {
                        changeCasingNames.Initialize(sub);
                        changeCasingNames.FixCasing();
                    }
                }
                if (multipleReplaceImportFiles != null && multipleReplaceImportFiles.Count() > 0)
                {
                    using (var mr = new MultipleReplace())
                    {
                        mr.RunFromBatch(sub, multipleReplaceImportFiles);
                        sub = mr.FixedSubtitle;
                        sub.RemoveParagraphsByIndices(mr.DeleteIndices);
                    }
                }

                bool targetFormatFound = false;
                string outputFileName;
                foreach (SubtitleFormat sf in formats)
                {
                    if (sf.IsTextBased && sf.Name.Replace(" ", string.Empty).Equals(targetFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        sf.BatchMode = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, sf.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        if (sf.IsFrameBased && !sub.WasLoadedWithFrameNumbers)
                            sub.CalculateFrameNumbersFromTimeCodesNoCheck(Configuration.Settings.General.CurrentFrameRate);
                        else if (sf.IsTimeBased && sub.WasLoadedWithFrameNumbers)
                            sub.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);

                        if (sf.GetType() == typeof(WebVTT))
                        {
                            targetEncoding = Encoding.UTF8;
                        }

                        try
                        {
                            if (sf.GetType() == typeof(ItunesTimedText) || sf.GetType() == typeof(ScenaristClosedCaptions) || sf.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
                            {
                                var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
                                using (var file = new StreamWriter(outputFileName, false, outputEnc)) // open file with encoding
                                {
                                    file.Write(sub.ToText(sf));
                                } // save and close it
                            }
                            else if (targetEncoding == Encoding.UTF8 && (format.GetType() == typeof(TmpegEncAW5) || format.GetType() == typeof(TmpegEncXml)))
                            {
                                var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
                                using (var file = new StreamWriter(outputFileName, false, outputEnc)) // open file with encoding
                                {
                                    file.Write(sub.ToText(sf));
                                } // save and close it
                            }
                            else
                            {
                                File.WriteAllText(outputFileName, sub.ToText(sf), targetEncoding);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            errors++;
                            return false;
                        }

                        if (format.GetType() == typeof(Sami) || format.GetType() == typeof(SamiModern))
                        {
                            var sami = (Sami)format;
                            foreach (string className in Sami.GetStylesFromHeader(sub.Header))
                            {
                                var newSub = new Subtitle();
                                foreach (Paragraph p in sub.Paragraphs)
                                {
                                    if (p.Extra != null && p.Extra.Trim().Equals(className.Trim(), StringComparison.OrdinalIgnoreCase))
                                        newSub.Paragraphs.Add(p);
                                }
                                if (newSub.Paragraphs.Count > 0 && newSub.Paragraphs.Count < sub.Paragraphs.Count)
                                {
                                    string s = fileName;
                                    if (s.LastIndexOf('.') > 0)
                                        s = s.Insert(s.LastIndexOf('.'), "_" + className);
                                    else
                                        s += "_" + className + format.Extension;
                                    outputFileName = FormatOutputFileNameForBatchConvert(s, sf.Extension, outputFolder, overwrite);
                                    File.WriteAllText(outputFileName, newSub.ToText(sf), targetEncoding);
                                }
                            }
                        }
                        Console.WriteLine(" done.");
                        break;
                    }
                }
                if (!targetFormatFound)
                {
                    var ebu = new Ebu();
                    if (ebu.Name.Replace(" ", string.Empty).Equals(targetFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, ebu.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        Ebu.Save(outputFileName, sub, true);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    var pac = new Pac();
                    if (pac.Name.Replace(" ", string.Empty).Equals(targetFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase) || targetFormat.Equals(".pac", StringComparison.OrdinalIgnoreCase) || targetFormat.Equals("pac", StringComparison.OrdinalIgnoreCase))
                    {
                        pac.BatchMode = true;
                        pac.CodePage = pacCodePage;
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, pac.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        pac.Save(outputFileName, sub);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    var cavena890 = new Cavena890();
                    if (cavena890.Name.Replace(" ", string.Empty).Equals(targetFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, cavena890.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        cavena890.Save(outputFileName, sub);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    var cheetahCaption = new CheetahCaption();
                    if (cheetahCaption.Name.Replace(" ", string.Empty).Equals(targetFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, cheetahCaption.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        CheetahCaption.Save(outputFileName, sub);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    var ayato = new Ayato();
                    if (ayato.Name.Replace(" ", string.Empty).Equals(targetFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, ayato.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        ayato.Save(outputFileName, null, sub);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    var capMakerPlus = new CapMakerPlus();
                    if (capMakerPlus.Name.Replace(" ", string.Empty).Equals(targetFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, capMakerPlus.Extension, outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        CapMakerPlus.Save(outputFileName, sub);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    if (Configuration.Settings.Language.BatchConvert.PlainText.Replace(" ", string.Empty).Equals(targetFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, ".txt", outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        File.WriteAllText(outputFileName, ExportText.GeneratePlainText(sub, false, false, false, false, false, false, string.Empty, true, false, true, true, false), targetEncoding);
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    if (BatchConvert.BluRaySubtitle.Replace(" ", string.Empty).Equals(targetFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, ".sup", outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        using (var form = new ExportPngXml())
                        {
                            form.Initialize(sub, format, "BLURAYSUP", fileName, null, null);
                            int width = 1920;
                            int height = 1080;
                            var parts = Configuration.Settings.Tools.ExportBluRayVideoResolution.Split('x');
                            if (parts.Length == 2 && Utilities.IsInteger(parts[0]) && Utilities.IsInteger(parts[1]))
                            {
                                width = int.Parse(parts[0]);
                                height = int.Parse(parts[1]);
                            }

                            using (var binarySubtitleFile = new FileStream(outputFileName, FileMode.Create))
                            {
                                for (int index = 0; index < sub.Paragraphs.Count; index++)
                                {
                                    var mp = form.MakeMakeBitmapParameter(index, width, height);
                                    mp.LineJoin = Configuration.Settings.Tools.ExportPenLineJoin;
                                    mp.Bitmap = ExportPngXml.GenerateImageFromTextWithStyle(mp);
                                    ExportPngXml.MakeBluRaySupImage(mp);
                                    binarySubtitleFile.Write(mp.Buffer, 0, mp.Buffer.Length);
                                }
                            }
                        }
                        Console.WriteLine(" done.");
                    }
                    else if (BatchConvert.VobSubSubtitle.Replace(" ", string.Empty).Equals(targetFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
                    {
                        targetFormatFound = true;
                        outputFileName = FormatOutputFileNameForBatchConvert(fileName, ".sub", outputFolder, overwrite);
                        Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
                        using (var form = new ExportPngXml())
                        {
                            form.Initialize(sub, format, "VOBSUB", fileName, null, null);
                            int width = 720;
                            int height = 576;
                            var parts = Configuration.Settings.Tools.ExportVobSubVideoResolution.Split('x');
                            if (parts.Length == 2 && Utilities.IsInteger(parts[0]) && Utilities.IsInteger(parts[1]))
                            {
                                width = int.Parse(parts[0]);
                                height = int.Parse(parts[1]);
                            }

                            var cfg = Configuration.Settings.Tools;
                            var language = DvdSubtitleLanguage.GetLanguageOrNull(LanguageAutoDetect.AutoDetectGoogleLanguage(sub)) ?? DvdSubtitleLanguage.English;
                            using (var vobSubWriter = new VobSubWriter(outputFileName, width, height, cfg.ExportBottomMargin, cfg.ExportBottomMargin, 32, cfg.ExportFontColor, cfg.ExportBorderColor, !cfg.ExportVobAntiAliasingWithTransparency, language))
                            {
                                for (int index = 0; index < sub.Paragraphs.Count; index++)
                                {
                                    var mp = form.MakeMakeBitmapParameter(index, width, height);
                                    mp.LineJoin = Configuration.Settings.Tools.ExportPenLineJoin;
                                    mp.Bitmap = ExportPngXml.GenerateImageFromTextWithStyle(mp);
                                    vobSubWriter.WriteParagraph(mp.P, mp.Bitmap, mp.Alignment);
                                }
                                vobSubWriter.WriteIdxFile();
                            }
                        }
                        Console.WriteLine(" done.");
                    }
                }
                if (!targetFormatFound)
                {
                    Console.WriteLine("{0}: {1} - target format '{2}' not found!", count, fileName, targetFormat);
                    errors++;
                    return false;
                }
                converted++;
                return true;
            }
            finally
            {
                Configuration.Settings.General.CurrentFrameRate = oldFrameRate;
            }
        }
Esempio n. 20
0
 private void vobSubToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var exportBdnXmlPng = new ExportPngXml())
     {
         _fromMenuItem = true;
         exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), "VOBSUB", FileName, this, _importLanguageString);
         exportBdnXmlPng.ShowDialog(this);
         _fromMenuItem = false;
     }
 }
Esempio n. 21
0
 private void ToolStripMenuItemImagePerFrameClick(object sender, EventArgs e)
 {
     var exportBdnXmlPng = new ExportPngXml();
     exportBdnXmlPng.Initialize(_subtitle, GetCurrentSubtitleFormat(), "IMAGE/FRAME", _fileName, _videoInfo);
     exportBdnXmlPng.ShowDialog(this);
 }
Esempio n. 22
0
 private void ToolStripMenuItemImagePerFrameClick(object sender, EventArgs e)
 {
     using (var exportBdnXmlPng = new ExportPngXml())
     {
         exportBdnXmlPng.Initialize(this._subtitle, this.GetCurrentSubtitleFormat(), "IMAGE/FRAME", this._fileName, this._videoInfo, this.VideoFileName);
         exportBdnXmlPng.ShowDialog(this);
     }
 }
Esempio n. 23
0
 /// <summary>
 /// The tool strip menu item export fcp i image_ click.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void toolStripMenuItemExportFcpIImage_Click(object sender, EventArgs e)
 {
     using (var exportBdnXmlPng = new ExportPngXml())
     {
         exportBdnXmlPng.Initialize(this._subtitle, this.GetCurrentSubtitleFormat(), "FCP", this._fileName, this._videoInfo, this._videoFileName);
         exportBdnXmlPng.ShowDialog(this);
     }
 }
Esempio n. 24
0
 private void BluraySupToolStripMenuItemClick(object sender, EventArgs e)
 {
     using (var exportBdnXmlPng = new ExportPngXml())
     {
         exportBdnXmlPng.Initialize(this._subtitle, this.GetCurrentSubtitleFormat(), "BLURAYSUP", this._fileName, this._videoInfo, this.VideoFileName);
         exportBdnXmlPng.ShowDialog(this);
     }
 }
Esempio n. 25
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            radioButtonSrt.Enabled         = false;
            radioButtonSrtOnlyText.Enabled = false;
            radioButtonBluRaySup.Enabled   = false;
            radioButtonASS.Enabled         = false;

            NikseBitmap lastNBmp = null;
            int         count    = 0;
            int         total    = (int)Math.Round(_cdgGraphics.DurationInMilliseconds / CdgGraphics.TimeMsFactor);

            _imageList = new List <NikseBitmap>();
            _subtitle.Paragraphs.Clear();
            Paragraph p            = null;
            int       packetNumber = 0;
            var       max          = _cdgGraphics.NumberOfPackets;

            while (packetNumber < max)
            {
                using (var bmp = _cdgGraphics.ToBitmap(packetNumber))
                {
                    var nBmp   = new NikseBitmap(bmp);
                    var timeMs = packetNumber * CdgGraphics.TimeMsFactor;
                    if (lastNBmp == null)
                    {
                        if (nBmp.Width > 0)
                        {
                            lastNBmp = nBmp;
                            p        = new Paragraph(string.Empty, timeMs, timeMs);
                        }
                    }
                    else
                    {
                        if (!IsImagesTheSame(nBmp, lastNBmp))
                        {
                            if (lastNBmp.Width > 0)
                            {
                                p.EndTime.TotalMilliseconds = timeMs;
                                _subtitle.Paragraphs.Add(p);
                                _imageList.Add(lastNBmp);
                            }

                            if (nBmp.Width > 0)
                            {
                                p = new Paragraph(string.Empty, timeMs, timeMs);
                            }
                        }
                        lastNBmp = nBmp;
                    }
                }
                count++;
                packetNumber++;
                labelProgress.Text = $"Frame {count:#,###,##0} of {total:#,###,##0}";
                labelProgress.Refresh();
                labelProgress2.Text = $"Unique images {_imageList.Count:#,###,##0}";
                labelProgress2.Refresh();
            }

            _subtitle.Renumber();
            using (var exportBdnXmlPng = new ExportPngXml())
            {
                exportBdnXmlPng.InitializeFromVobSubOcr(_subtitle, new SubRip(), ExportPngXml.ExportFormats.BluraySup, FileName, this, "Test123");
                //        exportBdnXmlPng.SetResolution(new Point(bmp.Width, bmp.Height));
                exportBdnXmlPng.ShowDialog(this);
            }
        }