private static bool HasMatroskaChapter(TaskDetail task) { FileInfo inputFile = new FileInfo(task.InputFile); if (inputFile.Extension.ToLower() != ".mkv") { Logger.Warn($"{task.InputFile}不是Matroska文件。"); return(false); } MediaInfo.MediaInfo MI = new MediaInfo.MediaInfo(); MI.Open(inputFile.FullName); MI.Option("Complete"); int.TryParse(MI.Get(StreamKind.General, 0, "MenuCount"), out var MenuCount); if (MenuCount == 0) { Logger.Warn($"{task.InputFile}内不含有章节。"); MI?.Close(); return(false); } MI?.Close(); return(true); }
public void Prepare(string path, ContextObject context) { _context = context; try { _mediaInfo = new MediaInfo.MediaInfo(Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Environment.Is64BitProcess ? "MediaInfo-x64\\" : "MediaInfo-x86\\")); _mediaInfo.Option("Cover_Data", "base64"); _mediaInfo.Open(path); } catch (Exception) { _mediaInfo?.Dispose(); _mediaInfo = null; } context.TitlebarOverlap = true; if (_mediaInfo == null || !string.IsNullOrWhiteSpace(_mediaInfo.Get(StreamKind.General, 0, "VideoCount"))) // video { int.TryParse(_mediaInfo?.Get(StreamKind.Video, 0, "Width"), out var width); int.TryParse(_mediaInfo?.Get(StreamKind.Video, 0, "Height"), out var height); double.TryParse(_mediaInfo?.Get(StreamKind.Video, 0, "Rotation"), out var rotation); // Correct rotation: on some machine the value "90" becomes "90000" by some reason if (rotation > 360) { rotation /= 1e3; } var windowSize = new Size { Width = Math.Max(100, width == 0 ? 1366 : width), Height = Math.Max(100, height == 0 ? 768 : height) }; if (rotation % 180 != 0) { windowSize = new Size(windowSize.Height, windowSize.Width); } context.SetPreferredSizeFit(windowSize, 0.8); context.TitlebarAutoHide = true; context.Theme = Themes.Dark; context.TitlebarBlurVisibility = true; } else // audio { context.PreferredSize = new Size(500, 300); context.CanResize = false; context.TitlebarAutoHide = false; context.TitlebarBlurVisibility = false; context.TitlebarColourVisibility = false; } }
static Plugin() { _mediaInfo = new MediaInfo.MediaInfo(Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Environment.Is64BitProcess ? "MediaInfo-x64\\" : "MediaInfo-x86\\")); _mediaInfo.Option("Cover_Data", "base64"); }
private string ProcessDvd(string filePath, NumberFormatInfo providerNumber) #endif { IsDvd = true; var path = Path.GetDirectoryName(filePath) ?? string.Empty; Size = GetDirectorySize(path); var bups = Directory.GetFiles(path, "*.BUP", SearchOption.TopDirectoryOnly); var programBlocks = new List <Tuple <string, int> >(); foreach (var bupFile in bups) { #if (NET40 || NET45) using (var mi = new MediaInfo(pathToDll)) #else using (var mi = new MediaInfo()) #endif { Version = mi.Option("Info_Version"); mi.Open(bupFile); var profile = mi.Get(StreamKind.General, 0, "Format_Profile"); if (profile == "Program") { double.TryParse( mi.Get(StreamKind.Video, 0, "Duration"), NumberStyles.AllowDecimalPoint, providerNumber, out var duration); programBlocks.Add(new Tuple <string, int>(bupFile, (int)duration)); } } } // get all other info from main title's 1st vob if (programBlocks.Any()) { Duration = programBlocks.Max(x => x.Item2); filePath = programBlocks.First(x => x.Item2 == Duration).Item1; } return(filePath); }
public static string Scan(string MediaPath, MediaInfoScanType ScanType = MediaInfoScanType.Full) { try { //MediaInfoWrapper mediaInfoWrapper = new MediaInfoWrapper(MediaPath); using (var mediaInfo = new MediaInfo.MediaInfo(DllPath)) //MediaInfo Dll { mediaInfo.Open(MediaPath); if (ScanType == MediaInfoScanType.Full) { mediaInfo.Option("Complete"); } return(mediaInfo.Inform()); } } catch (Exception ex) { return(""); } }
private void ExtractInfo(string filePath, string pathToDll, NumberFormatInfo providerNumber) { using (var mediaInfo = new MediaInfo(pathToDll)) { Version = mediaInfo.Option("Info_Version"); mediaInfo.Open(filePath); var streamNumber = 0; // Setup videos for (var i = 0; i < mediaInfo.CountGet(StreamKind.Video); ++i) { VideoStreams.Add(new VideoStreamBuilder(mediaInfo, streamNumber++, i).Build()); } if (VideoDuration == 0) { double duration; double.TryParse( mediaInfo.Get(StreamKind.Video, 0, "Duration"), NumberStyles.AllowDecimalPoint, providerNumber, out duration); VideoDuration = (int)duration; } // Setup audios for (var i = 0; i < mediaInfo.CountGet(StreamKind.Audio); ++i) { AudioStreams.Add(new AudioStreamBuilder(mediaInfo, streamNumber++, i).Build()); } // Setup subtitles for (var i = 0; i < mediaInfo.CountGet(StreamKind.Text); ++i) { Subtitles.Add(new SubtitleStreamBuilder(mediaInfo, streamNumber++, i).Build()); } // Setup chapters for (var i = 0; i < mediaInfo.CountGet(StreamKind.Other); ++i) { Chapters.Add(new ChapterStreamBuilder(mediaInfo, streamNumber++, i).Build()); } // Setup menus for (var i = 0; i < mediaInfo.CountGet(StreamKind.Menu); ++i) { MenuStreams.Add(new MenuStreamBuilder(mediaInfo, streamNumber++, i).Build()); } MediaInfoNotloaded = VideoStreams.Count == 0 && AudioStreams.Count == 0 && Subtitles.Count == 0; // Produce copability properties if (MediaInfoNotloaded) { SetPropertiesDefault(); } else { SetupProperties(mediaInfo); } } }
private void ExtractInfo(string filePath, NumberFormatInfo providerNumber) #endif { #if (NET40 || NET45) using (var mediaInfo = new MediaInfo(pathToDll)) #else using (var mediaInfo = new MediaInfo()) #endif { if (mediaInfo.Handle == IntPtr.Zero) { MediaInfoNotloaded = true; _logger.LogWarning("MediaInfo library was not loaded!"); return; } else { Version = mediaInfo.Option("Info_Version"); _logger.LogDebug($"MediaInfo library was loaded. Handle={mediaInfo.Handle} Version is {Version}"); } var filePricessingHandle = mediaInfo.Open(filePath); if (filePricessingHandle == IntPtr.Zero) { MediaInfoNotloaded = true; _logger.LogWarning($"MediaInfo library has not been opened media {filePath}"); return; } else { _logger.LogDebug($"MediaInfo library successfully opened {filePath}. Handle={filePricessingHandle}"); } var streamNumber = 0; Tags = new AudioTagBuilder(mediaInfo, 0).Build(); // Setup videos for (var i = 0; i < mediaInfo.CountGet(StreamKind.Video); ++i) { VideoStreams.Add(new VideoStreamBuilder(mediaInfo, streamNumber++, i).Build()); } if (Duration == 0) { double.TryParse( mediaInfo.Get(StreamKind.Video, 0, (int)NativeMethods.Video.Video_Duration), NumberStyles.AllowDecimalPoint, providerNumber, out var duration); Duration = (int)duration; } // Fix 3D for some containers if (VideoStreams.Count == 1 && Tags.GeneralTags.TryGetValue((NativeMethods.General) 1000, out var isStereo)) { var video = VideoStreams.First(); if (Tags.GeneralTags.TryGetValue((NativeMethods.General) 1001, out var stereoMode)) { video.Stereoscopic = (StereoMode)stereoMode; } else { video.Stereoscopic = (bool)isStereo ? StereoMode.Stereo : StereoMode.Mono; } } // Setup audios for (var i = 0; i < mediaInfo.CountGet(StreamKind.Audio); ++i) { AudioStreams.Add(new AudioStreamBuilder(mediaInfo, streamNumber++, i).Build()); } if (Duration == 0) { double.TryParse( mediaInfo.Get(StreamKind.Audio, 0, (int)NativeMethods.Audio.Audio_Duration), NumberStyles.AllowDecimalPoint, providerNumber, out var duration); Duration = (int)duration; } // Setup subtitles for (var i = 0; i < mediaInfo.CountGet(StreamKind.Text); ++i) { Subtitles.Add(new SubtitleStreamBuilder(mediaInfo, streamNumber++, i).Build()); } // Setup chapters for (var i = 0; i < mediaInfo.CountGet(StreamKind.Other); ++i) { Chapters.Add(new ChapterStreamBuilder(mediaInfo, streamNumber++, i).Build()); } // Setup menus for (var i = 0; i < mediaInfo.CountGet(StreamKind.Menu); ++i) { MenuStreams.Add(new MenuStreamBuilder(mediaInfo, streamNumber++, i).Build()); } MediaInfoNotloaded = VideoStreams.Count == 0 && AudioStreams.Count == 0 && Subtitles.Count == 0; // Produce capability properties if (MediaInfoNotloaded) { SetPropertiesDefault(); } else { SetupProperties(mediaInfo); } } }
public int Priority => - 3; // make it lower than TextViewer static Plugin() { _mediaInfo = new MediaInfo.MediaInfo(Assembly.GetExecutingAssembly().Location); _mediaInfo.Option("Cover_Data", "base64"); }