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); } }
/// <summary> /// The add ware form_ shown. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void AddWareForm_Shown(object sender, EventArgs e) { this.Refresh(); var audioTrackNames = new List<string>(); var mkvAudioTrackNumbers = new Dictionary<int, int>(); int numberOfAudioTracks = 0; if (this.labelVideoFileName.Text.Length > 1 && File.Exists(this.labelVideoFileName.Text)) { if (this.labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase)) { // Choose for number of audio tracks in matroska files MatroskaFile matroska = null; try { matroska = new MatroskaFile(this.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 (this.labelVideoFileName.Text.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase) || this.labelVideoFileName.Text.EndsWith(".m4v", StringComparison.OrdinalIgnoreCase)) { // Choose for number of audio tracks in mp4 files try { var mp4 = new MP4Parser(this.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; this._audioTrackNumber = 0; } // Choose audio track if (numberOfAudioTracks > 1) { using (var form = new ChooseAudioTrack(audioTrackNames, this._audioTrackNumber)) { if (form.ShowDialog(this) == DialogResult.OK) { this._audioTrackNumber = form.SelectedTrack; } else { this.DialogResult = DialogResult.Cancel; return; } } } // check for delay in matroska files if (this.labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase)) { MatroskaFile matroska = null; try { matroska = new MatroskaFile(this.labelVideoFileName.Text); if (matroska.IsValid) { this._delayInMilliseconds = (int)matroska.GetTrackStartTime(mkvAudioTrackNumbers[this._audioTrackNumber]); } } catch { this._delayInMilliseconds = 0; } finally { if (matroska != null) { matroska.Dispose(); } } } this.buttonRipWave_Click(null, null); } else if (this._wavFileName != null) { this.FixWaveOnly(); } }