public void MatroskaTestDelayed500Ms() { string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MKV_delayed.mkv"); using (var parser = new MatroskaFile(fileName)) { var delay = parser.GetTrackStartTime(parser.GetTracks()[0].TrackNumber); Assert.IsTrue(delay == 500); } }
private void AddWaveform_Shown(object sender, EventArgs e) { Refresh(); var audioTrackNames = new List <string>(); var mkvAudioTrackNumbers = new Dictionary <int, int>(); int numberOfAudioTracks = 0; if (labelVideoFileName.Text.Length > 1 && File.Exists(labelVideoFileName.Text)) { if (labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase)) { // Choose for number of audio tracks in matroska files MatroskaFile matroska = null; try { matroska = new MatroskaFile(labelVideoFileName.Text); if (matroska.IsValid) { foreach (var track in matroska.GetTracks()) { if (track.IsAudio) { numberOfAudioTracks++; 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); } } } } finally { matroska?.Dispose(); } } else if (labelVideoFileName.Text.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase) || labelVideoFileName.Text.EndsWith(".m4v", StringComparison.OrdinalIgnoreCase)) { // Choose for number of audio tracks in mp4 files try { var mp4 = new MP4Parser(labelVideoFileName.Text); var tracks = mp4.GetAudioTracks(); int i = 0; foreach (var track in tracks) { i++; if (track.Name != null && track.Mdia != null && track.Mdia.Mdhd != null && track.Mdia.Mdhd.LanguageString != null) { audioTrackNames.Add(i + ": " + track.Name + " - " + track.Mdia.Mdhd.LanguageString); } else if (track.Name != null) { audioTrackNames.Add(i + ": " + track.Name); } else { audioTrackNames.Add(i.ToString(CultureInfo.InvariantCulture)); } } numberOfAudioTracks = tracks.Count; } catch { // ignored } } // Choose audio track if (numberOfAudioTracks > 1) { using (var form = new ChooseAudioTrack(audioTrackNames, _audioTrackNumber)) { if (form.ShowDialog(this) == DialogResult.OK) { _audioTrackNumber = form.SelectedTrack; } else { DialogResult = DialogResult.Cancel; return; } } } // check for delay in matroska files if (labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase)) { MatroskaFile matroska = null; try { matroska = new MatroskaFile(labelVideoFileName.Text); if (matroska.IsValid) { _delayInMilliseconds = (int)matroska.GetTrackStartTime(mkvAudioTrackNumbers[_audioTrackNumber]); } } catch { _delayInMilliseconds = 0; } finally { matroska?.Dispose(); } } buttonRipWave_Click(null, null); } else if (_wavFileName != null) { FixWaveOnly(); } }
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 ExtractAudio() { try { _waveFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".wav"); Process process; try { process = GetCommandLineProcess(_videoFileName, -1, _waveFileName, Configuration.Settings.General.VlcWaveTranscodeSettings, out var waveExtractor); _backgroundWorker.ReportProgress(0, string.Format(Configuration.Settings.Language.AudioToText.ExtractingAudioUsingX, waveExtractor)); } 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) { UiUtil.OpenURL("http://www.videolan.org/"); } return; } process.Start(); while (!process.HasExited && !_abort) { Application.DoEvents(); } // check for delay in matroska files var mkvAudioTrackNumbers = new Dictionary <int, int>(); if (_videoFileName.ToLowerInvariant().EndsWith(".mkv", StringComparison.OrdinalIgnoreCase)) { MatroskaFile matroska = null; try { matroska = new MatroskaFile(_videoFileName); if (matroska.IsValid) { foreach (var track in matroska.GetTracks()) { if (track.IsAudio) { var audioTrackNames = new List <string>(); 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 { matroska?.Dispose(); } } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
private void AddWareForm_Shown(object sender, EventArgs e) { Refresh(); var audioTrackNames = new List<string>(); var mkvAudioTrackNumbers = new Dictionary<int, int>(); int numberOfAudioTracks = 0; if (labelVideoFileName.Text.Length > 1 && File.Exists(labelVideoFileName.Text)) { if (labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase)) { // Choose for number of audio tracks in matroska files MatroskaFile matroska = null; try { matroska = new MatroskaFile(labelVideoFileName.Text); if (matroska.IsValid) { foreach (var track in matroska.GetTracks()) { if (track.IsAudio) { numberOfAudioTracks++; 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); } } } } finally { if (matroska != null) { matroska.Dispose(); } } } else if (labelVideoFileName.Text.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase) || labelVideoFileName.Text.EndsWith(".m4v", StringComparison.OrdinalIgnoreCase)) { // Choose for number of audio tracks in mp4 files try { var mp4 = new MP4Parser(labelVideoFileName.Text); var tracks = mp4.GetAudioTracks(); int i = 0; foreach (var track in tracks) { i++; if (track.Name != null && track.Mdia != null && track.Mdia.Mdhd != null && track.Mdia.Mdhd.LanguageString != null) audioTrackNames.Add(i + ": " + track.Name + " - " + track.Mdia.Mdhd.LanguageString); else if (track.Name != null) audioTrackNames.Add(i + ": " + track.Name); else audioTrackNames.Add(i.ToString(CultureInfo.InvariantCulture)); } numberOfAudioTracks = tracks.Count; } catch { } } if (Configuration.Settings.General.UseFFmpegForWaveExtraction) { // don't know how to extract audio number x via FFmpeg... numberOfAudioTracks = 1; _audioTrackNumber = 0; } // Choose audio track if (numberOfAudioTracks > 1) { using (var form = new ChooseAudioTrack(audioTrackNames, _audioTrackNumber)) { if (form.ShowDialog(this) == DialogResult.OK) { _audioTrackNumber = form.SelectedTrack; } else { DialogResult = DialogResult.Cancel; return; } } } // check for delay in matroska files if (labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase)) { MatroskaFile matroska = null; try { matroska = new MatroskaFile(labelVideoFileName.Text); if (matroska.IsValid) { _delayInMilliseconds = (int)matroska.GetTrackStartTime(mkvAudioTrackNumbers[_audioTrackNumber]); } } catch { _delayInMilliseconds = 0; } finally { if (matroska != null) { matroska.Dispose(); } } } buttonRipWave_Click(null, null); } else if (_wavFileName != null) { FixWaveOnly(); } }
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 = Configuration.Settings.Language.AddWaveformBatch.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; }