This commit is contained in:
niksedk 2023-03-11 03:19:44 +01:00
parent fabff607a1
commit 546674c5df
4 changed files with 241 additions and 22 deletions

View File

@ -34,6 +34,9 @@ namespace Nikse.SubtitleEdit.Forms
this.buttonCancel = new System.Windows.Forms.Button();
this.labelInputVideoFile = new System.Windows.Forms.Label();
this.groupBoxSettings = new System.Windows.Forms.GroupBox();
this.buttonSetLanguage = new System.Windows.Forms.Button();
this.buttonSetDefault = new System.Windows.Forms.Button();
this.buttonToggleForced = new System.Windows.Forms.Button();
this.buttonClear = new System.Windows.Forms.Button();
this.ButtonRemoveSubtitles = new System.Windows.Forms.Button();
this.ButtonMoveSubDown = new System.Windows.Forms.Button();
@ -54,6 +57,8 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripMenuItemStorageMoveUp = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemStorageMoveDown = new System.Windows.Forms.ToolStripMenuItem();
this.toggleForcedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toggleDefaultToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonOpenVideoFile = new System.Windows.Forms.Button();
this.textBoxInputFileName = new System.Windows.Forms.TextBox();
this.textBoxLog = new System.Windows.Forms.TextBox();
@ -72,9 +77,13 @@ namespace Nikse.SubtitleEdit.Forms
this.nTSC720x480ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.x352ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.x272ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStripForm = new System.Windows.Forms.ContextMenuStrip(this.components);
this.closeWindowAfterGenerateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.setLanguageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBoxSettings.SuspendLayout();
this.contextMenuSubtitles.SuspendLayout();
this.contextMenuStripRes.SuspendLayout();
this.contextMenuStripForm.SuspendLayout();
this.SuspendLayout();
//
// buttonGenerate
@ -116,6 +125,9 @@ namespace Nikse.SubtitleEdit.Forms
this.groupBoxSettings.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxSettings.Controls.Add(this.buttonSetLanguage);
this.groupBoxSettings.Controls.Add(this.buttonSetDefault);
this.groupBoxSettings.Controls.Add(this.buttonToggleForced);
this.groupBoxSettings.Controls.Add(this.buttonClear);
this.groupBoxSettings.Controls.Add(this.ButtonRemoveSubtitles);
this.groupBoxSettings.Controls.Add(this.ButtonMoveSubDown);
@ -132,12 +144,45 @@ namespace Nikse.SubtitleEdit.Forms
this.groupBoxSettings.TabIndex = 0;
this.groupBoxSettings.TabStop = false;
//
// buttonSetLanguage
//
this.buttonSetLanguage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonSetLanguage.Location = new System.Drawing.Point(717, 298);
this.buttonSetLanguage.Name = "buttonSetLanguage";
this.buttonSetLanguage.Size = new System.Drawing.Size(122, 23);
this.buttonSetLanguage.TabIndex = 35;
this.buttonSetLanguage.Text = "Set language...";
this.buttonSetLanguage.UseVisualStyleBackColor = true;
this.buttonSetLanguage.Click += new System.EventHandler(this.buttonSetLanguage_Click);
//
// buttonSetDefault
//
this.buttonSetDefault.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonSetDefault.Location = new System.Drawing.Point(717, 269);
this.buttonSetDefault.Name = "buttonSetDefault";
this.buttonSetDefault.Size = new System.Drawing.Size(122, 23);
this.buttonSetDefault.TabIndex = 34;
this.buttonSetDefault.Text = "Toggle default";
this.buttonSetDefault.UseVisualStyleBackColor = true;
this.buttonSetDefault.Click += new System.EventHandler(this.buttonSetDefault_Click);
//
// buttonToggleForced
//
this.buttonToggleForced.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonToggleForced.Location = new System.Drawing.Point(717, 240);
this.buttonToggleForced.Name = "buttonToggleForced";
this.buttonToggleForced.Size = new System.Drawing.Size(122, 23);
this.buttonToggleForced.TabIndex = 33;
this.buttonToggleForced.Text = "Toggle forced";
this.buttonToggleForced.UseVisualStyleBackColor = true;
this.buttonToggleForced.Click += new System.EventHandler(this.buttonToggleForced_Click);
//
// buttonClear
//
this.buttonClear.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonClear.Location = new System.Drawing.Point(747, 155);
this.buttonClear.Location = new System.Drawing.Point(717, 155);
this.buttonClear.Name = "buttonClear";
this.buttonClear.Size = new System.Drawing.Size(92, 23);
this.buttonClear.Size = new System.Drawing.Size(122, 23);
this.buttonClear.TabIndex = 30;
this.buttonClear.Text = "Remove all";
this.buttonClear.UseVisualStyleBackColor = true;
@ -146,9 +191,9 @@ namespace Nikse.SubtitleEdit.Forms
// ButtonRemoveSubtitles
//
this.ButtonRemoveSubtitles.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonRemoveSubtitles.Location = new System.Drawing.Point(748, 127);
this.ButtonRemoveSubtitles.Location = new System.Drawing.Point(717, 127);
this.ButtonRemoveSubtitles.Name = "ButtonRemoveSubtitles";
this.ButtonRemoveSubtitles.Size = new System.Drawing.Size(91, 23);
this.ButtonRemoveSubtitles.Size = new System.Drawing.Size(122, 23);
this.ButtonRemoveSubtitles.TabIndex = 29;
this.ButtonRemoveSubtitles.Text = "Remove";
this.ButtonRemoveSubtitles.UseVisualStyleBackColor = true;
@ -157,9 +202,9 @@ namespace Nikse.SubtitleEdit.Forms
// ButtonMoveSubDown
//
this.ButtonMoveSubDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonMoveSubDown.Location = new System.Drawing.Point(747, 211);
this.ButtonMoveSubDown.Location = new System.Drawing.Point(717, 211);
this.ButtonMoveSubDown.Name = "ButtonMoveSubDown";
this.ButtonMoveSubDown.Size = new System.Drawing.Size(92, 23);
this.ButtonMoveSubDown.Size = new System.Drawing.Size(122, 23);
this.ButtonMoveSubDown.TabIndex = 32;
this.ButtonMoveSubDown.Text = "Move down";
this.ButtonMoveSubDown.UseVisualStyleBackColor = true;
@ -168,9 +213,9 @@ namespace Nikse.SubtitleEdit.Forms
// ButtonMoveSubUp
//
this.ButtonMoveSubUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonMoveSubUp.Location = new System.Drawing.Point(748, 183);
this.ButtonMoveSubUp.Location = new System.Drawing.Point(717, 183);
this.ButtonMoveSubUp.Name = "ButtonMoveSubUp";
this.ButtonMoveSubUp.Size = new System.Drawing.Size(91, 23);
this.ButtonMoveSubUp.Size = new System.Drawing.Size(122, 23);
this.ButtonMoveSubUp.TabIndex = 31;
this.ButtonMoveSubUp.Text = "Move up";
this.ButtonMoveSubUp.UseVisualStyleBackColor = true;
@ -179,9 +224,9 @@ namespace Nikse.SubtitleEdit.Forms
// buttonAddSubtitles
//
this.buttonAddSubtitles.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAddSubtitles.Location = new System.Drawing.Point(748, 98);
this.buttonAddSubtitles.Location = new System.Drawing.Point(717, 98);
this.buttonAddSubtitles.Name = "buttonAddSubtitles";
this.buttonAddSubtitles.Size = new System.Drawing.Size(91, 23);
this.buttonAddSubtitles.Size = new System.Drawing.Size(122, 23);
this.buttonAddSubtitles.TabIndex = 28;
this.buttonAddSubtitles.Text = "Add...";
this.buttonAddSubtitles.UseVisualStyleBackColor = true;
@ -213,7 +258,7 @@ namespace Nikse.SubtitleEdit.Forms
this.listViewSubtitles.HideSelection = false;
this.listViewSubtitles.Location = new System.Drawing.Point(22, 98);
this.listViewSubtitles.Name = "listViewSubtitles";
this.listViewSubtitles.Size = new System.Drawing.Size(719, 281);
this.listViewSubtitles.Size = new System.Drawing.Size(689, 281);
this.listViewSubtitles.TabIndex = 25;
this.listViewSubtitles.UseCompatibleStateImageBehavior = false;
this.listViewSubtitles.View = System.Windows.Forms.View.Details;
@ -252,9 +297,12 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemStorageRemoveAll,
this.toolStripSeparator2,
this.toolStripMenuItemStorageMoveUp,
this.toolStripMenuItemStorageMoveDown});
this.toolStripMenuItemStorageMoveDown,
this.toggleForcedToolStripMenuItem,
this.toggleDefaultToolStripMenuItem,
this.setLanguageToolStripMenuItem});
this.contextMenuSubtitles.Name = "contextMenuStrip1";
this.contextMenuSubtitles.Size = new System.Drawing.Size(203, 126);
this.contextMenuSubtitles.Size = new System.Drawing.Size(203, 192);
//
// addToolStripMenuItem
//
@ -303,6 +351,21 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemStorageMoveDown.Text = "Move down";
this.toolStripMenuItemStorageMoveDown.Click += new System.EventHandler(this.ButtonMoveSubDown_Click);
//
// toggleForcedToolStripMenuItem
//
this.toggleForcedToolStripMenuItem.Name = "toggleForcedToolStripMenuItem";
this.toggleForcedToolStripMenuItem.Size = new System.Drawing.Size(202, 22);
this.toggleForcedToolStripMenuItem.Text = "Toggle forced";
this.toggleForcedToolStripMenuItem.Click += new System.EventHandler(this.buttonToggleForced_Click);
//
// toggleDefaultToolStripMenuItem
//
this.toggleDefaultToolStripMenuItem.Name = "toggleDefaultToolStripMenuItem";
this.toggleDefaultToolStripMenuItem.Size = new System.Drawing.Size(202, 22);
this.toggleDefaultToolStripMenuItem.Text = "Toggle default";
this.toggleDefaultToolStripMenuItem.DropDownOpening += new System.EventHandler(this.toggleDefaultToolStripMenuItem_DropDownOpening);
this.toggleDefaultToolStripMenuItem.Click += new System.EventHandler(this.buttonSetDefault_Click);
//
// buttonOpenVideoFile
//
this.buttonOpenVideoFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
@ -437,11 +500,35 @@ namespace Nikse.SubtitleEdit.Forms
this.x272ToolStripMenuItem.Size = new System.Drawing.Size(203, 22);
this.x272ToolStripMenuItem.Text = "640x272";
//
// contextMenuStripForm
//
this.contextMenuStripForm.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.closeWindowAfterGenerateToolStripMenuItem});
this.contextMenuStripForm.Name = "contextMenuStripForm";
this.contextMenuStripForm.Size = new System.Drawing.Size(225, 26);
//
// closeWindowAfterGenerateToolStripMenuItem
//
this.closeWindowAfterGenerateToolStripMenuItem.Checked = true;
this.closeWindowAfterGenerateToolStripMenuItem.CheckOnClick = true;
this.closeWindowAfterGenerateToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.closeWindowAfterGenerateToolStripMenuItem.Name = "closeWindowAfterGenerateToolStripMenuItem";
this.closeWindowAfterGenerateToolStripMenuItem.Size = new System.Drawing.Size(224, 22);
this.closeWindowAfterGenerateToolStripMenuItem.Text = "Close window after generate";
//
// setLanguageToolStripMenuItem
//
this.setLanguageToolStripMenuItem.Name = "setLanguageToolStripMenuItem";
this.setLanguageToolStripMenuItem.Size = new System.Drawing.Size(202, 22);
this.setLanguageToolStripMenuItem.Text = "Set language...";
this.setLanguageToolStripMenuItem.Click += new System.EventHandler(this.buttonSetLanguage_Click);
//
// GenerateVideoWithSoftSubs
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(869, 439);
this.ContextMenuStrip = this.contextMenuStripForm;
this.Controls.Add(this.groupBoxSettings);
this.Controls.Add(this.buttonGenerate);
this.Controls.Add(this.buttonCancel);
@ -461,6 +548,7 @@ namespace Nikse.SubtitleEdit.Forms
this.groupBoxSettings.PerformLayout();
this.contextMenuSubtitles.ResumeLayout(false);
this.contextMenuStripRes.ResumeLayout(false);
this.contextMenuStripForm.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -509,5 +597,13 @@ namespace Nikse.SubtitleEdit.Forms
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemStorageMoveUp;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemStorageMoveDown;
private System.Windows.Forms.Button buttonToggleForced;
private System.Windows.Forms.Button buttonSetDefault;
private System.Windows.Forms.ToolStripMenuItem toggleForcedToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem toggleDefaultToolStripMenuItem;
private System.Windows.Forms.ContextMenuStrip contextMenuStripForm;
private System.Windows.Forms.ToolStripMenuItem closeWindowAfterGenerateToolStripMenuItem;
private System.Windows.Forms.Button buttonSetLanguage;
private System.Windows.Forms.ToolStripMenuItem setLanguageToolStripMenuItem;
}
}

