public ChapterInfo GetChapterInfo(string location, int titleSetNum) { if (location.StartsWith("VTS_")) { titleSetNum = int.Parse(Path.GetFileNameWithoutExtension(location) .ToUpper(System.Globalization.CultureInfo.InvariantCulture) .Replace("VTS_", string.Empty) .Replace("_0.IFO", string.Empty)); } ChapterInfo pgc = new ChapterInfo(); pgc.SourceType = "DVD"; pgc.SourceName = "PGC " + titleSetNum.ToString("D2"); pgc.TitleNumber = titleSetNum; pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location); pgc.Title = Path.GetFileNameWithoutExtension(location); if (pgc.Title.Split('_').Length == 3) { pgc.Title = pgc.Title.Split('_')[0] + "_" + pgc.Title.Split('_')[1]; } TimeSpan duration; double fps; pgc.Chapters = GetChapters(location, titleSetNum, out duration, out fps); pgc.Duration = duration; pgc.FramesPerSecond = fps; OnStreamDetected(pgc); OnExtractionComplete(); return(pgc); }
public override List <ChapterInfo> GetStreams(string location) { ChapterInfo pgc = new ChapterInfo(); pgc.Chapters = new List <Chapter>(); pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location); pgc.SourceName = location; pgc.Title = Path.GetFileNameWithoutExtension(location); pgc.SourceType = "Blu-Ray"; FileInfo fileInfo = new FileInfo(location); OnStreamDetected(pgc); TSPlaylistFile mpls = new TSPlaylistFile(fileInfo); //Dictionary<string, TSStreamClipFile> clips = new Dictionary<string,TSStreamClipFile>(); mpls.Scan(); int count = 1; foreach (double d in mpls.Chapters) { pgc.Chapters.Add(new Chapter() { Name = "Chapter " + count.ToString("D2"), Time = new TimeSpan((long)(d * (double)TimeSpan.TicksPerSecond)) }); count++; } pgc.Duration = new TimeSpan((long)(mpls.TotalLength * (double)TimeSpan.TicksPerSecond)); foreach (TSStreamClip clip in mpls.StreamClips) { clip.StreamClipFile.Scan(); foreach (TSStream stream in clip.StreamClipFile.Streams.Values) { if (stream.IsVideoStream) { pgc.FramesPerSecond = (double)((TSVideoStream)stream).FrameRateEnumerator / (double)((TSVideoStream)stream).FrameRateDenominator; break; } } if (pgc.FramesPerSecond != 0) { break; } } OnChaptersLoaded(pgc); OnExtractionComplete(); return(new List <ChapterInfo>() { pgc }); }
public override List <ChapterInfo> GetStreams(string location) { List <ChapterInfo> pgcs = new List <ChapterInfo>(); List <Chapter> list = new List <Chapter>(); int num = 0; TimeSpan ts = new TimeSpan(0); string time = String.Empty; string name = String.Empty; bool onTime = true; string[] lines = File.ReadAllLines(location); foreach (string line in lines) { if (onTime) { num++; //read time time = line.Replace("CHAPTER" + num.ToString("00") + "=", ""); ts = TimeSpan.Parse(time); } else { //read name name = line.Replace("CHAPTER" + num.ToString("00") + "NAME=", ""); //add it to list list.Add(new Chapter() { Name = name, Time = ts }); } onTime = !onTime; } pgcs.Add(new ChapterInfo() { Chapters = list, SourceName = location, SourceHash = ChapterExtractor.ComputeMD5Sum(location), FramesPerSecond = 25.0, Title = Path.GetFileNameWithoutExtension(location) }); OnStreamDetected(pgcs[0]); OnChaptersLoaded(pgcs[0]); OnExtractionComplete(); return(pgcs); }
public override List <ChapterInfo> GetStreams(string location) { ChapterInfo pgc = new ChapterInfo(); pgc.Chapters = new List <Chapter>(); pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location); pgc.SourceName = location; pgc.Title = Path.GetFileNameWithoutExtension(location); pgc.SourceType = "Blu-Ray"; DirectoryInfo DirectoryBDMV = GetDirectoryBDMV(location); if (DirectoryBDMV == null) { throw new Exception("Unable to locate BD structure."); } DirectoryInfo DirectoryRoot = DirectoryBDMV.Parent; DirectoryInfo DirectoryBDJO = GetDirectory("BDJO", DirectoryBDMV, 0); DirectoryInfo DirectoryCLIPINF = GetDirectory("CLIPINF", DirectoryBDMV, 0); DirectoryInfo DirectoryPLAYLIST = GetDirectory("PLAYLIST", DirectoryBDMV, 0); DirectoryInfo DirectorySNP = GetDirectory("SNP", DirectoryRoot, 0); DirectoryInfo DirectorySTREAM = GetDirectory("STREAM", DirectoryBDMV, 0); DirectoryInfo DirectorySSIF = GetDirectory("SSIF", DirectorySTREAM, 0); Dictionary <string, TSStreamClipFile> StreamClipFiles = new Dictionary <string, TSStreamClipFile>(); Dictionary <string, TSStreamFile> StreamFiles = new Dictionary <string, TSStreamFile>(); if (DirectorySTREAM != null) { FileInfo[] files = DirectorySTREAM.GetFiles("*.m2ts"); if (files.Length == 0) { files = DirectoryPLAYLIST.GetFiles("*.M2TS"); } foreach (FileInfo file in files) { StreamFiles.Add(file.Name.ToUpper(), new TSStreamFile(file)); } } if (DirectoryCLIPINF != null) { FileInfo[] files = DirectoryCLIPINF.GetFiles("*.clpi"); if (files.Length == 0) { files = DirectoryPLAYLIST.GetFiles("*.CLPI"); } foreach (FileInfo file in files) { StreamClipFiles.Add(file.Name.ToUpper(), new TSStreamClipFile(file)); } } FileInfo fileInfo = new FileInfo(location); TSPlaylistFile mpls = new TSPlaylistFile(fileInfo); mpls.Scan(StreamFiles, StreamClipFiles); int count = 1; foreach (double d in mpls.Chapters) { pgc.Chapters.Add(new Chapter() { Name = "Chapter " + count.ToString("D2"), Time = new TimeSpan((long)(d * (double)TimeSpan.TicksPerSecond)) }); count++; } pgc.Duration = new TimeSpan((long)(mpls.TotalLength * (double)TimeSpan.TicksPerSecond)); foreach (TSStreamClip clip in mpls.StreamClips) { clip.StreamClipFile.Scan(); foreach (TSStream stream in clip.StreamClipFile.Streams.Values) { if (stream.IsVideoStream) { pgc.FramesPerSecond = VideoUtil.ConvertFPSFractionToDouble(((TSVideoStream)stream).FrameRateEnumerator, ((TSVideoStream)stream).FrameRateDenominator); break; } } if (pgc.FramesPerSecond != 0) { break; } } if (pgc.Duration.TotalSeconds > MainForm.Instance.Settings.ChapterCreatorMinimumLength) { OnStreamDetected(pgc); OnChaptersLoaded(pgc); } else { pgc = null; } OnExtractionComplete(); return(new List <ChapterInfo>() { pgc }); }
public override List <ChapterInfo> GetStreams(string location) { List <ChapterInfo> pgcs = new List <ChapterInfo>(); List <Chapter> list = new List <Chapter>(); string tempChapterFile = String.Empty; do { tempChapterFile = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), Path.GetRandomFileName()); }while (File.Exists(tempChapterFile)); MediaInfoFile oInfo = new MediaInfoFile(location); if (!oInfo.hasMKVChapters() || !oInfo.extractMKVChapters(tempChapterFile)) { OnExtractionComplete(); return(pgcs); } int num = 0; TimeSpan ts = new TimeSpan(0); string time = String.Empty; string name = String.Empty; bool onTime = true; string[] lines = File.ReadAllLines(tempChapterFile); foreach (string line in lines) { if (onTime) { num++; //read time time = line.Replace("CHAPTER" + num.ToString("00") + "=", ""); ts = TimeSpan.Parse(time); } else { //read name name = line.Replace("CHAPTER" + num.ToString("00") + "NAME=", ""); //add it to list list.Add(new Chapter() { Name = name, Time = ts }); } onTime = !onTime; } pgcs.Add(new ChapterInfo() { Chapters = list, SourceName = location, SourceHash = ChapterExtractor.ComputeMD5Sum(tempChapterFile), FramesPerSecond = oInfo.VideoInfo.FPS, Title = Path.GetFileNameWithoutExtension(location) }); try { File.Delete(tempChapterFile); } catch {} OnStreamDetected(pgcs[0]); OnChaptersLoaded(pgcs[0]); OnExtractionComplete(); return(pgcs); }
public override List <ChapterInfo> GetStreams(string location) { ChapterInfo pgc = new ChapterInfo(); List <Chapter> chapters = new List <Chapter>(); pgc.SourceName = location; pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location); pgc.SourceType = "Blu-Ray"; pgc.Title = Path.GetFileNameWithoutExtension(location); FileInfo fileInfo = new FileInfo(location); byte[] data = File.ReadAllBytes(location); string fileType = ASCIIEncoding.ASCII.GetString(data, 0, 8); if ((fileType != "MPLS0100" && fileType != "MPLS0200") /*|| data[45] != 1*/) { throw new Exception(string.Format( "Playlist {0} has an unknown file type {1}.", fileInfo.Name, fileType)); } List <Clip> chapterClips = GetClips(data); pgc.Duration = new TimeSpan((long)(chapterClips.Sum(c => c.Length) * (double)TimeSpan.TicksPerSecond)); int chaptersIndex = ((int)data[12] << 24) + ((int)data[13] << 16) + ((int)data[14] << 8) + ((int)data[15]); int chaptersLength = ((int)data[chaptersIndex] << 24) + ((int)data[chaptersIndex + 1] << 16) + ((int)data[chaptersIndex + 2] << 8) + ((int)data[chaptersIndex + 3]); byte[] chapterData = new byte[chaptersLength]; Array.Copy(data, chaptersIndex + 4, chapterData, 0, chaptersLength); int chapterCount = ((int)chapterData[0] << 8) + chapterData[1]; int chapterOffset = 2; for (int chapterIndex = 0; chapterIndex < chapterCount; chapterIndex++) { if (chapterData[chapterOffset + 1] == 1) { int streamFileIndex = ((int)chapterData[chapterOffset + 2] << 8) + chapterData[chapterOffset + 3]; Clip streamClip = chapterClips[streamFileIndex]; long chapterTime = ((long)chapterData[chapterOffset + 4] << 24) + ((long)chapterData[chapterOffset + 5] << 16) + ((long)chapterData[chapterOffset + 6] << 8) + ((long)chapterData[chapterOffset + 7]); double chapterSeconds = (double)chapterTime / 45000D; double relativeSeconds = chapterSeconds - streamClip.TimeIn + streamClip.RelativeTimeIn; chapters.Add(new Chapter() { Name = "Chapter " + (chapterIndex + 1).ToString("D2"),//string.Empty, Time = new TimeSpan((long)(relativeSeconds * (double)TimeSpan.TicksPerSecond)) }); } chapterOffset += 14; } pgc.Chapters = chapters; MediaInfoFile oInfo = new MediaInfoFile(pgc.SourceName); pgc.FramesPerSecond = oInfo.VideoInfo.FPS; OnStreamDetected(pgc); OnChaptersLoaded(pgc); OnExtractionComplete(); return(new List <ChapterInfo>() { pgc }); }
public override List <ChapterInfo> GetStreams(string location) { List <ChapterInfo> pgcs = new List <ChapterInfo>(); XDocument doc = XDocument.Load(location); XNamespace ns = "http://www.dvdforum.org/2005/HDDVDVideo/Playlist"; foreach (XElement ts in doc.Element(ns + "Playlist").Elements(ns + "TitleSet")) { float timeBase = GetFps((string)ts.Attribute("timeBase")); float tickBase = GetFps((string)ts.Attribute("tickBase")); foreach (XElement title in ts.Elements(ns + "Title").Where(t => t.Element(ns + "ChapterList") != null)) { ChapterInfo pgc = new ChapterInfo(); List <Chapter> chapters = new List <Chapter>(); pgc.SourceName = location; pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location); pgc.SourceType = "HD-DVD"; pgc.FramesPerSecond = 24D; OnStreamDetected(pgc); int tickBaseDivisor = (int?)title.Attribute("tickBaseDivisor") ?? 1; pgc.Duration = GetTimeSpan((string)title.Attribute("titleDuration"), timeBase, tickBase, tickBaseDivisor); string titleName = Path.GetFileNameWithoutExtension(location); if (title.Attribute("id") != null) { titleName = (string)title.Attribute("id"); } if (title.Attribute("displayName") != null) { titleName = (string)title.Attribute("displayName"); } pgc.Title = titleName; int count = 0; foreach (XElement chapter in title.Element(ns + "ChapterList").Elements(ns + "Chapter")) { if (string.IsNullOrEmpty((string)chapter.Attribute("displayName"))) { chapters.Add(new Chapter() { Name = "Chapter " + (count + 1).ToString("D2"), Time = GetTimeSpan((string)chapter.Attribute("titleTimeBegin"), timeBase, tickBase, tickBaseDivisor) }); } else { chapters.Add(new Chapter() { Name = (string)chapter.Attribute("displayName"), Time = GetTimeSpan((string)chapter.Attribute("titleTimeBegin"), timeBase, tickBase, tickBaseDivisor) }); } count++; } pgc.Chapters = chapters; OnChaptersLoaded(pgc); //pgc.ChangeFps(24D / 1.001D); pgcs.Add(pgc); } } pgcs = pgcs.OrderByDescending(p => p.Duration).ToList(); OnExtractionComplete(); return(pgcs); }