private void SetPosition_Shown(object sender, EventArgs e) { ShowStyleAlignment(); ShowCurrentPosition(); var playResX = AdvancedSubStationAlpha.GetTagFromHeader("PlayResX", "[Script Info]", _subtitleWithNewHeader.Header); var playResY = AdvancedSubStationAlpha.GetTagFromHeader("PlayResY", "[Script Info]", _subtitleWithNewHeader.Header); if (string.IsNullOrEmpty(playResX) || string.IsNullOrEmpty(playResY)) { var dialogResult = MessageBox.Show(LanguageSettings.Current.AssaSetPosition.ResolutionMissing, "Subtitle Edit", MessageBoxButtons.YesNoCancel); if (dialogResult == DialogResult.OK || dialogResult == DialogResult.Yes) { if (string.IsNullOrEmpty(_subtitleWithNewHeader.Header)) { _subtitleWithNewHeader.Header = AdvancedSubStationAlpha.DefaultHeader; } _subtitleWithNewHeader.Header = AdvancedSubStationAlpha.AddTagToHeader("PlayResX", "PlayResX: " + _videoInfo.Width.ToString(CultureInfo.InvariantCulture), "[Script Info]", _subtitleWithNewHeader.Header); _subtitleWithNewHeader.Header = AdvancedSubStationAlpha.AddTagToHeader("PlayResY", "PlayResY: " + _videoInfo.Height.ToString(CultureInfo.InvariantCulture), "[Script Info]", _subtitleWithNewHeader.Header); } } GeneratePreviewViaMpv(); _loading = false; }
private void SetStyleForNonAssa(Subtitle sub) { sub.Header = AdvancedSubStationAlpha.DefaultHeader; var style = AdvancedSubStationAlpha.GetSsaStyle("Default", sub.Header); style.FontSize = numericUpDownFontSize.Value; style.FontName = comboBoxSubtitleFont.Text; style.Background = Color.FromArgb(150, 0, 0, 0); if (checkBoxAlignRight.Checked) { style.Alignment = "3"; } if (checkBoxBox.Checked) { style.BorderStyle = "4"; // box - multi line style.ShadowWidth = 5; } sub.Header = AdvancedSubStationAlpha.GetHeaderAndStylesFromAdvancedSubStationAlpha(sub.Header, new System.Collections.Generic.List <SsaStyle>() { style }); sub.Header = AdvancedSubStationAlpha.AddTagToHeader("PlayResX", "PlayResX: " + ((int)numericUpDownWidth.Value).ToString(CultureInfo.InvariantCulture), "[Script Info]", sub.Header); sub.Header = AdvancedSubStationAlpha.AddTagToHeader("PlayResY", "PlayResY: " + ((int)numericUpDownHeight.Value).ToString(CultureInfo.InvariantCulture), "[Script Info]", sub.Header); }
private void buttonOK_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(_subtitle.Header)) { _subtitle.Header = AdvancedSubStationAlpha.DefaultHeader; } var newStyles = AdvancedSubStationAlpha.GetSsaStylesFromHeader(_progessBarSubtitle.Header); var ignoreStyleNames = new List <string> { "SE-progress-bar-text", "SE-progress-bar-splitter", "SE-progress-bar-bg" }; var styles = AdvancedSubStationAlpha.GetSsaStylesFromHeader(_subtitle.Header).Where(p => !ignoreStyleNames.Contains(p.Name)).ToList(); styles.AddRange(newStyles); _subtitle.Header = AdvancedSubStationAlpha.GetHeaderAndStylesFromAdvancedSubStationAlpha(_subtitle.Header, styles); for (int i = _subtitle.Paragraphs.Count - 1; i >= 0; i--) { if (ignoreStyleNames.Contains(_subtitle.Paragraphs[i].Extra)) { _subtitle.Paragraphs.RemoveAt(i); } } _subtitle.Paragraphs.AddRange(_progessBarSubtitle.Paragraphs); if (_videoInfo != null && _videoInfo.Width > 0 && _videoInfo.Height > 0) { _subtitle.Header = AdvancedSubStationAlpha.AddTagToHeader("PlayResX", "PlayResX: " + _videoInfo.Width.ToString(CultureInfo.InvariantCulture), "[Script Info]", _subtitle.Header); _subtitle.Header = AdvancedSubStationAlpha.AddTagToHeader("PlayResY", "PlayResY: " + _videoInfo.Height.ToString(CultureInfo.InvariantCulture), "[Script Info]", _subtitle.Header); } Configuration.Settings.Tools.AssaProgressBarForeColor = panelPrimaryColor.BackColor; Configuration.Settings.Tools.AssaProgressBarBackColor = panelSecondaryColor.BackColor; Configuration.Settings.Tools.AssaProgressBarTextColor = panelTextColor.BackColor; Configuration.Settings.Tools.AssaProgressBarHeight = (int)numericUpDownHeight.Value; Configuration.Settings.Tools.AssaProgressBarSplitterWidth = (int)numericUpDownSplitterWidth.Value; Configuration.Settings.Tools.AssaProgressBarSplitterHeight = (int)numericUpDownSplitterHeight.Value; Configuration.Settings.Tools.AssaProgressBarFontName = comboBoxFontName.Text; Configuration.Settings.Tools.AssaProgressBarFontSize = (int)numericUpDownFontSize.Value; if (comboBoxTextHorizontalAlignment.SelectedIndex == 1) { Configuration.Settings.Tools.AssaProgressBarTextAlign = "center"; } else if (comboBoxTextHorizontalAlignment.SelectedIndex == 2) { Configuration.Settings.Tools.AssaProgressBarTextAlign = "right"; } else { Configuration.Settings.Tools.AssaProgressBarTextAlign = "left"; } DialogResult = DialogResult.OK; }
private void buttonOK_Click(object sender, EventArgs e) { if (!checkBoxMargins.Checked && !checkBoxFontSize.Checked && !checkBoxPosition.Checked && !checkBoxDrawing.Checked) { return; } if (string.IsNullOrEmpty(_subtitle.Header)) { _subtitle.Header = AdvancedSubStationAlpha.DefaultHeader; } var sourceWidth = numericUpDownSourceWidth.Value; var sourceHeight = numericUpDownSourceHeight.Value; var targetWidth = numericUpDownTargetWidth.Value; var targetHeight = numericUpDownTargetHeight.Value; if (sourceWidth == 0 || sourceHeight == 0 || targetWidth == 0 || targetHeight == 0) { MessageBox.Show("Video width/height cannot be zero"); return; } if (sourceWidth == targetWidth && sourceHeight == targetHeight) { MessageBox.Show("Source and target resolution is the same - nothing to do."); return; } var fixMargins = checkBoxMargins.Checked; var fixFonts = checkBoxFontSize.Checked; var fixPos = checkBoxPosition.Checked; var fixDraw = checkBoxDrawing.Checked; var styles = AdvancedSubStationAlpha.GetSsaStylesFromHeader(_subtitle.Header); foreach (var style in styles) { if (fixMargins) { style.MarginLeft = AssaResampler.Resample(sourceWidth, targetWidth, style.MarginLeft); style.MarginRight = AssaResampler.Resample(sourceWidth, targetWidth, style.MarginRight); style.MarginVertical = AssaResampler.Resample(sourceHeight, targetHeight, style.MarginVertical); } if (fixFonts) { style.FontSize = AssaResampler.Resample(sourceHeight, targetHeight, style.FontSize); } if (fixFonts || fixDraw) { style.OutlineWidth = (decimal)AssaResampler.Resample(sourceHeight, targetHeight, (float)style.OutlineWidth); style.ShadowWidth = (decimal)AssaResampler.Resample(sourceHeight, targetHeight, (float)style.ShadowWidth); style.Spacing = (decimal)AssaResampler.Resample(sourceWidth, targetWidth, (float)style.Spacing); } } _subtitle.Header = AdvancedSubStationAlpha.GetHeaderAndStylesFromAdvancedSubStationAlpha(_subtitle.Header, styles); _subtitle.Header = AdvancedSubStationAlpha.AddTagToHeader("PlayResX", "PlayResX: " + targetWidth.ToString(CultureInfo.InvariantCulture), "[Script Info]", _subtitle.Header); _subtitle.Header = AdvancedSubStationAlpha.AddTagToHeader("PlayResY", "PlayResY: " + targetHeight.ToString(CultureInfo.InvariantCulture), "[Script Info]", _subtitle.Header); foreach (var p in _subtitle.Paragraphs) { if (fixFonts) { p.Text = AssaResampler.ResampleOverrideTagsFont(sourceWidth, targetWidth, sourceHeight, targetHeight, p.Text); } if (fixPos) { p.Text = AssaResampler.ResampleOverrideTagsPosition(sourceWidth, targetWidth, sourceHeight, targetHeight, p.Text); } if (fixDraw) { p.Text = AssaResampler.ResampleOverrideTagsDrawing(sourceWidth, targetWidth, sourceHeight, targetHeight, p.Text, null); } } DialogResult = DialogResult.OK; }
private void SortAndLoad() { JoinedFormat = new SubRip(); // default subtitle format string header = null; SubtitleFormat lastFormat = null; var subtitles = new List <Subtitle>(); for (int k = 0; k < _fileNamesToJoin.Count; k++) { var fileName = _fileNamesToJoin[k]; try { var sub = new Subtitle(); SubtitleFormat format = null; if (fileName.EndsWith(".ismt", StringComparison.InvariantCultureIgnoreCase) || fileName.EndsWith(".mp4", StringComparison.InvariantCultureIgnoreCase) || fileName.EndsWith(".m4v", StringComparison.InvariantCultureIgnoreCase) || fileName.EndsWith(".3gp", StringComparison.InvariantCultureIgnoreCase)) { format = new IsmtDfxp(); if (format.IsMine(null, fileName)) { var s = new Subtitle(); format.LoadSubtitle(s, null, fileName); if (s.Paragraphs.Count > 0) { lastFormat = format; } } } var lines = FileUtil.ReadAllLinesShared(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)); if (lastFormat != null && lastFormat.IsMine(lines, fileName)) { format = lastFormat; format.LoadSubtitle(sub, lines, fileName); } if (sub.Paragraphs.Count == 0 || format == null) { format = sub.LoadSubtitle(fileName, out _, null); } if (format == null && lines.Count > 0 && lines.Count < 10 && lines[0].Trim() == "WEBVTT") { format = new WebVTT(); // empty WebVTT } if (format == null) { foreach (var binaryFormat in SubtitleFormat.GetBinaryFormats(true)) { if (binaryFormat.IsMine(null, fileName)) { binaryFormat.LoadSubtitle(sub, null, fileName); format = binaryFormat; break; } } } if (format == null) { foreach (var f in SubtitleFormat.GetTextOtherFormats()) { if (f.IsMine(lines, fileName)) { f.LoadSubtitle(sub, lines, fileName); format = f; break; } } } if (format == null) { Revert(k, LanguageSettings.Current.UnknownSubtitle.Title + Environment.NewLine + fileName); break; } if (sub.Header != null) { if (format.Name == AdvancedSubStationAlpha.NameOfFormat && header != null) { var oldPlayResX = AdvancedSubStationAlpha.GetTagFromHeader("PlayResX", "[Script Info]", header); var oldPlayResY = AdvancedSubStationAlpha.GetTagFromHeader("PlayResY", "[Script Info]", header); var newPlayResX = AdvancedSubStationAlpha.GetTagFromHeader("PlayResX", "[Script Info]", sub.Header); var newPlayResY = AdvancedSubStationAlpha.GetTagFromHeader("PlayResY", "[Script Info]", sub.Header); var stylesInHeader = AdvancedSubStationAlpha.GetStylesFromHeader(header); var styles = new List <SsaStyle>(); foreach (var styleName in stylesInHeader) { styles.Add(AdvancedSubStationAlpha.GetSsaStyle(styleName, header)); } foreach (var newStyle in AdvancedSubStationAlpha.GetStylesFromHeader(sub.Header)) { if (stylesInHeader.Any(p => p == newStyle)) { var styleToBeRenamed = AdvancedSubStationAlpha.GetSsaStyle(newStyle, sub.Header); var newName = styleToBeRenamed.Name + "_" + Guid.NewGuid(); foreach (var p in sub.Paragraphs.Where(p => p.Extra == styleToBeRenamed.Name)) { p.Extra = newName; } styleToBeRenamed.Name = newName; styles.Add(styleToBeRenamed); } else { styles.Add(AdvancedSubStationAlpha.GetSsaStyle(newStyle, sub.Header)); } } header = AdvancedSubStationAlpha.GetHeaderAndStylesFromAdvancedSubStationAlpha(header, styles); if (!string.IsNullOrEmpty(oldPlayResX) && string.IsNullOrEmpty(newPlayResX)) { header = AdvancedSubStationAlpha.AddTagToHeader("PlayResX", oldPlayResX, "[Script Info]", header); } if (!string.IsNullOrEmpty(oldPlayResY) && string.IsNullOrEmpty(newPlayResY)) { header = AdvancedSubStationAlpha.AddTagToHeader("PlayResY", oldPlayResY, "[Script Info]", header); } } else { header = sub.Header; } } lastFormat = lastFormat == null || lastFormat.FriendlyName == format.FriendlyName ? format : new SubRip(); subtitles.Add(sub); } catch (Exception exception) { Revert(k, exception.Message); return; } } JoinedFormat = lastFormat; if (!radioButtonJoinAddTime.Checked) { for (int outer = 0; outer < subtitles.Count; outer++) { for (int inner = 1; inner < subtitles.Count; inner++) { var a = subtitles[inner - 1]; var b = subtitles[inner]; if (a.Paragraphs.Count > 0 && b.Paragraphs.Count > 0 && a.Paragraphs[0].StartTime.TotalMilliseconds > b.Paragraphs[0].StartTime.TotalMilliseconds) { var t1 = _fileNamesToJoin[inner - 1]; _fileNamesToJoin[inner - 1] = _fileNamesToJoin[inner]; _fileNamesToJoin[inner] = t1; var t2 = subtitles[inner - 1]; subtitles[inner - 1] = subtitles[inner]; subtitles[inner] = t2; } } } } listViewParts.BeginUpdate(); listViewParts.Items.Clear(); int i = 0; foreach (var fileName in _fileNamesToJoin) { var sub = subtitles[i]; var lvi = new ListViewItem($"{sub.Paragraphs.Count:#,###,###}"); if (sub.Paragraphs.Count > 0) { lvi.SubItems.Add(sub.Paragraphs[0].StartTime.ToString()); lvi.SubItems.Add(sub.Paragraphs[sub.Paragraphs.Count - 1].StartTime.ToString()); } else { lvi.SubItems.Add("-"); lvi.SubItems.Add("-"); } lvi.SubItems.Add(fileName); listViewParts.Items.Add(lvi); i++; } listViewParts.EndUpdate(); JoinedSubtitle = new Subtitle(); if (JoinedFormat != null && JoinedFormat.FriendlyName != SubRip.NameOfFormat) { JoinedSubtitle.Header = header; } var addTime = radioButtonJoinAddTime.Checked; foreach (var sub in subtitles) { double addMs = 0; if (addTime && JoinedSubtitle.Paragraphs.Count > 0) { addMs = JoinedSubtitle.Paragraphs.Last().EndTime.TotalMilliseconds + Convert.ToDouble(numericUpDownAddMs.Value); } foreach (var p in sub.Paragraphs) { p.StartTime.TotalMilliseconds += addMs; p.EndTime.TotalMilliseconds += addMs; JoinedSubtitle.Paragraphs.Add(p); } } JoinedSubtitle.Renumber(); labelTotalLines.Text = string.Format(LanguageSettings.Current.JoinSubtitles.TotalNumberOfLinesX, JoinedSubtitle.Paragraphs.Count); }
private void buttonOK_Click(object sender, EventArgs e) { buttonOK.Enabled = false; using (var saveDialog = new SaveFileDialog { FileName = string.Empty, Filter = "MP4|*.mp4|Matroska|*.mkv|WebM|*.webm" }) { if (saveDialog.ShowDialog(this) != DialogResult.OK) { return; } VideoFileName = saveDialog.FileName; } if (File.Exists(VideoFileName)) { File.Delete(VideoFileName); } if (numericUpDownFontSize.Visible) { var fontSize = (int)numericUpDownFontSize.Value; var style = AdvancedSubStationAlpha.GetSsaStyle("Default", _assaSubtitle.Header); style.FontSize = fontSize; var styleLine = style.ToRawAss(); _assaSubtitle.Header = AdvancedSubStationAlpha.AddTagToHeader("Style", styleLine, "[V4+ Styles]", _assaSubtitle.Header); } if (Configuration.Settings.General.RightToLeftMode && LanguageAutoDetect.CouldBeRightToLeftLanguage(_assaSubtitle)) { for (var index = 0; index < _assaSubtitle.Paragraphs.Count; index++) { var paragraph = _assaSubtitle.Paragraphs[index]; if (LanguageAutoDetect.ContainsRightToLeftLetter(paragraph.Text)) { paragraph.Text = Utilities.FixRtlViaUnicodeChars(paragraph.Text); } } } SubtitleFormat format = new AdvancedSubStationAlpha(); var assaTempFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".ass"); File.WriteAllText(assaTempFileName, format.ToText(_assaSubtitle, null)); progressBar1.Style = ProgressBarStyle.Marquee; progressBar1.Visible = true; labelPleaseWait.Visible = true; var process = VideoPreviewGenerator.GenerateHardcodedVideoFile( _inputVideoFileName, assaTempFileName, VideoFileName); process.Start(); while (!process.HasExited) { System.Threading.Thread.Sleep(100); Application.DoEvents(); if (_abort) { process.Kill(); } } progressBar1.Visible = false; labelPleaseWait.Visible = false; try { File.Delete(assaTempFileName); } catch { // ignore } DialogResult = _abort ? DialogResult.Cancel : DialogResult.OK; }