View File

@ -133,7 +133,7 @@ namespace Nikse.SubtitleEdit.Forms
Tag = sub.Tag,
Text = sub.Name,
};
item.SubItems.Add(sub.Language);
item.SubItems.Add(GetDisplayLanguage(sub.Language));
item.SubItems.Add(sub.IsDefault.ToString(CultureInfo.InvariantCulture));
item.SubItems.Add(sub.IsForced.ToString(CultureInfo.InvariantCulture));
item.SubItems.Add(sub.FileName);
@ -142,6 +142,22 @@ namespace Nikse.SubtitleEdit.Forms
_softSubs.Add(sub);
}
private static string GetDisplayLanguage(string language)
{
if (string.IsNullOrWhiteSpace(language))
{
return "Undefined";
}
var threeLetterCode = Iso639Dash2LanguageCode.GetThreeLetterCodeFromTwoLetterCode(language);
if (language.Length == 3)
{
threeLetterCode =language;
}
return Iso639Dash2LanguageCode.List.FirstOrDefault(p => p.ThreeLetterCode == threeLetterCode)?.EnglishName;
}
private void AddListViewItem(MatroskaTrackInfo track)
{
AddListViewItem(new VideoPreviewGeneratorSub
@ -282,7 +298,10 @@ namespace Nikse.SubtitleEdit.Forms
return;
}
DialogResult = DialogResult.OK;
if (closeWindowAfterGenerateToolStripMenuItem.Checked)
{
DialogResult = DialogResult.OK;
}
}
private static string GetAssaFileName(string inputVideoFileName)
@ -305,7 +324,7 @@ namespace Nikse.SubtitleEdit.Forms
{
var fileName = Path.GetFileNameWithoutExtension(_inputVideoFileName);
fileName += ".embed";
return fileName.Replace(".", "_") + ".mp4";
return fileName.Replace(".", "_") + ".mkv";
}
private void RunEmbedding()
@ -560,6 +579,30 @@ namespace Nikse.SubtitleEdit.Forms
listView.Items.Insert(idx, item);
}
private void MoveToTop(ListView listView)
{
if (listView.SelectedItems.Count != 1)
{
return;
}
var idx = listView.SelectedItems[0].Index;
if (idx == 0)
{
return;
}
var item = listView.SelectedItems[0];
listView.Items.RemoveAt(idx);
var style = _softSubs[idx];
_softSubs.RemoveAt(idx);
_softSubs.Insert(0, style);
idx = 0;
listView.Items.Insert(idx, item);
}
private void ButtonMoveSubUp_Click(object sender, EventArgs e)
{
MoveUp(listViewSubtitles);
@ -574,5 +617,53 @@ namespace Nikse.SubtitleEdit.Forms
{
listViewSubtitles.AutoSizeLastColumn();
}
private void buttonToggleForced_Click(object sender, EventArgs e)
{
if (listViewSubtitles.SelectedIndices.Count < 1)
{
return;
}
foreach (int index in listViewSubtitles.SelectedIndices)
{
_softSubs[index].IsForced = !_softSubs[index].IsForced;
listViewSubtitles.Items[index].SubItems[3].Text = _softSubs[index].IsForced.ToString(CultureInfo.InvariantCulture);
}
}
private void buttonSetDefault_Click(object sender, EventArgs e)
{
if (listViewSubtitles.SelectedIndices.Count != 1)
{
return;
}
var selectedIndex = listViewSubtitles.SelectedItems[0].Index;
if (_softSubs[selectedIndex].IsDefault)
{
_softSubs[selectedIndex].IsDefault = false;
listViewSubtitles.Items[selectedIndex].SubItems[2].Text = _softSubs[selectedIndex].IsDefault.ToString(CultureInfo.InvariantCulture);
return;
}
for (var index = 0; index < listViewSubtitles.Items.Count; index++)
{
_softSubs[index].IsDefault = index == selectedIndex;
listViewSubtitles.Items[index].SubItems[2].Text = _softSubs[index].IsDefault.ToString(CultureInfo.InvariantCulture);
}
MoveToTop(listViewSubtitles);
}
private void toggleDefaultToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
{
toggleDefaultToolStripMenuItem.Visible = listViewSubtitles.SelectedIndices.Count == 1;
}
private void buttonSetLanguage_Click(object sender, EventArgs e)
{
}
}
}

