public void VobSubWriteAndReadTwoBitmaps() { string fileName = Guid.NewGuid() + ".sub"; using (var writer = new VobSubWriter(fileName, 800, 600, 10, 10, 32, Color.White, Color.Black, true, DvdSubtitleLanguage.English)) { var p1 = new Paragraph("Line1", 0, 1000); var p2 = new Paragraph("Line2", 2000, 3000); writer.WriteParagraph(p1, new Bitmap(200, 20), ContentAlignment.BottomCenter); writer.WriteParagraph(p2, new Bitmap(200, 20), ContentAlignment.BottomCenter); } var reader = new VobSubParser(true); reader.Open(fileName); var list = reader.MergeVobSubPacks(); Assert.IsTrue(list.Count == 2); }
private int WriteParagraph(int width, StringBuilder sb, int border, int height, int imagesSavedCount, VobSubWriter vobSubWriter, FileStream binarySubtitleFile, MakeBitmapParameter param, int i) { if (param.Bitmap != null) { if (_exportType == "BLURAYSUP") { if (!param.Saved) { binarySubtitleFile.Write(param.Buffer, 0, param.Buffer.Length); } param.Saved = true; } else if (_exportType == "VOBSUB") { if (!param.Saved) vobSubWriter.WriteParagraph(param.P, param.Bitmap, param.Alignment); param.Saved = true; } else if (_exportType == "FAB") { if (!param.Saved) { string numberString = string.Format("IMAGE{0:000}", i); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower()); if (checkBoxFullFrameImage.Visible && checkBoxFullFrameImage.Checked) { var nbmp = new NikseBitmap(param.Bitmap); nbmp.ReplaceTransparentWith(panelFullFrameBackground.BackColor); using (var bmp = nbmp.GetBitmap()) { // param.Bitmap.Save(fileName, ImageFormat); imagesSavedCount++; //RACE001.TIF 00;00;02;02 00;00;03;15 000 000 720 480 //RACE002.TIF 00;00;05;18 00;00;09;20 000 000 720 480 int top = param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin); int left = (param.ScreenWidth - param.Bitmap.Width) / 2; var b = new NikseBitmap(param.ScreenWidth, param.ScreenHeight); { b.Fill(panelFullFrameBackground.BackColor); using (var fullSize = b.GetBitmap()) { if (param.Alignment == ContentAlignment.BottomLeft || param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.TopLeft) left = param.LeftRightMargin; else if (param.Alignment == ContentAlignment.BottomRight || param.Alignment == ContentAlignment.MiddleRight || param.Alignment == ContentAlignment.TopRight) left = param.ScreenWidth - param.Bitmap.Width - param.LeftRightMargin; if (param.Alignment == ContentAlignment.TopLeft || param.Alignment == ContentAlignment.TopCenter || param.Alignment == ContentAlignment.TopRight) top = param.BottomMargin; if (param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.MiddleCenter || param.Alignment == ContentAlignment.MiddleRight) top = param.ScreenHeight - (param.Bitmap.Height / 2); using (var g = Graphics.FromImage(fullSize)) { g.DrawImage(bmp, left, top); g.Dispose(); } SaveImage(fullSize, fileName, ImageFormat); } } left = 0; top = 0; sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5} {6}", Path.GetFileName(fileName), FormatFabTime(param.P.StartTime, param), FormatFabTime(param.P.EndTime, param), left, top, left + param.ScreenWidth, top + param.ScreenHeight)); } } else { SaveImage(param.Bitmap, fileName, ImageFormat); imagesSavedCount++; //RACE001.TIF 00;00;02;02 00;00;03;15 000 000 720 480 //RACE002.TIF 00;00;05;18 00;00;09;20 000 000 720 480 int top = param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin); int left = (param.ScreenWidth - param.Bitmap.Width) / 2; if (param.Alignment == ContentAlignment.BottomLeft || param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.TopLeft) left = param.LeftRightMargin; else if (param.Alignment == ContentAlignment.BottomRight || param.Alignment == ContentAlignment.MiddleRight || param.Alignment == ContentAlignment.TopRight) left = param.ScreenWidth - param.Bitmap.Width - param.LeftRightMargin; if (param.Alignment == ContentAlignment.TopLeft || param.Alignment == ContentAlignment.TopCenter || param.Alignment == ContentAlignment.TopRight) top = param.BottomMargin; if (param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.MiddleCenter || param.Alignment == ContentAlignment.MiddleRight) top = param.ScreenHeight - (param.Bitmap.Height / 2); sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5} {6}", Path.GetFileName(fileName), FormatFabTime(param.P.StartTime, param), FormatFabTime(param.P.EndTime, param), left, top, left + param.Bitmap.Width, top + param.Bitmap.Height)); } param.Saved = true; } } else if (_exportType == "STL") { if (!param.Saved) { string numberString = string.Format("IMAGE{0:000}", i); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower()); SaveImage(param.Bitmap, fileName, ImageFormat); imagesSavedCount++; const string paragraphWriteFormat = "{0} , {1} , {2}\r\n"; const string timeFormat = "{0:00}:{1:00}:{2:00}:{3:00}"; double factor = (TimeCode.BaseUnit / Configuration.Settings.General.CurrentFrameRate); string startTime = string.Format(timeFormat, param.P.StartTime.Hours, param.P.StartTime.Minutes, param.P.StartTime.Seconds, (int)Math.Round(param.P.StartTime.Milliseconds / factor)); string endTime = string.Format(timeFormat, param.P.EndTime.Hours, param.P.EndTime.Minutes, param.P.EndTime.Seconds, (int)Math.Round(param.P.EndTime.Milliseconds / factor)); sb.AppendFormat(paragraphWriteFormat, startTime, endTime, fileName); param.Saved = true; } } else if (_exportType == "SPUMUX") { if (!param.Saved) { string numberString = string.Format("IMAGE{0:000}", i); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower()); foreach (var encoder in ImageCodecInfo.GetImageEncoders()) { if (encoder.FormatID == ImageFormat.Png.Guid) { var parameters = new EncoderParameters(); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8); var nbmp = new NikseBitmap(param.Bitmap); var b = nbmp.ConverTo8BitsPerPixel(); b.Save(fileName, encoder, parameters); b.Dispose(); break; } } imagesSavedCount++; const string paragraphWriteFormat = "\t\t<spu start=\"{0}\" end=\"{1}\" image=\"{2}\" />"; const string timeFormat = "{0:00}:{1:00}:{2:00}:{3:00}"; double factor = (TimeCode.BaseUnit / Configuration.Settings.General.CurrentFrameRate); string startTime = string.Format(timeFormat, param.P.StartTime.Hours, param.P.StartTime.Minutes, param.P.StartTime.Seconds, (int)Math.Round(param.P.StartTime.Milliseconds / factor)); string endTime = string.Format(timeFormat, param.P.EndTime.Hours, param.P.EndTime.Minutes, param.P.EndTime.Seconds, (int)Math.Round(param.P.EndTime.Milliseconds / factor)); sb.AppendLine(string.Format(paragraphWriteFormat, startTime, endTime, fileName)); param.Saved = true; } } else if (_exportType == "FCP") { if (!param.Saved) { string numberString = string.Format(Path.GetFileNameWithoutExtension(Path.GetFileName(param.SavDialogFileName)) + "{0:0000}", i); string fileName = numberString + "." + comboBoxImageFormat.Text.ToLower(); string fileNameNoPath = Path.GetFileName(fileName); string fileNameNoExt = Path.GetFileNameWithoutExtension(fileNameNoPath); string template = " <clipitem id=\"" + System.Security.SecurityElement.Escape(fileNameNoPath) + "\">" + Environment.NewLine + // <pathurl>file://localhost/" + fileNameNoPath.Replace(" ", "%20") + @"</pathurl> @" <name>" + System.Security.SecurityElement.Escape(fileNameNoPath) + @"</name> <duration>[DURATION]</duration> <rate> <ntsc>FALSE</ntsc> <timebase>25</timebase> </rate> <in>[IN]</in> <out>[OUT]</out> <start>[START]</start> <end>[END]</end> <pixelaspectratio>" + param.VideoResolution + @"</pixelaspectratio> <stillframe>TRUE</stillframe> <anamorphic>FALSE</anamorphic> <alphatype>straight</alphatype> <masterclipid>" + System.Security.SecurityElement.Escape(fileNameNoPath) + @"1</masterclipid>" + Environment.NewLine + " <file id=\"" + fileNameNoExt + "\">" + @" <name>" + System.Security.SecurityElement.Escape(fileNameNoPath) + @"</name> <pathurl>" + Utilities.UrlEncode(fileNameNoPath) + @"</pathurl> <rate> <timebase>25</timebase> </rate> <duration>[DURATION]</duration> <width>" + param.ScreenWidth + @"</width> <height>" + param.ScreenHeight + @"</height> <media> <video> <duration>[DURATION]</duration> <stillframe>TRUE</stillframe> <samplecharacteristics> <width>" + param.ScreenWidth + @"</width> <height>" + param.ScreenHeight + @"</height> </samplecharacteristics> </video> </media> </file> <sourcetrack> <mediatype>video</mediatype> </sourcetrack> <fielddominance>none</fielddominance> </clipitem>"; fileName = Path.Combine(Path.GetDirectoryName(param.SavDialogFileName), fileName); if (comboBoxImageFormat.Text == "8-bit png") { foreach (var encoder in ImageCodecInfo.GetImageEncoders()) { if (encoder.FormatID == ImageFormat.Png.Guid) { var parameters = new EncoderParameters(); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8); var nbmp = new NikseBitmap(param.Bitmap); var b = nbmp.ConverTo8BitsPerPixel(); b.Save(fileName, encoder, parameters); b.Dispose(); break; } } } else { SaveImage(param.Bitmap, fileName, ImageFormat); } imagesSavedCount++; int duration = (int)Math.Round(param.P.Duration.TotalSeconds * param.FramesPerSeconds); int start = (int)Math.Round(param.P.StartTime.TotalSeconds * param.FramesPerSeconds); int end = (int)Math.Round(param.P.EndTime.TotalSeconds * param.FramesPerSeconds); template = template.Replace("[DURATION]", duration.ToString(CultureInfo.InvariantCulture)); template = template.Replace("[IN]", start.ToString(CultureInfo.InvariantCulture)); template = template.Replace("[OUT]", end.ToString(CultureInfo.InvariantCulture)); template = template.Replace("[START]", start.ToString(CultureInfo.InvariantCulture)); template = template.Replace("[END]", end.ToString(CultureInfo.InvariantCulture)); sb.AppendLine(template); param.Saved = true; } } else if (_exportType == "DOST") { if (!param.Saved) { string numberString = string.Format("{0:0000}", i); string fileName = Path.Combine(Path.GetDirectoryName(saveFileDialog1.FileName), Path.GetFileNameWithoutExtension(saveFileDialog1.FileName).Replace(" ", "_")) + "_" + numberString + ".png"; foreach (var encoder in ImageCodecInfo.GetImageEncoders()) { if (encoder.FormatID == ImageFormat.Png.Guid) { var parameters = new EncoderParameters(); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8); var nbmp = new NikseBitmap(param.Bitmap); var b = nbmp.ConverTo8BitsPerPixel(); b.Save(fileName, encoder, parameters); b.Dispose(); break; } } imagesSavedCount++; const string paragraphWriteFormat = "{0}\t{1}\t{2}\t{4}\t{5}\t{3}\t0\t0"; int top = param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin); int left = (param.ScreenWidth - param.Bitmap.Width) / 2; if (param.Alignment == ContentAlignment.BottomLeft || param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.TopLeft) left = param.LeftRightMargin; else if (param.Alignment == ContentAlignment.BottomRight || param.Alignment == ContentAlignment.MiddleRight || param.Alignment == ContentAlignment.TopRight) left = param.ScreenWidth - param.Bitmap.Width - param.LeftRightMargin; if (param.Alignment == ContentAlignment.TopLeft || param.Alignment == ContentAlignment.TopCenter || param.Alignment == ContentAlignment.TopRight) top = param.BottomMargin; if (param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.MiddleCenter || param.Alignment == ContentAlignment.MiddleRight) top = param.ScreenHeight - (param.Bitmap.Height / 2); string startTime = ToHHMMSSFF(param.P.StartTime); string endTime = ToHHMMSSFF(param.P.EndTime); sb.AppendLine(string.Format(paragraphWriteFormat, numberString, startTime, endTime, Path.GetFileName(fileName), left, top)); param.Saved = true; } } else if (_exportType == "IMAGE/FRAME") { if (!param.Saved) { var imageFormat = ImageFormat; int lastFrame = imagesSavedCount; int startFrame = (int)Math.Round(param.P.StartTime.TotalMilliseconds / (TimeCode.BaseUnit / param.FramesPerSeconds)); var empty = new Bitmap(param.ScreenWidth, param.ScreenHeight); if (imagesSavedCount == 0 && checkBoxSkipEmptyFrameAtStart.Checked) { } else { // Save empty picture for each frame up to start frame for (int k = lastFrame + 1; k < startFrame; k++) { string numberString = string.Format("{0:00000}", k); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower()); empty.Save(fileName, imageFormat); imagesSavedCount++; } } int endFrame = (int)Math.Round(param.P.EndTime.TotalMilliseconds / (TimeCode.BaseUnit / param.FramesPerSeconds)); var fullSize = new Bitmap(param.ScreenWidth, param.ScreenHeight); Graphics g = Graphics.FromImage(fullSize); g.DrawImage(param.Bitmap, (param.ScreenWidth - param.Bitmap.Width) / 2, param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin)); g.Dispose(); if (imagesSavedCount > startFrame) startFrame = imagesSavedCount; // no overlapping // Save sub picture for each frame in duration for (int k = startFrame; k <= endFrame; k++) { string numberString = string.Format("{0:00000}", k); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower()); fullSize.Save(fileName, imageFormat); imagesSavedCount++; } fullSize.Dispose(); param.Saved = true; } } else if (_exportType == "DCINEMA_INTEROP") { if (!param.Saved) { string numberString = string.Format("{0:0000}", i); string fileName = Path.Combine(Path.GetDirectoryName(saveFileDialog1.FileName), numberString + ".png"); param.Bitmap.Save(fileName, ImageFormat.Png); imagesSavedCount++; param.Saved = true; sb.AppendLine("<Subtitle FadeDownTime=\"" + 0 + "\" FadeUpTime=\"" + 0 + "\" TimeOut=\"" + DCSubtitle.ConvertToTimeString(param.P.EndTime) + "\" TimeIn=\"" + DCSubtitle.ConvertToTimeString(param.P.StartTime) + "\" SpotNumber=\"" + param.P.Number + "\">"); if (param.Depth3D == 0) sb.AppendLine("<Image VPosition=\"9.7\" VAlign=\"bottom\" HAlign=\"center\">" + numberString + ".png" + "</Image>"); else sb.AppendLine("<Image VPosition=\"9.7\" ZPosition=\"" + param.Depth3D + "\" VAlign=\"bottom\" HAlign=\"center\">" + numberString + ".png" + "</Image>"); sb.AppendLine("</Subtitle>"); } } else if (_exportType == "EDL") { if (!param.Saved) { // 001 7M6C7986 V C 14:14:55:21 14:15:16:24 01:00:10:18 01:00:31:21 var fileName1 = "IMG" + i.ToString(CultureInfo.InvariantCulture).PadLeft(5, '0'); var fullSize = new Bitmap(param.ScreenWidth, param.ScreenHeight); using (var g = Graphics.FromImage(fullSize)) { g.DrawImage(param.Bitmap, (param.ScreenWidth - param.Bitmap.Width) / 2, param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin)); } var fileName2 = Path.Combine(Path.GetDirectoryName(param.SavDialogFileName), fileName1 + ".PNG"); fullSize.Save(fileName2, ImageFormat.Png); fullSize.Dispose(); string line = string.Format("{0:000} {1} V C {2} {3} {4} {5}", i, fileName1, new TimeCode(0).ToHHMMSSFF(), param.P.Duration.ToHHMMSSFF(), param.P.StartTime.ToHHMMSSFF(), param.P.EndTime.ToHHMMSSFF()); sb.AppendLine(line); sb.AppendLine(); imagesSavedCount++; param.Saved = true; } } else // BDNXML { if (!param.Saved) { string numberString = string.Format("{0:0000}", i); string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + ".png"); if (comboBoxImageFormat.Text == "Png 8-bit") { foreach (var encoder in ImageCodecInfo.GetImageEncoders()) { if (encoder.FormatID == ImageFormat.Png.Guid) { var parameters = new EncoderParameters(); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8); var nbmp = new NikseBitmap(param.Bitmap); var b = nbmp.ConverTo8BitsPerPixel(); b.Save(fileName, encoder, parameters); b.Dispose(); break; } } } else { param.Bitmap.Save(fileName, ImageFormat.Png); } imagesSavedCount++; //<Event InTC="00:00:24:07" OutTC="00:00:31:13" Forced="False"> // <Graphic Width="696" Height="111" X="612" Y="930">subtitle_exp_0001.png</Graphic> //</Event> sb.AppendLine("<Event InTC=\"" + ToHHMMSSFF(param.P.StartTime) + "\" OutTC=\"" + ToHHMMSSFF(param.P.EndTime) + "\" Forced=\"" + param.Forced.ToString().ToLower() + "\">"); int x = (width - param.Bitmap.Width) / 2; int y = height - (param.Bitmap.Height + param.BottomMargin); switch (param.Alignment) { case ContentAlignment.BottomLeft: x = border; y = height - (param.Bitmap.Height + param.BottomMargin); break; case ContentAlignment.BottomRight: x = height - param.Bitmap.Width - border; y = height - (param.Bitmap.Height + param.BottomMargin); break; case ContentAlignment.MiddleCenter: x = (width - param.Bitmap.Width) / 2; y = (height - param.Bitmap.Height) / 2; break; case ContentAlignment.MiddleLeft: x = border; y = (height - param.Bitmap.Height) / 2; break; case ContentAlignment.MiddleRight: x = width - param.Bitmap.Width - border; y = (height - param.Bitmap.Height) / 2; break; case ContentAlignment.TopCenter: x = (width - param.Bitmap.Width) / 2; y = border; break; case ContentAlignment.TopLeft: x = border; y = border; break; case ContentAlignment.TopRight: x = width - param.Bitmap.Width - border; y = border; break; } sb.AppendLine(" <Graphic Width=\"" + param.Bitmap.Width.ToString(CultureInfo.InvariantCulture) + "\" Height=\"" + param.Bitmap.Height.ToString(CultureInfo.InvariantCulture) + "\" X=\"" + x.ToString(CultureInfo.InvariantCulture) + "\" Y=\"" + y.ToString(CultureInfo.InvariantCulture) + "\">" + numberString + ".png</Graphic>"); sb.AppendLine("</Event>"); param.Saved = true; } } } return imagesSavedCount; }
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; } }