public static DVDDiskInfo ParseDVD(string videoTSDir) { return(videoTSDir != null && Directory.Exists(videoTSDir) ? new DVDDiskInfo() { Titles = IFOUtilities.Titles(videoTSDir).ToArray() } : null); }
public static List <DVDTitle> Titles(string videoTSDir) { List <DVDTitle> ret = new List <DVDTitle>(); string videoIFO = Path.Combine(videoTSDir, "VIDEO_TS.IFO"); if (File.Exists(videoIFO)) { byte[] bytRead = new byte[4]; long VMG_PTT_STPT_Position = ToFilePosition(GetFileBlock(videoIFO, 0xC4, 4)); int titlePlayMaps = ToInt16(GetFileBlock(videoIFO, VMG_PTT_STPT_Position, 2)); string longestIfo = GetLongestIFO(videoTSDir); for (int currentTitle = 1; currentTitle <= titlePlayMaps; ++currentTitle) { DVDTitle title = new DVDTitle() { TitleNumber = currentTitle }; long titleInfoStart = 8 + ((currentTitle - 1) * 12); int titleSetNumber = GetFileBlock(videoIFO, (VMG_PTT_STPT_Position + titleInfoStart) + 6L, 1)[0]; int titleSetTitleNumber = IFOUtilities.GetFileBlock(videoIFO, (VMG_PTT_STPT_Position + titleInfoStart) + 7L, 1)[0]; string vtsIFO = Path.Combine(videoTSDir, string.Format("VTS_{0:D2}_0.IFO", titleSetNumber)); if (File.Exists(vtsIFO) == false) { Trace.WriteLine(string.Format("IFOUtils.Titles: VTS IFO file missing: {0}", Path.GetFileName(vtsIFO))); continue; } byte[] b = IFOUtilities.GetFileBlock(vtsIFO, 0x200, 2); VideoValues video = VideoValues.ReadVideoSpecs(b[0], b[1]); title.Main = Path.GetFileName(longestIfo) == Path.GetFileName(vtsIFO); title.File = "vts " + titleSetNumber; title.AspectRatio = video.AspectRatio; title.Resolution = video.Resolution; title.Chapters = Chapters(vtsIFO, titleSetTitleNumber); title.AudioTracks = AudioTracks(vtsIFO); title.Subtitles = SubTitleTracks(vtsIFO); title.Duration = DVDTitle.GetTotalTimeSpan(title.Chapters); //if (title.Duration.TotalSeconds > 10) ret.Add(title); //else // Trace.WriteLine(string.Format("IFOUtils.Titles: Duration < 10s, ignoring: {0}", Path.GetFileName(vtsIFO))); } } else { Trace.WriteLine(string.Format("IFOUtilities.Titles: Cannot analyze DVD, file {0} not found", videoIFO)); } return(ret); }
internal static List <DVDAudioTrack> AudioTracks(string ifoFile) { List <DVDAudioTrack> ret = new List <DVDAudioTrack>(); int audioStreams = IFOUtilities.GetFileBlock(ifoFile, 0x203, 1)[0]; for (int currentAudioStream = 1; currentAudioStream <= audioStreams; currentAudioStream++) { byte[] bytes = IFOUtilities.GetFileBlock(ifoFile, (long)(0x204 + (8 * (currentAudioStream - 1))), 8); AudioValues audioValues = AudioValues.ReadAudioSpecs(bytes[0], bytes[1], bytes[5]); string languageCode = ""; if (audioValues.LanguageTypePresent) { languageCode = "" + (char)bytes[2] + (char)bytes[3]; } // audio channel // - MPEG: 0-31 // - VOB(AC3): 128-159 // - VOB(LPCM): 160-191 int id = currentAudioStream - 1; if (audioValues.Encoding == AudioEncoding.AC3) { id = 127 + currentAudioStream; } else if (audioValues.Encoding == AudioEncoding.DTS) { id = 135 + currentAudioStream; } else if (audioValues.Encoding == AudioEncoding.LPCM) { id = 159 + currentAudioStream; } ret.Add(new DVDAudioTrack() { Frequency = audioValues.SampleRate * 1000, LanguageID = languageCode, TrackNumber = currentAudioStream, ID = id, Channels = audioValues.Channels, Format = audioValues.Encoding, Extension = audioValues.Extension, // Bitrate = , }); } return(ret); }
internal static List <DVDSubtitle> SubTitleTracks(string ifoFile) { List <DVDSubtitle> ret = new List <DVDSubtitle>(); int subPictureStreams = IFOUtilities.GetFileBlock(ifoFile, 0x255, 1)[0]; for (int currentSubPictureStream = 1; currentSubPictureStream <= subPictureStreams; currentSubPictureStream++) { byte[] bytes = IFOUtilities.GetFileBlock(ifoFile, (long)(0x256 + (6 * (currentSubPictureStream - 1))), 6); if (bytes[2] == 0 || bytes[3] == 0) { continue; } string languageCode = "" + (char)bytes[2] + (char)bytes[3]; ret.Add(new DVDSubtitle() { LanguageID = languageCode, TrackNumber = currentSubPictureStream }); } return(ret); }