Add force stereo

This commit is contained in:
Nikolaj Olsson 2024-05-10 15:39:55 +02:00
parent 6b0270eaf5
commit 13c9c4cdbe
3 changed files with 26 additions and 8 deletions

View File

@ -35,6 +35,7 @@
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.labelEngine = new System.Windows.Forms.Label();
this.groupBoxSettings = new System.Windows.Forms.GroupBox();
this.checkBoxForceStereo = new System.Windows.Forms.CheckBox();
this.labelRegion = new System.Windows.Forms.Label();
this.nikseComboBoxRegion = new Nikse.SubtitleEdit.Controls.NikseComboBox();
this.labelVoiceCount = new System.Windows.Forms.Label();
@ -117,6 +118,7 @@
//
this.groupBoxSettings.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.groupBoxSettings.Controls.Add(this.checkBoxForceStereo);
this.groupBoxSettings.Controls.Add(this.labelRegion);
this.groupBoxSettings.Controls.Add(this.nikseComboBoxRegion);
this.groupBoxSettings.Controls.Add(this.labelVoiceCount);
@ -137,6 +139,19 @@
this.groupBoxSettings.TabStop = false;
this.groupBoxSettings.Text = "Settings";
//
// checkBoxForceStereo
//
this.checkBoxForceStereo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.checkBoxForceStereo.AutoSize = true;
this.checkBoxForceStereo.Checked = true;
this.checkBoxForceStereo.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxForceStereo.Location = new System.Drawing.Point(34, 382);
this.checkBoxForceStereo.Name = "checkBoxForceStereo";
this.checkBoxForceStereo.Size = new System.Drawing.Size(85, 17);
this.checkBoxForceStereo.TabIndex = 33;
this.checkBoxForceStereo.Text = "Force stereo";
this.checkBoxForceStereo.UseVisualStyleBackColor = true;
//
// labelRegion
//
this.labelRegion.AutoSize = true;
@ -188,7 +203,7 @@
this.checkBoxShowPreview.AutoSize = true;
this.checkBoxShowPreview.Checked = true;
this.checkBoxShowPreview.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxShowPreview.Location = new System.Drawing.Point(17, 350);
this.checkBoxShowPreview.Location = new System.Drawing.Point(17, 335);
this.checkBoxShowPreview.Name = "checkBoxShowPreview";
this.checkBoxShowPreview.Size = new System.Drawing.Size(115, 17);
this.checkBoxShowPreview.TabIndex = 25;
@ -243,7 +258,7 @@
this.checkBoxAddToVideoFile.AutoSize = true;
this.checkBoxAddToVideoFile.Checked = true;
this.checkBoxAddToVideoFile.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxAddToVideoFile.Location = new System.Drawing.Point(17, 373);
this.checkBoxAddToVideoFile.Location = new System.Drawing.Point(17, 358);
this.checkBoxAddToVideoFile.Name = "checkBoxAddToVideoFile";
this.checkBoxAddToVideoFile.Size = new System.Drawing.Size(176, 17);
this.checkBoxAddToVideoFile.TabIndex = 26;
@ -446,5 +461,6 @@
private Controls.NikseComboBox nikseComboBoxRegion;
private System.Windows.Forms.ContextMenuStrip contextMenuStripVoices;
private System.Windows.Forms.ToolStripMenuItem refreshVoicesToolStripMenuItem;
private System.Windows.Forms.CheckBox checkBoxForceStereo;
}
}

View File

@ -181,6 +181,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
checkBoxShowPreview.Checked = Configuration.Settings.Tools.TextToSpeechPreview;
checkBoxAddToVideoFile.Enabled = _videoFileName != null;
checkBoxForceStereo.Enabled = _videoFileName != null;
}
private void SetActor(ActorAndVoice actor)
@ -215,7 +216,6 @@ namespace Nikse.SubtitleEdit.Forms.Tts
private void ButtonGenerateTtsClick(object sender, EventArgs e)
{
if (buttonGenerateTTS.Text == LanguageSettings.Current.General.Cancel)
{
buttonGenerateTTS.Enabled = false;
@ -297,7 +297,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
if (checkBoxAddToVideoFile.Checked && _videoFileName != null)
{
AddAudioToVideoFile(resultAudioFileName);
AddAudioToVideoFile(resultAudioFileName, checkBoxForceStereo.Checked);
if (_abort)
{
HandleAbort();
@ -378,7 +378,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
return false;
}
private void AddAudioToVideoFile(string audioFileName)
private void AddAudioToVideoFile(string audioFileName, bool forceStereo)
{
var videoExt = ".mkv";
if (_videoFileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase))
@ -388,7 +388,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
labelProgress.Text = "Add audio to video file...";
var outputFileName = Path.Combine(_waveFolder, Path.GetFileNameWithoutExtension(audioFileName) + videoExt);
var addAudioProcess = VideoPreviewGenerator.AddAudioTrack(_videoFileName, audioFileName, outputFileName);
var addAudioProcess = VideoPreviewGenerator.AddAudioTrack(_videoFileName, audioFileName, outputFileName, forceStereo);
addAudioProcess.Start();
while (!addAudioProcess.HasExited)
{

View File

@ -626,14 +626,16 @@ namespace Nikse.SubtitleEdit.Logic
return processMakeVideo;
}
public static Process AddAudioTrack(string inputFileName, string audioFileName, string outputFileName, DataReceivedEventHandler dataReceivedHandler = null)
public static Process AddAudioTrack(string inputFileName, string audioFileName, string outputFileName, bool forceStereo, DataReceivedEventHandler dataReceivedHandler = null)
{
var ac2 = forceStereo ? " -ac 2 " : " ";
var processMakeVideo = new Process
{
StartInfo =
{
FileName = GetFfmpegLocation(),
Arguments = $"-i \"{inputFileName}\" -i \"{audioFileName}\" -c copy -map 0:v:0 -map 1:a:0 \"{outputFileName}\"",
Arguments = $"-i \"{inputFileName}\" -i \"{audioFileName}\" -c copy -map 0:v:0 -map 1:a:0{ac2}\"{outputFileName}\"",
UseShellExecute = false,
CreateNoWindow = true
}