public void TEST_DVD_IFO_PARSING_2() { MediaSource ms = TestDVD(@"C:\Users\Public\Videos\DVDs\Apocalypto"); Assert.AreEqual(29, ms.DVDDiskInfo.Titles.Length); DVDTitle title = ms.DVDDiskInfo.GetMainTitle(); Assert.AreEqual(4, title.TitleNumber); Assert.AreEqual(19, title.Chapters.Count); Assert.AreEqual(3, title.AudioTracks.Count); //audio stream: 0 format: ac3 (5.1) language: unknown aid: 128. Assert.AreEqual("", title.AudioTracks[0].LanguageID); Assert.AreEqual(128, title.AudioTracks[0].ID); //audio stream: 1 format: dts (5.1) language: unknown aid: 137. Assert.AreEqual("", title.AudioTracks[1].LanguageID); Assert.AreEqual(137, title.AudioTracks[1].ID); //audio stream: 2 format: ac3 (mono) language: en aid: 130. Assert.AreEqual("en", title.AudioTracks[2].LanguageID); Assert.AreEqual(130, title.AudioTracks[2].ID); Assert.AreEqual(5, title.Subtitles.Count); //subtitle ( sid ): 0 language: en Assert.AreEqual("en", title.Subtitles[0].LanguageID); //subtitle ( sid ): 1 language: en Assert.AreEqual("en", title.Subtitles[1].LanguageID); //subtitle ( sid ): 2 language: fr Assert.AreEqual("fr", title.Subtitles[2].LanguageID); //subtitle ( sid ): 3 language: es Assert.AreEqual("es", title.Subtitles[3].LanguageID); //subtitle ( sid ): 4 language: en Assert.AreEqual("en", title.Subtitles[4].LanguageID); }
public void TEST_DVD_IFO_PARSING() { MediaSource ms = TestDVD(TestDVD_Dir); Assert.IsNotNull(ms.DVDDiskInfo); Assert.AreEqual(1, ms.DVDDiskInfo.Titles.Length); DVDTitle title = ms.DVDDiskInfo.Titles[0]; Assert.AreEqual("vts 1", title.File); Assert.IsTrue(title.Main); Assert.AreEqual(30, title.FPS); Assert.AreEqual(480, title.Resolution.Height); Assert.AreEqual(720, title.Resolution.Width); Assert.AreEqual(1.78f, title.AspectRatio); Assert.AreEqual(16, title.Chapters.Count); Assert.AreEqual(TimeSpan.Parse("02:06:12.532"), title.Duration); Assert.AreEqual(2, title.Subtitles.Count); Assert.AreEqual("en", title.Subtitles[0].LanguageID); Assert.AreEqual("fr", title.Subtitles[1].LanguageID); Assert.AreEqual(3, title.AudioTracks.Count); Assert.AreEqual("en", title.AudioTracks[0].LanguageID); Assert.AreEqual(6, title.AudioTracks[0].Channels); Assert.AreEqual(AudioEncoding.AC3, title.AudioTracks[0].Format); Assert.AreEqual("fr", title.AudioTracks[1].LanguageID); Assert.AreEqual("en", title.AudioTracks[2].LanguageID); Assert.AreEqual(AudioExtension.Director_s_comments, title.AudioTracks[2].Extension); }
void FillSubtitle(DVDTitle title) { txtSubtitles.Text = string.Empty; foreach (DVDSubtitle st in title.Subtitles) { txtSubtitles.Text += ", " + st.LanguageID; } txtSubtitles.Text = txtSubtitles.Text.TrimStart(',', ' '); }
public SubtitleStream GetSubTitle(string languageID) { DVDTitle title = DVDTitle; if (title == null) { return(null); } return(GetSubTitle(title.GetSubTitle(languageID))); }
public AudioStream GetAudioSteam(AudioExtension extension) { DVDTitle title = DVDTitle; if (title == null) { return(null); } return(GetAudioSteam((from a in title.AudioTracks where a.Extension == extension select a).FirstOrDefault())); }
private void txtName_TextChanged(object sender, EventArgs e) { DVDTitle title = (DVDTitle)this.cbTitle.SelectedItem; MediaSource source = _menu.ContainsKey(title) ? _menu[title] : null; if (source == null) { return; } source.Disk.Name = txtName.Text; UpdateMenu(); }
void PlayTitle(DVDTitle title) { if (m_dvdCtrl == null) { PreviewInit(); } IDvdCmd cmd; DvdHMSFTimeCode time = new DvdHMSFTimeCode() { bSeconds = 10 }; m_dvdCtrl.PlayAtTimeInTitle(title.TitleNumber, time, DvdCmdFlags.SendEvents, out cmd); }
void FillAudioTrack(DVDTitle title) { txtAudioTracks.Text = string.Empty; foreach (DVDAudioTrack at in title.AudioTracks) { txtAudioTracks.Text += ", " + at.LanguageID + " (" + at.Format + "," + at.SubFormat; if (at.Extension != AudioExtension.Normal && at.Extension != AudioExtension.Unspecified) { txtAudioTracks.Text += ", " + DVDAudioTrack.GetExtension(at.Extension); } txtAudioTracks.Text += ")"; } txtAudioTracks.Text = txtAudioTracks.Text.TrimStart(',', ' '); }
private void txtEndChapters_TextChanged(object sender, EventArgs e) { DVDTitle title = (DVDTitle)this.cbTitle.SelectedItem; MediaSource source = _menu.ContainsKey(title) ? _menu[title] : null; if (source == null) { return; } int val; source.EndChapter = int.TryParse(txtEndChapters.Text, out val) ? (int?)val : null; UpdateMenu(); }
private void cbTitle_SelectedIndexChanged(object sender, EventArgs e) { cbEnabled.CheckedChanged -= cbEnabledCheckedChanged; DVDTitle title = (DVDTitle)this.cbTitle.SelectedItem; PlayTitle(title); int chapterCount; m_dvdInfo.GetNumberOfChapters(title.TitleNumber, out chapterCount); Debug.Assert(chapterCount == title.Chapters.Count); if (title == _disk.DVDDiskInfo.GetMainTitle()) { cbEnabled.Checked = true; txtName.Text = lblDVDName.Text; txtStartChapters.Text = txtEndChapters.Text = string.Empty; FillAudioTrack(title); FillSubtitle(title); cbEnabled.Enabled = txtName.Enabled = txtStartChapters.Enabled = txtEndChapters.Enabled = false; return; } cbEnabled.Enabled = txtName.Enabled = txtStartChapters.Enabled = txtEndChapters.Enabled = true; MediaSource source = _menu.ContainsKey(title) ? _menu[title] : null; cbEnabled.Checked = source != null; cbEnabled.CheckedChanged += cbEnabledCheckedChanged; lblChapters.Text = title.Chapters.Count.ToString(); if (cbEnabled.Checked) { txtName.Text = source.Name; txtStartChapters.Text = source.StartChapter != null?source.StartChapter.ToString() : ""; txtEndChapters.Text = source.EndChapter != null?source.EndChapter.ToString() : ""; } else { txtName.Text = "Title " + title.TitleNumber; txtStartChapters.Text = txtEndChapters.Text = string.Empty; } txtStartChapters.Enabled = txtEndChapters.Enabled = title.Chapters.Count > 1; FillAudioTrack(title); FillSubtitle(title); }
static MediaSource TestDVD_A_S(string dir, int at, int st) { MediaSource ms = TestDVD(dir); DVDTitle main = ms.DVDDiskInfo.GetMainTitle(); if (at >= 0) { ms.AudioStream = new AudioStream(main.AudioTracks[at]); } if (st >= 0) { ms.Subtitle = new SubtitleStream(main.Subtitles[st]); } return(ms); }
public static IEnumerable <MediaSource> GetSourcesFromOptions(string mediaPath, string extraOptions, bool returnDefault) { List <MediaSource> ret = new List <MediaSource>(); if (extraOptions == null && returnDefault) { var ms = new MediaSource(new Disk("Main", mediaPath, VideoFormat.DVD)); DVDTitle mt = ms.DVDTitle; if (mt != null) { TimeSpan minDuration = TimeSpan.FromSeconds(30); var list = from t in ms.DVDDiskInfo.Titles where t.TitleNumber != mt.TitleNumber && t.AudioTracks.Count > 0 && t.Duration > minDuration group t by t.File.Substring(4).ToLower() into t select new { TitleNumber = t.Last().TitleNumber, File = t.Last().File.Substring(4), Duration = TimeSpan.FromSeconds(t.Sum(a => a.Duration.TotalSeconds)) }; ret.AddRange(from t in list.Take(7) orderby t.Duration.TotalSeconds select new MediaSource(new Disk("" + FormatTime(t.Duration) + ": " + t.File, mediaPath, VideoFormat.DVD) { ExtraOptions = "T=" + t.TitleNumber })); } return(ret); } if (extraOptions == null || extraOptions.StartsWith("#\n") == false) { return(ret); } foreach (string sourceLine in extraOptions.TrimStart('#', '\n').Split('\n')) { int pos = sourceLine.IndexOf(";N="); string name = sourceLine.Substring(pos + ";N=".Length); ret.Add(new MediaSource(new Disk(name, mediaPath, VideoFormat.DVD) { ExtraOptions = sourceLine.Substring(0, pos) })); } return(ret); }
private void cbEnabled_CheckedChanged(object sender, EventArgs e) { DVDTitle title = (DVDTitle)this.cbTitle.SelectedItem; if (cbEnabled.Checked) { _menu[title] = new MediaSource(new Disk(txtName.Text, _disk.Path, _disk.Format)) { Title = title.TitleNumber } } ; else { _menu.Remove(title); } UpdateMenu(); }
// keep all the Playing logic here static bool IsExtenderDVD_NoTranscoding(MediaSource source) { if (OMLApplication.Current.IsExtender == false || source.Format != VideoFormat.DVD || FileScanner.IsDVD(source.MediaPath) == false || ExtenderDVDPlayer.CanPlay(source) == false) { return(false); } // non-default audio/subtitle/chapter start: needs transcoding if (source.AudioStream != null || source.Subtitle != null || source.StartChapter != null) { Utilities.DebugLine("Source has custom audio/subtitle/startchapter: {0}", source); return(false); } if (source.DVDDiskInfo == null) { Utilities.DebugLine("Source has no DVDDiskInfo: {0}", source); return(true); } string languageCode = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; DVDTitle title = source.Title != null ? source.DVDDiskInfo.Titles[source.Title.Value] : source.DVDDiskInfo.GetMainTitle(); if (title.AudioTracks.Count != 0 && string.Compare(title.AudioTracks[0].LanguageID, languageCode, true) != 0) { DVDSubtitle st = title.Subtitles.Count != 0 ? title.FindSubTitle(languageCode) : null; if (st != null) { source.Subtitle = new SubtitleStream(st); Utilities.DebugLine("Autoselect subtitle, since default audio stream is not native: {0}", source); return(false); } } return(true); }
public static string FindMPeg(MediaSource source) { DVDTitle dvdTitle = source.DVDTitle; if (dvdTitle == null) { return(null); } // ensure DVD's with DTS audio get transcoded, since extenders don't support DTS audio playback if (dvdTitle.AudioTracks.Count > 0 && dvdTitle.AudioTracks[0].Format == AudioEncoding.DTS) { return(null); } string videoTSDir = source.VIDEO_TS; int fileID = int.Parse(dvdTitle.File.Substring(4)); string vts = string.Format("VTS_{0:D2}_", fileID); List <string> vobs = new List <string>(Directory.GetFiles(videoTSDir, vts + "*.VOB")); vobs.Remove(Path.Combine(videoTSDir, vts + "0.VOB")); // don't direct play unmerged .VOB files if (vobs.Count < 1 || vobs.Count > 1) { return(null); } if (IsNTFS(videoTSDir)) { string mpegFolder = Path.Combine(FileSystemWalker.ExtenderCacheDirectory, Guid.NewGuid().ToString()); if (Directory.Exists(mpegFolder) == false) { Directory.CreateDirectory(mpegFolder); } if (Directory.Exists(mpegFolder) == false) { return(null); } OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Attempting to connect to WCF Transcoder Service"); TranscodingAPI transcoder = new TranscodingAPI(source, null); OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Calling MakeMPEGLink on WCF Transcoder Service"); string mpegFile = transcoder.MakeMPEGLink(mpegFolder, vobs[0]); if (File.Exists(mpegFile)) { return(mpegFile); } } else if (videoTSDir.StartsWith("\\\\")) { string mpegFile = Path.ChangeExtension(source.GetTranscodingFileName(), ".MPEG"); if (File.Exists(mpegFile)) { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Found '{0}' as pre-existing .MPEG soft-link", mpegFile); return(mpegFile); } string vob = Path.Combine(videoTSDir, vobs[0]); OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Trying to create '{0}' soft-link to '{1}'", mpegFile, vob); OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Attempting to connect to WCF Transcoder Service"); TranscodingAPI transcoder = new TranscodingAPI(source, null); OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Calling CreateSymbolicLink on WCF Transcoder Service"); bool ret = transcoder.CreateSymbolicLink(mpegFile, vob); string retMsg = ret ? "success" : "Sym-Link failed: " + new Win32Exception(Marshal.GetLastWin32Error()).Message; if (File.Exists(mpegFile)) { return(mpegFile); } OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Soft-link creation failed! {0}", retMsg); } else { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Media not on a network drive nor on a NTFS compatible drive, no supported"); } return(null); }
public bool PlayMovie() { _info = _source.DVDDiskInfo; string videoFile = FindMPeg(_source); if (videoFile == null && _info != null) { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: DVD Disk info: '{0}'", _info); DVDTitle dvdTitle = _source.DVDTitle; if (dvdTitle != null) { string videoTSDir = _source.VIDEO_TS; int fileID = int.Parse(dvdTitle.File.Substring(4)); OMLApplication.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: main title fileID={1} found for '{0}'", _source, fileID); string vts = string.Format("VTS_{0:D2}_", fileID); List <string> vobs = new List <string>(Directory.GetFiles(videoTSDir, vts + "*.VOB")); vobs.Remove(Path.Combine(videoTSDir, vts + "0.VOB")); if (vobs.Count < 1) { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: no VOB files found for '{0}'", _source); return(false); } string mpegFolder = Path.Combine(FileSystemWalker.ExtenderCacheDirectory, Guid.NewGuid().ToString()); if (Directory.Exists(mpegFolder) == false) { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: creating folder '{0}'", mpegFolder); Directory.CreateDirectory(mpegFolder); } if (vobs.Count == 1) { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Single VOB file, trying to use a hard-link approach and direct playback"); OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Calling MakeMPEGLink on WCF Transcoder Service"); string mpegFile = transcoder.MakeMPEGLink(mpegFolder, vobs[0]); if (File.Exists(mpegFile)) { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] directly use MPEG"); videoFile = mpegFile; } } else if (OMLSettings.Extender_MergeVOB) { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Multiple VOB files, and Extender_MergeVOB == true, trying to use a hard-link and auto-merge into single large .VOB file approach "); OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Calling MakeMPEGLink on WCF Transcoder Service"); string mpegFile = transcoder.MakeMPEGLink(mpegFolder, vobs[0]); OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Merge VOB's, use first VOB to play and merge into"); if (File.Exists(mpegFile) == false) { return(false); } videoFile = mpegFile; Microsoft.MediaCenter.UI.Application.DeferredInvokeOnWorkerThread(delegate { FileStream writer = null; try { writer = File.Open(vobs[0], FileMode.Append, FileAccess.Write, FileShare.Read); for (int i = 1; i < vobs.Count; ++i) { MergeFile(writer, vobs[0], vobs[i]); } for (int i = 1; i < vobs.Count; ++i) { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Deleting '{0}'", vobs[i]); File.Delete(vobs[i]); } } finally { if (writer != null) { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Done merging into '{0}'", vobs[0]); writer.Close(); } } }, delegate { Utilities.DebugLine("[MoviePlayerExtenderDVD] Merging done, restart play, and reset posision"); if (AddInHost.Current.MediaCenterEnvironment.MediaExperience != null) { TimeSpan cur = AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.Position; Utilities.DebugLine("[MoviePlayerExtenderDVD] Current position: {0}", cur); if (AddInHost.Current.MediaCenterEnvironment.PlayMedia(MediaType.Video, videoFile, false)) { AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.Position = cur; Utilities.DebugLine("[MoviePlayerExtenderDVD] Done starting over, resetting position: {0}", cur); } } }, null); } //else if (OMLSettings.Extender_UseAsx) else { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Multiple VOB files, and Extender_UseAsx == true, trying to use a hard-link and asx playlist approach "); foreach (string vob in vobs) { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] Calling MakeMPEGLink on WCF Transcoder Service"); transcoder.MakeMPEGLink(mpegFolder, vob); } if (File.Exists(GetMPEGName(mpegFolder, vobs[0]))) { videoFile = CreateASX(mpegFolder, vts, _source.Name, vobs); } } } else { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: no main title found for {0}", _source); } } else { OMLApplication.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: no DVD-DiskInfo found for {0}", _source); } if (videoFile == null) { videoFile = GetAsxFile(); } if (videoFile != null && AddInHost.Current.MediaCenterEnvironment.PlayMedia(MediaType.Video, videoFile, false)) { if (AddInHost.Current.MediaCenterEnvironment.MediaExperience != null) { Utilities.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: movie '{0}', Playing file '{1}'", _source.Name, videoFile); OMLApplication.Current.NowPlayingMovieName = _source.Name; OMLApplication.Current.NowPlayingStatus = PlayState.Playing; if (_source.ResumeTime != null) { Utilities.DebugLine("[MoviePlayerExtenderDVD] PlayMovie: set resume time to: {0}", _source.ResumeTime); AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.Position = _source.ResumeTime.Value; } AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.PropertyChanged -= MoviePlayerFactory.Transport_PropertyChanged; AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.PropertyChanged += MoviePlayerFactory.Transport_PropertyChanged; AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.PropertyChanged -= this.Transport_PropertyChanged; AddInHost.Current.MediaCenterEnvironment.MediaExperience.Transport.PropertyChanged += this.Transport_PropertyChanged; AddInHost.Current.MediaCenterEnvironment.MediaExperience.GoToFullScreen(); } return(true); } else { return(false); } }