private void buttonRipWave_Click(object sender, EventArgs e) { if (listViewInputFiles.Items.Count == 0) { MessageBox.Show(Configuration.Settings.Language.BatchConvert.NothingToConvert); return; } _converting = true; buttonRipWave.Enabled = false; progressBar1.Style = ProgressBarStyle.Blocks; progressBar1.Maximum = listViewInputFiles.Items.Count; progressBar1.Value = 0; progressBar1.Visible = progressBar1.Maximum > 2; buttonInputBrowse.Enabled = false; buttonSearchFolder.Enabled = false; _abort = false; listViewInputFiles.BeginUpdate(); foreach (ListViewItem item in listViewInputFiles.Items) { item.SubItems[3].Text = "-"; } listViewInputFiles.EndUpdate(); Refresh(); int index = 0; while (index < listViewInputFiles.Items.Count && _abort == false) { var item = listViewInputFiles.Items[index]; item.SubItems[3].Text = Configuration.Settings.Language.AddWaveformBatch.ExtractingAudio; string fileName = item.Text; try { string targetFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".wav"); Process process; try { string encoderName; process = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out encoderName); labelInfo.Text = encoderName; } catch (DllNotFoundException) { if (MessageBox.Show(Configuration.Settings.Language.AddWaveform.VlcMediaPlayerNotFound + Environment.NewLine + Environment.NewLine + Configuration.Settings.Language.AddWaveform.GoToVlcMediaPlayerHomePage, Configuration.Settings.Language.AddWaveform.VlcMediaPlayerNotFoundTitle, MessageBoxButtons.YesNo) == DialogResult.Yes) { Process.Start("http://www.videolan.org/"); } buttonRipWave.Enabled = true; return; } process.Start(); while (!process.HasExited && !_abort) { Application.DoEvents(); } // check for delay in matroska files var audioTrackNames = new List <string>(); var mkvAudioTrackNumbers = new Dictionary <int, int>(); if (fileName.ToLower().EndsWith(".mkv", StringComparison.OrdinalIgnoreCase)) { MatroskaFile matroska = null; try { matroska = new MatroskaFile(fileName); if (matroska.IsValid) { foreach (var track in matroska.GetTracks()) { if (track.IsAudio) { if (track.CodecId != null && track.Language != null) { audioTrackNames.Add("#" + track.TrackNumber + ": " + track.CodecId.Replace("\0", string.Empty) + " - " + track.Language.Replace("\0", string.Empty)); } else { audioTrackNames.Add("#" + track.TrackNumber); } mkvAudioTrackNumbers.Add(mkvAudioTrackNumbers.Count, track.TrackNumber); } } if (mkvAudioTrackNumbers.Count > 0) { _delayInMilliseconds = (int)matroska.GetTrackStartTime(mkvAudioTrackNumbers[0]); } } } catch { _delayInMilliseconds = 0; } finally { if (matroska != null) { matroska.Dispose(); } } } item.SubItems[3].Text = Configuration.Settings.Language.AddWaveformBatch.Calculating; MakeWaveformAndSpectrogram(fileName, targetFile, _delayInMilliseconds); // cleanup try { File.Delete(targetFile); } catch { // don't show error about unsuccessful delete } IncrementAndShowProgress(); item.SubItems[3].Text = Configuration.Settings.Language.AddWaveformBatch.Done; } catch { IncrementAndShowProgress(); item.SubItems[3].Text = "ERROR"; } index++; } _converting = false; labelProgress.Text = string.Empty; labelInfo.Text = string.Empty; progressBar1.Visible = false; TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress); buttonRipWave.Enabled = true; buttonInputBrowse.Enabled = true; buttonSearchFolder.Enabled = true; }
private void buttonRipWave_Click(object sender, EventArgs e) { if (listViewInputFiles.Items.Count == 0) { MessageBox.Show(LanguageSettings.Current.BatchConvert.NothingToConvert); return; } _converting = true; buttonRipWave.Enabled = false; progressBar1.Style = ProgressBarStyle.Blocks; progressBar1.Maximum = listViewInputFiles.Items.Count; progressBar1.Value = 0; progressBar1.Visible = progressBar1.Maximum > 2; buttonInputBrowse.Enabled = false; buttonSearchFolder.Enabled = false; _abort = false; listViewInputFiles.BeginUpdate(); foreach (ListViewItem item in listViewInputFiles.Items) { item.SubItems[3].Text = "-"; } listViewInputFiles.EndUpdate(); Refresh(); var index = 0; while (index < listViewInputFiles.Items.Count && _abort == false) { var item = listViewInputFiles.Items[index]; void UpdateStatus(string status) { item.SubItems[3].Text = status; Refresh(); } UpdateStatus(LanguageSettings.Current.AddWaveformBatch.ExtractingAudio); var fileName = item.Text; try { var targetFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".wav"); Process process; try { process = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out var encoderName); labelInfo.Text = encoderName; } catch (DllNotFoundException) { var isFfmpegAvailable = !string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) && File.Exists(Configuration.Settings.General.FFmpegLocation); if (isFfmpegAvailable) { Configuration.Settings.General.UseFFmpegForWaveExtraction = true; process = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out var encoderName); labelInfo.Text = encoderName; } else { if (MessageBox.Show(LanguageSettings.Current.AddWaveform.FfmpegNotFound, "Subtitle Edit", MessageBoxButtons.YesNoCancel) != DialogResult.Yes) { buttonRipWave.Enabled = true; return; } using (var form = new DownloadFfmpeg()) { if (form.ShowDialog(this) == DialogResult.OK && !string.IsNullOrEmpty(form.FFmpegPath)) { Configuration.Settings.General.FFmpegLocation = form.FFmpegPath; Configuration.Settings.General.UseFFmpegForWaveExtraction = true; process = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out var encoderName); labelInfo.Text = encoderName; } else { buttonRipWave.Enabled = true; return; } } } } process.Start(); while (!process.HasExited && !_abort) { Application.DoEvents(); } // check for delay in matroska files var audioTrackNames = new List <string>(); var mkvAudioTrackNumbers = new Dictionary <int, int>(); if (fileName.ToLowerInvariant().EndsWith(".mkv", StringComparison.OrdinalIgnoreCase)) { try { using (var matroska = new MatroskaFile(fileName)) { if (matroska.IsValid) { foreach (var track in matroska.GetTracks()) { if (track.IsAudio) { if (track.CodecId != null && track.Language != null) { audioTrackNames.Add("#" + track.TrackNumber + ": " + track.CodecId.Replace("\0", string.Empty) + " - " + track.Language.Replace("\0", string.Empty)); } else { audioTrackNames.Add("#" + track.TrackNumber); } mkvAudioTrackNumbers.Add(mkvAudioTrackNumbers.Count, track.TrackNumber); } } if (mkvAudioTrackNumbers.Count > 0) { _delayInMilliseconds = (int)matroska.GetAudioTrackDelayMilliseconds(mkvAudioTrackNumbers[0]); } } } } catch (Exception exception) { SeLogger.Error(exception, $"Error getting delay from mkv: {fileName}"); _delayInMilliseconds = 0; } } UpdateStatus(LanguageSettings.Current.AddWaveformBatch.Calculating); MakeWaveformAndSpectrogram(fileName, targetFile, _delayInMilliseconds); if (checkBoxGenerateSceneChanges.Visible && checkBoxGenerateSceneChanges.Checked) { GenerateSceneChanges(fileName); } // cleanup try { File.Delete(targetFile); } catch { // don't show error about unsuccessful delete } IncrementAndShowProgress(); UpdateStatus(LanguageSettings.Current.AddWaveformBatch.Done); } catch { IncrementAndShowProgress(); UpdateStatus(LanguageSettings.Current.AddWaveformBatch.Error); } index++; } _converting = false; labelProgress.Text = string.Empty; labelInfo.Text = string.Empty; progressBar1.Visible = false; TaskbarList.SetProgressState(Owner.Handle, TaskbarButtonProgressFlags.NoProgress); buttonRipWave.Enabled = true; buttonInputBrowse.Enabled = true; buttonSearchFolder.Enabled = true; }