private string GetDefaultHeader() { SubtitleFormat format = new AdvancedSubStationAlpha(); var sub = new Subtitle(); string text = format.ToText(sub, string.Empty); var lines = text.SplitToLines(); format.LoadSubtitle(sub, lines, string.Empty); return(sub.Header.Trim()); }
public void AssSimpleFontSizeMultipleToText() { var target = new AdvancedSubStationAlpha(); var subtitle = new Subtitle(); subtitle.Paragraphs.Add(new Paragraph("<font size=\"1\">T</font><font size=\"2\">E</font><font size=\"3\">S</font><font size=\"4\">T</font>", 0, 2000)); var result = target.ToText(subtitle, ""); Assert.IsTrue(result.Contains(@"{\fs1}T{\fs2}E{\fs3}S{\fs4}T")); }
private void ButtonRemoveAll_Click(object sender, EventArgs e) { this.listViewStyles.Items.Clear(); var sub = new Subtitle(); if (this.isSubStationAlpha) { var ssa = new SubStationAlpha(); string text = ssa.ToText(sub, string.Empty); string[] lineArray = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); var lines = new List<string>(); foreach (string line in lineArray) { lines.Add(line); } ssa.LoadSubtitle(sub, lines, string.Empty); this.header = this.header.Remove(this.header.IndexOf("[V4 Styles]", StringComparison.Ordinal)) + sub.Header.Substring(sub.Header.IndexOf("[V4 Styles]", StringComparison.Ordinal)); } else { var ass = new AdvancedSubStationAlpha(); string text = ass.ToText(sub, string.Empty); string[] lineArray = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); var lines = new List<string>(); foreach (string line in lineArray) { lines.Add(line); } ass.LoadSubtitle(sub, lines, string.Empty); this.header = this.header.Remove(this.header.IndexOf("[V4+ Styles]", StringComparison.Ordinal)) + sub.Header.Substring(sub.Header.IndexOf("[V4+ Styles]", StringComparison.Ordinal)); } this.InitializeListView(); }
private void buttonOK_Click(object sender, EventArgs e) { _log = new StringBuilder(); buttonOK.Enabled = false; var oldFontSizeEnabled = numericUpDownFontSize.Enabled; numericUpDownFontSize.Enabled = false; using (var saveDialog = new SaveFileDialog { FileName = SuggestNewVideoFileName(), Filter = "MP4|*.mp4|Matroska|*.mkv|WebM|*.webm", AddExtension = true }) { if (saveDialog.ShowDialog(this) != DialogResult.OK) { buttonOK.Enabled = true; numericUpDownFontSize.Enabled = true; return; } VideoFileName = saveDialog.FileName; } if (File.Exists(VideoFileName)) { try { File.Delete(VideoFileName); } catch { MessageBox.Show($"Cannot overwrite video file { VideoFileName} - probably in use!"); buttonOK.Enabled = true; numericUpDownFontSize.Enabled = oldFontSizeEnabled; return; } } _totalFrames = (long)_videoInfo.TotalFrames; _log = new StringBuilder(); _log.AppendLine("Target file name: " + VideoFileName); _log.AppendLine("Video info width: " + _videoInfo.Width); _log.AppendLine("Video info width: " + _videoInfo.Height); _log.AppendLine("Video info total frames: " + _videoInfo.TotalFrames); _log.AppendLine("Video info total seconds: " + _videoInfo.TotalSeconds); labelFileName.Text = string.Format(LanguageSettings.Current.GenerateVideoWithBurnedInSubs.TargetFileName, VideoFileName); if (!_isAssa) { SetStyleForNonAssa(_assaSubtitle); } FixRightToLeft(_assaSubtitle); var format = new AdvancedSubStationAlpha(); var assaTempFileName = GetAssaFileName(_inputVideoFileName); FileUtil.WriteAllText(assaTempFileName, format.ToText(_assaSubtitle, null), new TextEncoding(Encoding.UTF8, "UTF8")); groupBoxSettings.Enabled = false; labelPleaseWait.Visible = true; if (_videoInfo.TotalFrames > 0) { progressBar1.Visible = true; } var stopWatch = Stopwatch.StartNew(); if (checkBoxTargetFileSize.Checked) { RunTwoPassEncoding(assaTempFileName); } else { RunOnePassEncoding(assaTempFileName); } progressBar1.Visible = false; labelPleaseWait.Visible = false; timer1.Stop(); MillisecondsEncoding = stopWatch.ElapsedMilliseconds; labelProgress.Text = string.Empty; groupBoxSettings.Enabled = true; try { File.Delete(assaTempFileName); } catch { // ignore } if (_abort) { DialogResult = DialogResult.Cancel; return; } if (!File.Exists(VideoFileName) || new FileInfo(VideoFileName).Length == 0) { SeLogger.Error(Environment.NewLine + "Generate hard subbed video failed: " + Environment.NewLine + _log); DialogResult = DialogResult.Cancel; return; } DialogResult = DialogResult.OK; }
private void buttonOK_Click(object sender, EventArgs e) { _log = new StringBuilder(); buttonOK.Enabled = false; numericUpDownFontSize.Enabled = false; using (var saveDialog = new SaveFileDialog { FileName = string.Empty, Filter = "MP4|*.mp4|Matroska|*.mkv|WebM|*.webm" }) { if (saveDialog.ShowDialog(this) != DialogResult.OK) { buttonOK.Enabled = true; numericUpDownFontSize.Enabled = true; return; } VideoFileName = saveDialog.FileName; } _totalFrames = (long)_videoInfo.TotalFrames; _log = new StringBuilder(); _log.AppendLine("Target file name: " + VideoFileName); _log.AppendLine("Video info width: " + _videoInfo.Width); _log.AppendLine("Video info width: " + _videoInfo.Height); _log.AppendLine("Video info total frames: " + _videoInfo.TotalFrames); _log.AppendLine("Video info total seconds: " + _videoInfo.TotalSeconds); if (File.Exists(VideoFileName)) { File.Delete(VideoFileName); } labelFileName.Text = string.Format(LanguageSettings.Current.GenerateVideoWithBurnedInSubs.TargetFileName, VideoFileName); if (numericUpDownFontSize.Visible) // not ASSA format { SetStyleForNonAssa(_assaSubtitle); } FixRightToLeft(_assaSubtitle); var format = new AdvancedSubStationAlpha(); var assaTempFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".ass"); File.WriteAllText(assaTempFileName, format.ToText(_assaSubtitle, null)); groupBoxSettings.Enabled = false; progressBar1.Maximum = (int)_videoInfo.TotalFrames; progressBar1.Visible = true; labelPleaseWait.Visible = true; if (checkBoxTargetFileSize.Checked) { RunTwoPassEncoding(assaTempFileName); } else { RunOnePassEncoding(assaTempFileName); } progressBar1.Visible = false; labelPleaseWait.Visible = false; timer1.Stop(); labelProgress.Text = string.Empty; groupBoxSettings.Enabled = true; try { File.Delete(assaTempFileName); } catch { // ignore } DialogResult = _abort ? DialogResult.Cancel : DialogResult.OK; }
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; }
private void TimerRenderTick(object sender, EventArgs e) { _progessBarSubtitle = new Subtitle(); var script = @"[Script Info] ; This is an Advanced Sub Station Alpha v4+script. ScriptType: v4.00+ ScaledBorderAndShadow: Yes PlayResX: [VIDEO_WIDTH] PlayResY: [VIDEO_HEIGHT] [V4+ Styles] Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding Style: SE-progress-bar-splitter,Arial,20,[TEXT_COLOR],&H0000FFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,0,0,7,0,0,0,1 Style: SE-progress-bar-bg,Arial,20,[FORE_COLOR],[BACK_COLOR],&H00FFFFFF,&H00000000,0,0,0,0,100,100,0,0,1,0,0,[ALIGNMENT],0,0,0,1 Style: SE-progress-bar-text,[FONT_NAME],[FONT_SIZE],[TEXT_COLOR],&H0000FFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,0,0,[TEXT_ALIGNMENT],0,0,0,1 [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: -255,0:00:00.00,0:43:00.00,SE-progress-bar-bg,,0,0,0,,[PB_DRAWING]"; script = script.Replace("[VIDEO_WIDTH]", _videoInfo.Width.ToString(CultureInfo.InvariantCulture)); script = script.Replace("[VIDEO_HEIGHT]", _videoInfo.Height.ToString(CultureInfo.InvariantCulture)); script = script.Replace("[FORE_COLOR]", AdvancedSubStationAlpha.GetSsaColorString(panelPrimaryColor.BackColor)); script = script.Replace("[BACK_COLOR]", AdvancedSubStationAlpha.GetSsaColorString(panelSecondaryColor.BackColor)); script = script.Replace("[TEXT_COLOR]", AdvancedSubStationAlpha.GetSsaColorString(panelTextColor.BackColor)); script = script.Replace("[FONT_SIZE]", numericUpDownFontSize.Value.ToString(CultureInfo.InvariantCulture)); script = script.Replace("[FONT_NAME]", comboBoxFontName.Text); var duration = (int)Math.Round(_videoInfo.TotalMilliseconds / 10.0); script = script.Replace("[PB_DRAWING]", GenerateProgressBar(_videoInfo, (int)numericUpDownHeight.Value, duration)); if (radioButtonPosTop.Checked) { script = script.Replace("[ALIGNMENT]", "7"); } else { script = script.Replace("[ALIGNMENT]", "1"); } if (comboBoxTextHorizontalAlignment.SelectedIndex == 1) { script = script.Replace("[TEXT_ALIGNMENT]", "5"); } else if (comboBoxTextHorizontalAlignment.SelectedIndex == 2) { script = script.Replace("[TEXT_ALIGNMENT]", "6"); } else { script = script.Replace("[TEXT_ALIGNMENT]", "4"); } new AdvancedSubStationAlpha().LoadSubtitle(_progessBarSubtitle, script.SplitToLines(), string.Empty); _progessBarSubtitle.Paragraphs[0].EndTime.TotalMilliseconds = _videoInfo.TotalMilliseconds; if (_chapters?.Paragraphs.Count > 0) { var layer = -254; using (var graphics = CreateGraphics()) { for (int i = 0; i < _chapters.Paragraphs.Count; i++) { Paragraph p = _chapters.Paragraphs[i]; var percentOfDuration = p.StartTime.TotalMilliseconds * 100.0 / _videoInfo.TotalMilliseconds; var position = (int)Math.Round(_videoInfo.Width * percentOfDuration / 100.0); var textPosition = GetTextPosition(position, p, i, percentOfDuration); string posTag; string splitterText; SizeF chapterSize; try { using (var font = new Font(comboBoxFontName.Text, (float)(numericUpDownFontSize.Value * 0.7m), FontStyle.Regular)) { chapterSize = graphics.MeasureString(p.Text, font); } } catch { using (var font = new Font(Font.Name, (float)(numericUpDownFontSize.Value * 0.7m), FontStyle.Regular)) { chapterSize = graphics.MeasureString(p.Text, font); } } if (radioButtonPosTop.Checked) { var top = (int)Math.Round((numericUpDownHeight.Value / 2.0m) + numericUpDownYAdjust.Value); posTag = $"{{\\pos({textPosition}, {top})}}"; var splitterTop = 0; if (numericUpDownSplitterHeight.Value < numericUpDownHeight.Value) { splitterTop += (int)Math.Round((numericUpDownHeight.Value - numericUpDownSplitterHeight.Value) / 2); } splitterText = $"{{\\p1}}m {position} {splitterTop} l " + // top left point $"{position + numericUpDownSplitterWidth.Value} {splitterTop} " + // top right point $"{position + numericUpDownSplitterWidth.Value} {splitterTop + numericUpDownSplitterHeight.Value} " + // bottom right point $"{position} {splitterTop + numericUpDownSplitterHeight.Value} " + // bottom left point $"{position} {splitterTop}" + // top left point $"{{\\p0}}"; } else { posTag = $"{{\\pos({textPosition}, {(int)Math.Round(_videoInfo.Height - (numericUpDownHeight.Value / 2.0m) + numericUpDownYAdjust.Value)})}}"; var splitterTop = _videoInfo.Height - numericUpDownHeight.Value; if (numericUpDownSplitterHeight.Value < numericUpDownHeight.Value) { splitterTop += (int)Math.Round((numericUpDownHeight.Value - numericUpDownSplitterHeight.Value) / 2); } splitterText = $"{{\\p1}}m {position} {splitterTop} l " + // top left point $"{position + numericUpDownSplitterWidth.Value} {splitterTop} " + // top right point $"{position + numericUpDownSplitterWidth.Value} {splitterTop + numericUpDownSplitterHeight.Value} " + // bottom right point $"{position} {splitterTop + numericUpDownSplitterHeight.Value} " + // bottom left point $"{position} {splitterTop}" + // top left point $"{{\\p0}}"; } if (i > 0) { var splitter = new Paragraph(splitterText, 0, _videoInfo.TotalMilliseconds) { Extra = "SE-progress-bar-splitter", Layer = layer, }; layer++; _progessBarSubtitle.Paragraphs.Add(splitter); } var chapterInfo = new Paragraph(posTag + p.Text, 0, _videoInfo.TotalMilliseconds) { Extra = "SE-progress-bar-text", Layer = -1, Actor = p.StartTime.TotalMilliseconds.ToString(CultureInfo.InvariantCulture), }; _progessBarSubtitle.Paragraphs.Add(chapterInfo); } } } var format = new AdvancedSubStationAlpha(); textBoxSource.Text = format.ToText(_progessBarSubtitle, string.Empty); var hashValue = _progessBarSubtitle.GetFastHashCode(string.Empty); if (hashValue != _oldHashValue) { _videoPlayerContainer.SetSubtitleText(string.Empty, new Paragraph(), _progessBarSubtitle, format); _oldHashValue = hashValue; } _videoPlayerContainer.RefreshProgressBar(); }