View File

@ -123,4 +123,7 @@
<metadata name="contextMenuStripRes.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>104, 17</value>
</metadata>
<metadata name="contextMenuStripForm.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>442, 17</value>
</metadata>
</root>

View File

@ -4,6 +4,7 @@ using Nikse.SubtitleEdit.Forms;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Eventing.Reader;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
@ -275,15 +276,15 @@ namespace Nikse.SubtitleEdit.Logic
var subsMap = string.Empty;
var subsMeta = string.Empty;
var subsFormat = string.Empty;
var count = 0;
//TODO: check number of audio + video tracks!
var ffmpegInfo = FfmpegMediaInfo.Parse(inputVideoFileName);
var videoTrackCount = ffmpegInfo.Tracks.Count(p => p.TrackType == FfmpegTrackType.Video);
var audioTrackCount = ffmpegInfo.Tracks.Count(p => p.TrackType == FfmpegTrackType.Audio);
var isMp4 = inputVideoFileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase);
var isMp4 = outputVideoFileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase);
var count = 0;
foreach (var softSub in softSubs)
{
count++;
@ -292,7 +293,35 @@ namespace Nikse.SubtitleEdit.Logic
if (!string.IsNullOrEmpty(softSub.Language))
{
subsMeta += $" -metadata:s:s:{count} language={softSub.Language}";
var threeLetterCode = Iso639Dash2LanguageCode.GetThreeLetterCodeFromTwoLetterCode(softSub.Language);
if (softSub.Language.Length == 3)
{
threeLetterCode = softSub.Language;
}
var languageName = Iso639Dash2LanguageCode.List.FirstOrDefault(p => p.TwoLetterCode == softSub.Language)?.EnglishName;
if (!string.IsNullOrEmpty(threeLetterCode) && !string.IsNullOrEmpty(languageName))
{
subsMeta += $" -metadata:s:s:{count - 1} language=\"{threeLetterCode}\"";
subsMeta += $" -metadata:s:s:{count - 1} title=\"{languageName}\"";
}
else
{
subsMeta += $" -metadata:s:s:{count - 1} language=\"{softSub.Language}\"";
subsMeta += $" -metadata:s:s:{count - 1} title=\"{softSub.Language}\"";
}
}
if (softSub.IsDefault)
{
subsMeta += $" -disposition:s:s:{count - 1} default";
}
if (softSub.IsForced)
{
subsMeta += $" -disposition:s:s:{count - 1} forced";
subsMeta += $" -metadata:s:s:{count - 1} forced=1";
}
if (isMp4)
@ -301,16 +330,16 @@ namespace Nikse.SubtitleEdit.Logic
}
else if (softSub.SubtitleFormat.GetType() == typeof(SubRip))
{
subsFormat += $" -c:s:s:{count} srt";
subsFormat += $" -c:s:s:{count - 1} srt";
}
else if (softSub.SubtitleFormat.GetType() == typeof(AdvancedSubStationAlpha))
{
subsFormat += $" -c:s:s:{count} ass";
subsFormat += $" -c:s:s:{count - 1} ass";
}
else if (softSub.SubtitleFormat.GetType() == typeof(WebVTT) ||
softSub.SubtitleFormat.GetType() == typeof(WebVTTFileWithLineNumber))
{
subsFormat += $" -c:s:s:{count} webvtt";
subsFormat += $" -c:s:s:{count - 1} webvtt";
}
}