void AdaptRefreshRateFromCacheFile() { if (!PluginConfiguration.Instance.AllowRefreshRateChange) { refreshRateAdapted = true; return; } if (!string.IsNullOrEmpty(cacheFile)) { try { MediaInfo mi = new MediaInfo(); int hr = mi.Open(cacheFile); double framerate; double.TryParse(mi.Get(StreamKind.Video, 0, "FrameRate"), System.Globalization.NumberStyles.AllowDecimalPoint, new System.Globalization.NumberFormatInfo() { NumberDecimalSeparator = "." }, out framerate); if (framerate > 1) { Log.Instance.Info("OnlineVideosPlayer got {0} FPS from MediaInfo", framerate); double matchedFps = RefreshRateHelper.MatchConfiguredFPS(framerate); if (matchedFps != default(double)) { refreshRateAdapted = true; RefreshRateHelper.ChangeRefreshRateToMatchedFps(matchedFps, cacheFile); try { if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.EVR) EVRUpdateDisplayFPS(); } catch (EntryPointNotFoundException) { Log.Instance.Warn("OnlineVideosPlayer: Your version of dshowhelper.dll does not support FPS updating."); } catch (Exception ex) { Log.Instance.Warn("OnlineVideosPlayer: Exception trying update refresh rate fo EVR: {0}", ex.ToString()); } } else { Log.Instance.Info("No matching configured FPS found - skipping RefreshRate Adaption from Cache File"); } } else { Log.Instance.Info("OnlineVideosPlayer got no FPS from MediaInfo"); } } catch (Exception ex) { Log.Instance.Warn("OnlineVideosPlayer: Exception trying refresh rate change from cache file: {0}", ex.ToString()); } } else { Log.Instance.Info("OnlineVideosPlayer: No cache file, skipping FPS detection via MediaInfo"); } }
public MediaInfoWrapper(string strFile, bool useMediaInfo, int cachedMISubtitleCount, bool useLocalOnly, bool checkAll) { bool isTV = MediaPortal.Util.Utils.IsLiveTv(strFile); bool isRadio = MediaPortal.Util.Utils.IsLiveRadio(strFile); bool isDVD = MediaPortal.Util.Utils.IsDVD(strFile); bool isVideo = MediaPortal.Util.Utils.IsVideo(strFile); bool isAVStream = MediaPortal.Util.Utils.IsAVStream(strFile); //rtsp users for live TV and recordings. if (isTV || isRadio || isAVStream) { return; } logger.Debug("MediaInfoWrapper: Inspecting media : {0}", strFile); if (cachedMISubtitleCount > -1) { _numSubtitles = cachedMISubtitleCount; useMediaInfo = false; } if (useLocalOnly) { _numSubtitles = 0; useMediaInfo = false; } _hasExternalSubtitles = checkHasExternalSubtitles(strFile, useLocalOnly, checkAll); if (useMediaInfo) { try { logger.Debug("MediaInfoWrapper: Trying to use MediaInfo"); _mI = new MediaInfo(); _mI.Open(strFile); int.TryParse(_mI.Get(StreamKind.General, 0, "TextCount"), out _numSubtitles); } catch (Exception e) { logger.ErrorException(string.Format("MediaInfoWrapper: MediaInfo processing failed ('MediaInfo.dll' may be missing){0}", Environment.NewLine), e); } finally { if (_mI != null) { _mI.Close(); } } } if (_hasExternalSubtitles) { _hasSubtitles = true; } else if (_numSubtitles > 0) { _hasSubtitles = true; } else { _hasSubtitles = false; } logger.Debug("MediaInfoWrapper: HasExternalSubtitles : {0}", _hasExternalSubtitles); logger.Debug("MediaInfoWrapper: HasSubtitles : {0}", _hasSubtitles); logger.Debug("MediaInfoWrapper: NumSubtitles : {0}", _numSubtitles); }
public MediaInfoWrapper(string strFile) { bool isTV = Util.Utils.IsLiveTv(strFile); bool isRadio = Util.Utils.IsLiveRadio(strFile); bool isDVD = Util.Utils.IsDVD(strFile); bool isVideo = Util.Utils.IsVideo(strFile); bool isAVStream = Util.Utils.IsAVStream(strFile); //rtsp users for live TV and recordings. if (isTV || isRadio || isAVStream) { return; } try { _mI = new MediaInfo(); _mI.Open(strFile); FileInfo fileInfo = strFile.PathToFileInfo(); DriveInfo driveInfo = fileInfo.GetDriveInfo(); NumberFormatInfo providerNumber = new NumberFormatInfo(); providerNumber.NumberDecimalSeparator = "."; double.TryParse(_mI.Get(StreamKind.Video, 0, "FrameRate"), NumberStyles.AllowDecimalPoint, providerNumber, out _framerate); _videoCodec = _mI.Get(StreamKind.Video, 0, "Codec").ToLower(); _scanType = _mI.Get(StreamKind.Video, 0, "ScanType").ToLower(); int.TryParse(_mI.Get(StreamKind.Video, 0, "Width"), out _width); int.TryParse(_mI.Get(StreamKind.Video, 0, "Height"), out _height); int.TryParse(_mI.Get(StreamKind.General, 0, "TextCount"), out _numSubtitles); int.TryParse(_mI.Get(StreamKind.Video, 0, "MultiView_Count"), out _multiview_count); _multiview_layout = _mI.Get(StreamKind.Video, 0, "MultiView_Layout"); string aspectStr = _mI.Get(StreamKind.Video, 0, "AspectRatio/String"); if (aspectStr == "4/3" || aspectStr == "4:3") _aspectRatio = "fullscreen"; else _aspectRatio = "widescreen"; if (strFile.ToLower().EndsWith(".ifo") && driveInfo != null && driveInfo.IsOptical()) { // mediainfo is not able to obtain duration of IFO files // so we use this to loop through all corresponding VOBs and add up the duration // we do not do this for optical drives because there are issues with some discs // taking more than 2 minutes(copy protection?) _duration = 0; string filePrefix = Path.GetFileName(strFile); filePrefix = filePrefix.Substring(0, filePrefix.LastIndexOf('_')); MediaInfo mi = new MediaInfo(); foreach (string file in Directory.GetFiles(Path.GetDirectoryName(strFile), filePrefix + "*.VOB")) { mi.Open(file); int durationPart = 0; int.TryParse(_mI.Get(StreamKind.Video, 0, "PlayTime"), out durationPart); _duration += durationPart; } } else { int.TryParse(_mI.Get(StreamKind.Video, 0, "PlayTime"), out _duration); } _isInterlaced = (_scanType.IndexOf("interlaced") > -1); if (_height >= 720) { _isHDTV = true; } else { _isSDTV = true; } if ((_width == 1280 || _height == 720) && !_isInterlaced) { _is720P = true; } if ((_width == 1920 || _height == 1080) && !_isInterlaced) { _is1080P = true; } if ((_width == 1920 || _height == 1080) && _isInterlaced) { _is1080I = true; } _isDIVX = (_videoCodec.IndexOf("dx50") > -1) | (_videoCodec.IndexOf("div3") > -1); // DivX 5 and DivX 3 _isXVID = (_videoCodec.IndexOf("xvid") > -1); _isH264 = (_videoCodec.IndexOf("avc") > -1 || _videoCodec.IndexOf("h264") > -1); _isMP1V = (_videoCodec.IndexOf("mpeg-1v") > -1); _isMP2V = (_videoCodec.IndexOf("mpeg-2v") > -1); _isMP4V = (_videoCodec.IndexOf("fmp4") > -1); // add more _isWMV = (_videoCodec.IndexOf("wmv") > -1); // wmv3 = WMV9 _is3D = (_multiview_count > 1); // Probably 3D // missing cvid etc if (checkHasExternalSubtitles(strFile)) { _hasSubtitles = true; } else if (_numSubtitles > 0) { _hasSubtitles = true; } else { _hasSubtitles = false; } logger.Debug("MediaInfoWrapper: inspecting media : {0}", strFile); logger.Debug("MediaInfoWrapper: --- Video Information ---"); logger.Debug("MediaInfoWrapper: FrameRate : {0}", _framerate); logger.Debug("MediaInfoWrapper: VideoCodec : {0}", _videoCodec); if (_isDIVX) logger.Debug("MediaInfoWrapper: IsDIVX: {0}", _isDIVX); if (_isXVID) logger.Debug("MediaInfoWrapper: IsXVID: {0}", _isXVID); if (_isH264) logger.Debug("MediaInfoWrapper: IsH264: {0}", _isH264); if (_isMP1V) logger.Debug("MediaInfoWrapper: IsMP1V: {0}", _isMP1V); if (_isMP2V) logger.Debug("MediaInfoWrapper: IsMP2V: {0}", _isMP2V); if (_isMP4V) logger.Debug("MediaInfoWrapper: IsMP4V: {0}", _isMP4V); if (_isWMV) logger.Debug("MediaInfoWrapper: IsWMV: {0}", _isWMV); logger.Debug("MediaInfoWrapper: HasSubtitles : {0}", _hasSubtitles); logger.Debug("MediaInfoWrapper: NumSubtitles : {0}", _numSubtitles); logger.Debug("MediaInfoWrapper: Scan type : {0}", _scanType); logger.Debug("MediaInfoWrapper: IsInterlaced: {0}", _isInterlaced); logger.Debug("MediaInfoWrapper: Width : {0}", _width); logger.Debug("MediaInfoWrapper: Height : {0}", _height); logger.Debug("MediaInfoWrapper: AspectRatio : {0}", _aspectRatio); logger.Debug(""); // Retrieve Audio Information GetAudioInformation(); // Retrieve Subtitle Information GetSubtitleInformation(); int numMenus; if ((int.TryParse(_mI.Get(StreamKind.General, 0, "MenuCount"), out numMenus)) && numMenus > 0) _hasChapters = true; logger.Debug("MediaInfoWrapper: Has Chapters: {0}", _hasChapters); } catch (Exception ex) { logger.Error("MediaInfo processing failed ('MediaInfo.dll' may be missing): {0}", ex.Message); } finally { if (_mI != null) { _mI.Close(); } } }
public MediaInfoWrapper(string strFile) { if (!MediaInfoExist()) { return; } using (Settings xmlreader = new MPSettings()) { _DVDenabled = xmlreader.GetValueAsBool("dvdplayer", "mediainfoused", false); _ParseSpeed = xmlreader.GetValueAsString("debug", "MediaInfoParsespeed", "0.3"); // fix delay introduced after 0.7.26: http://sourceforge.net/tracker/?func=detail&aid=3013548&group_id=86862&atid=581181 } bool isTV = Util.Utils.IsLiveTv(strFile); bool isRadio = Util.Utils.IsLiveRadio(strFile); bool isRTSP = Util.Utils.IsRTSP(strFile); //rtsp for live TV and recordings. bool isDVD = Util.Utils.IsDVD(strFile); bool isVideo = Util.Utils.IsVideo(strFile); bool isAVStream = Util.Utils.IsAVStream(strFile); //other AV streams //currently disabled for all tv/radio/streaming video if (isTV || isRadio || isRTSP || isAVStream) { Log.Debug("MediaInfoWrapper: isTv:{0}, isRadio:{1}, isRTSP:{2}, isAVStream:{3}", isTV, isRadio, isRTSP, isAVStream); Log.Debug("MediaInfoWrapper: disabled for this content"); return; } //currently mediainfo is only used for local video related material (if enabled) if ((!isVideo && !isDVD) || (isDVD && !_DVDenabled)) { Log.Debug("MediaInfoWrapper: isVideo:{0}, isDVD:{1}[enabled:{2}]", isVideo, isDVD, _DVDenabled); Log.Debug("MediaInfoWrapper: disabled for this content"); return; } try { _mI = new MediaInfo(); _mI.Option("ParseSpeed", _ParseSpeed); if (Util.VirtualDirectory.IsImageFile(System.IO.Path.GetExtension(strFile))) strFile = Util.DaemonTools.GetVirtualDrive() + @"\VIDEO_TS\VIDEO_TS.IFO"; if (strFile.ToLower().EndsWith(".ifo")) { string path = Path.GetDirectoryName(strFile); string mainTitle = GetLargestFileInDirectory(path, "VTS_*1.VOB"); string titleSearch = Path.GetFileName(mainTitle); titleSearch = titleSearch.Substring(0, titleSearch.LastIndexOf('_')) + "*.VOB"; string[] vobs = Directory.GetFiles(path, titleSearch, SearchOption.TopDirectoryOnly); foreach (string vob in vobs) { int vobDuration = 0; _mI.Open(vob); int.TryParse(_mI.Get(StreamKind.General, 0, "Duration"), out vobDuration); _mI.Close(); _videoDuration += vobDuration; } // get all other info from main title's 1st vob strFile = mainTitle; } _mI.Open(strFile); NumberFormatInfo providerNumber = new NumberFormatInfo(); providerNumber.NumberDecimalSeparator = "."; //Video double.TryParse(_mI.Get(StreamKind.Video, 0, "FrameRate"), NumberStyles.AllowDecimalPoint, providerNumber, out _framerate); int.TryParse(_mI.Get(StreamKind.Video, 0, "Width"), out _width); int.TryParse(_mI.Get(StreamKind.Video, 0, "Height"), out _height); _aspectRatio = _mI.Get(StreamKind.Video, 0, "Display AspectRatio") == "4:3" ? "fullscreen" : "widescreen"; _videoCodec = GetFullCodecName(StreamKind.Video); _scanType = _mI.Get(StreamKind.Video, 0, "ScanType").ToLower(); _isInterlaced = _scanType.Contains("interlaced"); _videoResolution = _height < 720 ? "SD" : "HD"; if ((_width == 1280 || _height == 720) && !_isInterlaced) { _videoResolution = "720P"; } if ((_width == 1920 || _height == 1080) && !_isInterlaced) { _videoResolution = "1080P"; } if ((_width == 1920 || _height == 1080) && _isInterlaced) { _videoResolution = "1080I"; } if (_videoDuration == 0) { int.TryParse(_mI.Get(StreamKind.Video, 0, "Duration"), out _videoDuration); } //Audio int iAudioStreams = _mI.Count_Get(StreamKind.Audio); for (int i = 0; i < iAudioStreams; i++) { int intValue; string sChannels = _mI.Get(StreamKind.Audio, i, "Channel(s)").Split(new char[] {'/'})[0].Trim(); if (int.TryParse(sChannels, out intValue) && intValue > _audioChannels) { int.TryParse(_mI.Get(StreamKind.Audio, i, "SamplingRate"), out _audioRate); _audioChannels = intValue; _audioCodec = GetFullCodecName(StreamKind.Audio, i); } } switch (_audioChannels) { case 8: _audioChannelsFriendly = "7.1"; break; case 7: _audioChannelsFriendly = "6.1"; break; case 6: _audioChannelsFriendly = "5.1"; break; case 2: _audioChannelsFriendly = "stereo"; break; case 1: _audioChannelsFriendly = "mono"; break; default: _audioChannelsFriendly = _audioChannels.ToString(); break; } //Detection _hasAudio = _mI.Count_Get(StreamKind.Audio) > 0; _hasVideo = _mI.Count_Get(StreamKind.Video) > 0; //Subtitles _numsubtitles = _mI.Count_Get(StreamKind.Text); if (checkHasExternalSubtitles(strFile)) { _hasSubtitles = true; } else { _hasSubtitles = _numsubtitles > 0; } Log.Info("MediaInfoWrapper.MediaInfoWrapper: DLL Version : {0}", _mI.Option("Info_Version")); Log.Info("MediaInfoWrapper.MediaInfoWrapper: Inspecting media : {0}", strFile); Log.Info("MediaInfoWrapper.MediaInfoWrapper: Parse speed : {0}", _ParseSpeed); //Video Log.Info("MediaInfoWrapper.MediaInfoWrapper: FrameRate : {0}", _framerate); Log.Info("MediaInfoWrapper.MediaInfoWrapper: Width : {0}", _width); Log.Info("MediaInfoWrapper.MediaInfoWrapper: Height : {0}", _height); Log.Info("MediaInfoWrapper.MediaInfoWrapper: AspectRatio : {0}", _aspectRatio); Log.Info("MediaInfoWrapper.MediaInfoWrapper: VideoCodec : {0} [ \"{1}.png\" ]", _videoCodec, Util.Utils.MakeFileName(_videoCodec).ToLower()); Log.Info("MediaInfoWrapper.MediaInfoWrapper: Scan type : {0}", _scanType); Log.Info("MediaInfoWrapper.MediaInfoWrapper: IsInterlaced : {0}", _isInterlaced); Log.Info("MediaInfoWrapper.MediaInfoWrapper: VideoResolution : {0}", _videoResolution); Log.Info("MediaInfoWrapper.MediaInfoWrapper: VideoDuration : {0}", _videoDuration); //Audio Log.Info("MediaInfoWrapper.MediaInfoWrapper: AudioRate : {0}", _audioRate); Log.Info("MediaInfoWrapper.MediaInfoWrapper: AudioChannels : {0} [ \"{1}.png\" ]", _audioChannels, _audioChannelsFriendly); Log.Info("MediaInfoWrapper.MediaInfoWrapper: AudioCodec : {0} [ \"{1}.png\" ]", _audioCodec, Util.Utils.MakeFileName(_audioCodec).ToLower()); //Detection Log.Info("MediaInfoWrapper.MediaInfoWrapper: HasAudio : {0}", _hasAudio); Log.Info("MediaInfoWrapper.MediaInfoWrapper: HasVideo : {0}", _hasVideo); //Subtitles Log.Info("MediaInfoWrapper.MediaInfoWrapper: HasSubtitles : {0}", _hasSubtitles); Log.Info("MediaInfoWrapper.MediaInfoWrapper: NumSubtitles : {0}", _numsubtitles); } catch (Exception) { Log.Error( "MediaInfoWrapper.MediaInfoWrapper: Error occurred while scanning media: '{0}'", strFile); } finally { if (_mI != null) { _mI.Close(); } } }
public MediaInfoWrapper(string strFile) { bool isTV = MediaPortal.Util.Utils.IsLiveTv(strFile); bool isRadio = MediaPortal.Util.Utils.IsLiveRadio(strFile); bool isDVD = MediaPortal.Util.Utils.IsDVD(strFile); bool isVideo = MediaPortal.Util.Utils.IsVideo(strFile); bool isAVStream = MediaPortal.Util.Utils.IsAVStream(strFile); //rtsp users for live TV and recordings. if (isTV || isRadio || isAVStream) { return; } try { _mI = new MediaInfo(); _mI.Open(strFile); FileInfo fileInfo = strFile.PathToFileInfo(); DriveInfo driveInfo = fileInfo.GetDriveInfo(); NumberFormatInfo providerNumber = new NumberFormatInfo(); providerNumber.NumberDecimalSeparator = "."; double.TryParse(_mI.Get(StreamKind.Video, 0, "FrameRate"), NumberStyles.AllowDecimalPoint, providerNumber, out _framerate); _videoCodec = _mI.Get(StreamKind.Video, 0, "Codec").ToLower(); _scanType = _mI.Get(StreamKind.Video, 0, "ScanType").ToLower(); int.TryParse(_mI.Get(StreamKind.Video, 0, "Width"), out _width); int.TryParse(_mI.Get(StreamKind.Video, 0, "Height"), out _height); int.TryParse(_mI.Get(StreamKind.General, 0, "TextCount"), out _numSubtitles); int intValue; int iAudioStreams = _mI.Count_Get(StreamKind.Audio); for (int i = 0; i < iAudioStreams; i++) { string sChannels = Regex.Split(_mI.Get(StreamKind.Audio, i, "Channel(s)"), @"\D+").Max(); if (int.TryParse(sChannels, out intValue) && intValue > _audioChannels) { _audioChannels = intValue; int.TryParse(_mI.Get(StreamKind.Audio, i, "SamplingRate"), out _audioRate); _audioCodec = _mI.Get(StreamKind.Audio, i, "Codec/String").ToLower(); _audioFormatProfile = _mI.Get(StreamKind.Audio, i, "Format_Profile").ToLower(); } } string aspectStr = _mI.Get(StreamKind.Video, 0, "AspectRatio/String"); if (aspectStr == "4/3" || aspectStr == "4:3") _aspectRatio = "fullscreen"; else _aspectRatio = "widescreen"; if (strFile.ToLower().EndsWith(".ifo") && driveInfo != null && driveInfo.IsOptical()) { // mediainfo is not able to obtain duration of IFO files // so we use this to loop through all corresponding VOBs and add up the duration // we do not do this for optical drives because there are issues with some discs // taking more than 2 minutes(copy protection?) _duration = 0; string filePrefix = Path.GetFileName(strFile); filePrefix = filePrefix.Substring(0, filePrefix.LastIndexOf('_')); MediaInfo mi = new MediaInfo(); foreach (string file in Directory.GetFiles(Path.GetDirectoryName(strFile), filePrefix + "*.VOB")) { mi.Open(file); int durationPart = 0; int.TryParse(_mI.Get(StreamKind.Video, 0, "PlayTime"), out durationPart); _duration += durationPart; } } else { int.TryParse(_mI.Get(StreamKind.Video, 0, "PlayTime"), out _duration); } _isInterlaced = (_scanType.IndexOf("interlaced") > -1); if (_height >= 720) { _isHDTV = true; } else { _isSDTV = true; } if ((_width == 1280 || _height == 720) && !_isInterlaced) { _is720P = true; } if ((_width == 1920 || _height == 1080) && !_isInterlaced) { _is1080P = true; } if ((_width == 1920 || _height == 1080) && _isInterlaced) { _is1080I = true; } _isDIVX = (_videoCodec.IndexOf("dx50") > -1) | (_videoCodec.IndexOf("div3") > -1); // DivX 5 and DivX 3 _isXVID = (_videoCodec.IndexOf("xvid") > -1); _isH264 = (_videoCodec.IndexOf("avc") > -1 || _videoCodec.IndexOf("h264") > -1); _isMP1V = (_videoCodec.IndexOf("mpeg-1v") > -1); _isMP2V = (_videoCodec.IndexOf("mpeg-2v") > -1); _isMP4V = (_videoCodec.IndexOf("fmp4") > -1); // add more _isWMV = (_videoCodec.IndexOf("wmv") > -1); // wmv3 = WMV9 // missing cvid etc _isAC3 = (System.Text.RegularExpressions.Regex.IsMatch(_audioCodec, "ac-?3")); _isMP3 = (_audioCodec.IndexOf("mpeg-1 audio layer 3") > -1) || (_audioCodec.IndexOf("mpeg-2 audio layer 3") > -1); _isMP2A = (_audioCodec.IndexOf("mpeg-1 audio layer 2") > -1); _isDTS = (_audioCodec.IndexOf("dts") > -1); _isOGG = (_audioCodec.IndexOf("ogg") > -1); _isAAC = (_audioCodec.IndexOf("aac") > -1); _isWMA = (_audioCodec.IndexOf("wma") > -1); // e.g. wma3 _isPCM = (_audioCodec.IndexOf("pcm") > -1); _isTrueHD = (_audioCodec.Contains("truehd") || _audioFormatProfile.Contains("truehd")); _isDTSHD = (_audioCodec.Contains("dts") && (_audioFormatProfile.Contains("hra") || _audioFormatProfile.Contains("ma"))); if (checkHasExternalSubtitles(strFile)) { _hasSubtitles = true; } else if (_numSubtitles > 0) { _hasSubtitles = true; } else { _hasSubtitles = false; } //logger.Debug("MediaInfoWrapper: inspecting media : {0}", strFile); //logger.Debug("MediaInfoWrapper: FrameRate : {0}", _framerate); //logger.Debug("MediaInfoWrapper: VideoCodec : {0}", _videoCodec); //if (_isDIVX) // logger.Debug("MediaInfoWrapper: IsDIVX: {0}", _isDIVX); //if (_isXVID) // logger.Debug("MediaInfoWrapper: IsXVID: {0}", _isXVID); //if (_isH264) // logger.Debug("MediaInfoWrapper: IsH264: {0}", _isH264); //if (_isMP1V) // logger.Debug("MediaInfoWrapper: IsMP1V: {0}", _isMP1V); //if (_isMP2V) // logger.Debug("MediaInfoWrapper: IsMP2V: {0}", _isMP2V); //if (_isMP4V) // logger.Debug("MediaInfoWrapper: IsMP4V: {0}", _isMP4V); //if (_isWMV) // logger.Debug("MediaInfoWrapper: IsWMV: {0}", _isWMV); //logger.Debug("MediaInfoWrapper: HasSubtitles : {0}", _hasSubtitles); //logger.Debug("MediaInfoWrapper: NumSubtitles : {0}", _numSubtitles); //logger.Debug("MediaInfoWrapper: Scan type : {0}", _scanType); //logger.Debug("MediaInfoWrapper: IsInterlaced: {0}", _isInterlaced); //logger.Debug("MediaInfoWrapper: Width : {0}", _width); //logger.Debug("MediaInfoWrapper: Height : {0}", _height); //logger.Debug("MediaInfoWrapper: Audiochannels : {0}", _audioChannels); //logger.Debug("MediaInfoWrapper: Audiorate : {0}", _audioRate); //logger.Debug("MediaInfoWrapper: AspectRatio : {0}", _aspectRatio); //logger.Debug("MediaInfoWrapper: AudioCodec : {0}", _audioCodec); //if (_isAC3) // logger.Debug("MediaInfoWrapper: IsAC3 : {0}", _isAC3); //if (_isMP3) // logger.Debug("MediaInfoWrapper: IsMP3 : {0}", _isMP3); //if (_isMP2A) // logger.Debug("MediaInfoWrapper: IsMP2A: {0}", _isMP2A); //if (_isDTS) // logger.Debug("MediaInfoWrapper: IsDTS : {0}", _isDTS); //if (_isTrueHD) // logger.Debug("MediaInfoWrapper: IsTrueHD : {0}", _isTrueHD); //if (_isDTSHD) // logger.Debug("MediaInfoWrapper: IsDTSHD : {0}", _isDTSHD); //if (_isOGG) // logger.Debug("MediaInfoWrapper: IsOGG : {0}", _isOGG); //if (_isAAC) // logger.Debug("MediaInfoWrapper: IsAAC : {0}", _isAAC); //if (_isWMA) // logger.Debug("MediaInfoWrapper: IsWMA: {0}", _isWMA); //if (_isPCM) // logger.Debug("MediaInfoWrapper: IsPCM: {0}", _isPCM); } catch (Exception ex) { logger.Error("MediaInfo processing failed ('MediaInfo.dll' may be missing): {0}", ex.Message); } finally { if (_mI != null) { _mI.Close(); } } }
public MediaInfoWrapper(string strFile) { new Thread(() => { Thread.CurrentThread.IsBackground = true; Thread.CurrentThread.Name = "MediaInfoWrapper"; if (!MediaInfoExist()) { _mediaInfoNotloaded = true; return; } using (Settings xmlreader = new MPSettings()) { _DVDenabled = xmlreader.GetValueAsBool("dvdplayer", "mediainfoused", false); _BDenabled = xmlreader.GetValueAsBool("bdplayer", "mediainfoused", false); _ParseSpeed = xmlreader.GetValueAsString("debug", "MediaInfoParsespeed", "0.3"); // fix delay introduced after 0.7.26: http://sourceforge.net/tracker/?func=detail&aid=3013548&group_id=86862&atid=581181 } bool isTV = Util.Utils.IsLiveTv(strFile); bool isRadio = Util.Utils.IsLiveRadio(strFile); bool isRTSP = Util.Utils.IsRTSP(strFile); //rtsp for live TV and recordings. bool isDVD = Util.Utils.IsDVD(strFile); bool isVideo = Util.Utils.IsVideo(strFile); bool isAVStream = Util.Utils.IsAVStream(strFile); //other AV streams //currently disabled for all tv/radio/streaming video if (isTV || isRadio || isRTSP || isAVStream) { Log.Debug("MediaInfoWrapper: isTv:{0}, isRadio:{1}, isRTSP:{2}, isAVStream:{3}", isTV, isRadio, isRTSP, isAVStream); Log.Debug("MediaInfoWrapper: disabled for this content"); _mediaInfoNotloaded = true; return; } if (strFile.ToLowerInvariant().EndsWith(".wtv")) { Log.Debug("MediaInfoWrapper: WTV file is not handled"); _mediaInfoNotloaded = true; return; } // Check if video file is from image file string vDrive = DaemonTools.GetVirtualDrive(); string bDrive = Path.GetPathRoot(strFile); if (vDrive == Util.Utils.RemoveTrailingSlash(bDrive)) { isDVD = false; } //currently mediainfo is only used for local video related material (if enabled) if ((!isVideo && !isDVD) || (isDVD && !_DVDenabled) || (isDVD && _BDenabled)) { Log.Debug("MediaInfoWrapper: isVideo:{0}, isDVD:{1}[enabled:{2}]", isVideo, isDVD, _DVDenabled); Log.Debug("MediaInfoWrapper: disabled for this content"); _mediaInfoNotloaded = true; return; } try { _mI = new MediaInfo(); _mI.Option("ParseSpeed", _ParseSpeed); if (Util.VirtualDirectory.IsImageFile(System.IO.Path.GetExtension(strFile))) { strFile = Util.DaemonTools.GetVirtualDrive() + @"\VIDEO_TS\VIDEO_TS.IFO"; if (!File.Exists(strFile)) { strFile = Util.DaemonTools.GetVirtualDrive() + @"\BDMV\index.bdmv"; if (!File.Exists(strFile)) { _mediaInfoNotloaded = true; return; } } } if (strFile.ToLowerInvariant().EndsWith(".ifo")) { string path = Path.GetDirectoryName(strFile); string mainTitle = GetLargestFileInDirectory(path, "VTS_*1.VOB"); string titleSearch = Path.GetFileName(mainTitle); titleSearch = titleSearch.Substring(0, titleSearch.LastIndexOf('_')) + "*.VOB"; string[] vobs = Directory.GetFiles(path, titleSearch, SearchOption.TopDirectoryOnly); foreach (string vob in vobs) { int vobDuration = 0; _mI.Open(vob); int.TryParse(_mI.Get(StreamKind.General, 0, "Duration"), out vobDuration); _mI.Close(); _videoDuration += vobDuration; } // get all other info from main title's 1st vob strFile = mainTitle; } else if (strFile.ToLowerInvariant().EndsWith(".bdmv")) { string path = Path.GetDirectoryName(strFile) + @"\STREAM"; strFile = GetLargestFileInDirectory(path, "*.m2ts"); } if (strFile != null) { Log.Debug("MediaInfoWrapper.MediaInfoWrapper: Opening file : {0}", strFile); _mI.Open(strFile); } else { _mediaInfoNotloaded = true; return; } NumberFormatInfo providerNumber = new NumberFormatInfo(); providerNumber.NumberDecimalSeparator = "."; //Video double.TryParse(_mI.Get(StreamKind.Video, 0, "FrameRate"), NumberStyles.AllowDecimalPoint, providerNumber, out _framerate); int.TryParse(_mI.Get(StreamKind.Video, 0, "Width"), out _width); int.TryParse(_mI.Get(StreamKind.Video, 0, "Height"), out _height); _aspectRatio = _mI.Get(StreamKind.Video, 0, "DisplayAspectRatio"); if ((_aspectRatio == "4:3") || (_aspectRatio == "1.333")) { _aspectRatio = "fullscreen"; } else { _aspectRatio = "widescreen"; } _videoCodec = GetFullCodecName(StreamKind.Video); _scanType = _mI.Get(StreamKind.Video, 0, "ScanType").ToLowerInvariant(); _isInterlaced = _scanType.Contains("interlaced"); if (_width >= 3840 || _height >= 2160) { _videoResolution = "UHD"; } else if (_width >= 1280 || _height >= 720) { _videoResolution = "HD"; } else { _videoResolution = "SD"; } if (_videoResolution == "UHD") { if ((_width >= 7680 || _height >= 4320) && !_isInterlaced) { _videoResolution = "4320P"; } else if ((_width >= 3840 || _height >= 2160) && !_isInterlaced) { _videoResolution = "2160P"; } } else if (_videoResolution == "HD") { if ((_width >= 2560 || _height >= 1440) && !_isInterlaced) { _videoResolution = "1440P"; } else if ((_width >= 1920 || _height >= 1080) && _isInterlaced) { _videoResolution = "1080I"; } else if ((_width >= 1920 || _height >= 1080) && !_isInterlaced) { _videoResolution = "1080P"; } else if ((_width >= 1280 || _height >= 720) && _isInterlaced) { _videoResolution = "720I"; } else if ((_width >= 1280 || _height >= 720) && !_isInterlaced) { _videoResolution = "720P"; } } else { if (_height >= 576) { _videoResolution = "576"; } else if (_height >= 480) { _videoResolution = "480"; } else if (_height >= 360) { _videoResolution = "360"; } else if (_height >= 240) { _videoResolution = "240"; } } if (_videoDuration == 0) { int.TryParse(_mI.Get(StreamKind.Video, 0, "Duration"), out _videoDuration); } //Audio int iAudioStreams = _mI.Count_Get(StreamKind.Audio); for (int i = 0; i < iAudioStreams; i++) { int intValue; string sChannels = _mI.Get(StreamKind.Audio, i, "Channel(s)").Split(new char[] { '/' })[0].Trim(); if (int.TryParse(sChannels, out intValue) && intValue > _audioChannels) { int.TryParse(_mI.Get(StreamKind.Audio, i, "SamplingRate"), out _audioRate); _audioChannels = intValue; _audioCodec = GetFullCodecName(StreamKind.Audio, i); } } switch (_audioChannels) { case 8: _audioChannelsFriendly = "7.1"; break; case 7: _audioChannelsFriendly = "6.1"; break; case 6: _audioChannelsFriendly = "5.1"; break; case 2: _audioChannelsFriendly = "stereo"; break; case 1: _audioChannelsFriendly = "mono"; break; default: _audioChannelsFriendly = _audioChannels.ToString(); break; } //Detection _hasAudio = _mI.Count_Get(StreamKind.Audio) > 0; _hasVideo = _mI.Count_Get(StreamKind.Video) > 0; //Subtitles _numsubtitles = _mI.Count_Get(StreamKind.Text); if (checkHasExternalSubtitles(strFile)) { _hasSubtitles = true; } else { _hasSubtitles = _numsubtitles > 0; } var sct = _mI.Count_Get(StreamKind.Text); for (var i = 0; i < sct; ++i) { var format = _mI.Get(StreamKind.Text, i, "Format").ToLowerInvariant(); _subtitleFormatsDetected.Add(format.ToLowerInvariant()); } Log.Debug("MediaInfoWrapper.MediaInfoWrapper: DLL Version : {0}", _mI.Option("Info_Version")); Log.Info("MediaInfoWrapper.MediaInfoWrapper: Inspecting media : {0}", strFile); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: Parse speed : {0}", _ParseSpeed); //Video Log.Debug("MediaInfoWrapper.MediaInfoWrapper: FrameRate : {0}", _framerate); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: Width : {0}", _width); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: Height : {0}", _height); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: AspectRatio : {0}", _aspectRatio); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: VideoCodec : {0} [ \"{1}.png\" ]", _videoCodec, Util.Utils.MakeFileName(_videoCodec).ToLowerInvariant()); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: Scan type : {0}", _scanType); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: IsInterlaced : {0}", _isInterlaced); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: VideoResolution : {0}", _videoResolution); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: VideoDuration : {0}", _videoDuration); //Audio Log.Debug("MediaInfoWrapper.MediaInfoWrapper: AudioRate : {0}", _audioRate); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: AudioChannels : {0} [ \"{1}.png\" ]", _audioChannels, _audioChannelsFriendly); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: AudioCodec : {0} [ \"{1}.png\" ]", _audioCodec, Util.Utils.MakeFileName(_audioCodec).ToLowerInvariant()); //Detection Log.Debug("MediaInfoWrapper.MediaInfoWrapper: HasAudio : {0}", _hasAudio); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: HasVideo : {0}", _hasVideo); //Subtitles Log.Debug("MediaInfoWrapper.MediaInfoWrapper: HasSubtitles : {0}", _hasSubtitles); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: NumSubtitles : {0}", _numsubtitles); } catch (Exception) { Log.Error( "MediaInfoWrapper.MediaInfoWrapper: Error occurred while scanning media: '{0}'", strFile); } finally { if (_mI != null) { _mI.Close(); Log.Debug("MediaInfoWrapper.MediaInfoWrapper: Closing file : {0}", strFile); finished.Set(); } } }).Start(); }
/// <summary> /// Set new refresh rate for BDs /// </summary> private void SetRefreshRateBD() { if (!_changeRefreshRate) { return; } Log.Info("Blu-Ray Player Launcher: SetRefreshRate for BluRay."); if (_driveLetter == null) { Log.Error("Blu-Ray Player Launcher: SetRefreshRate for BluRay - drive letter not assigned!"); return; } double fps = -1; try { FileInfo[] files = null; double maxFileSize = 0; string maxFileName = ""; DirectoryInfo dir = new DirectoryInfo(_driveLetter + "\\BDMV\\STREAM"); files = dir.GetFiles("*.M2TS"); foreach (FileInfo file in files) { if (file.Length > maxFileSize) { maxFileSize = file.Length; maxFileName = file.Name; } } MediaInfo MI = new MediaInfo(); MI.Open(_driveLetter + "\\BDMV\\STREAM\\" + maxFileName); string _BD_Framerate = MI.Get(StreamKind.Video, 0, "FrameRate"); Log.Info("Blu-Ray Player Launcher: BD Framerate via Mediainfo: - {0}", _BD_Framerate); switch (_BD_Framerate) { case "23.976": fps = 23.976; break; case "24": fps = 24; break; case "24.000": fps = 24; break; case "25": fps = 25; break; case "25.000": fps = 25; break; case "29.970": fps = 29.97; break; case "50": fps = 50; break; case "50.000": fps = 50; break; case "59.94": fps = 59.94; break; } } catch (Exception e) { Log.Error("Blu-Ray Player Launcher: SetRefreshRate - failed to get refresh rate from disk!"); Log.Error("Blu-Ray Player Launcher: SetRefreshRate - exception {0}", e); return; } if (fps != -1) { try { Log.Info("Blu-Ray Player Launcher: calling SetRefreshRateBasedOnFPS() - {0}Hz", fps); RefreshRateChanger.SetRefreshRateBasedOnFPS(fps, "", RefreshRateChanger.MediaType.Video); _refreshRateChangeSuccessful = true; } catch (Exception e) { Log.Error("Blu-Ray Player Launcher: SetRefreshRate - exception {0}", e); } } else { Log.Error("Blu-Ray Player Launcher: Invalid Refresh Rate: {0} fps", fps); _refreshRateChangeSuccessful = false; } }
/// <summary> /// Set new refresh rate for HDDVDs /// </summary> private void SetRefreshRateHD() { if (!_changeRefreshRate) { return; } Log.Info("Blu-Ray Player Launcher: SetRefreshRate for HD-DVD"); if (_driveLetter == null) { Log.Error("Blu-Ray Player Launcher: SetRefreshRate for HD-DVD - drive letter not assigned!"); return; } double fps = -1; try { FileInfo[] files = null; double maxFileSize = 0; string maxFileName = ""; DirectoryInfo dir = new DirectoryInfo(_driveLetter + "\\HVDVD_TS"); files = dir.GetFiles("*.EVO"); foreach (FileInfo file in files) { Log.Info("Blu-Ray Player Launcher: Files: - {0} with {1} Bytes", file.Name, file.Length); if (file.Length > maxFileSize) { maxFileSize = file.Length; maxFileName = file.Name; } } Log.Info("Blu-Ray Player Launcher: Biggest file: - {0} with {1} bytes", maxFileName, maxFileSize); MediaInfo MI = new MediaInfo(); MI.Open(_driveLetter + "\\HVDVD_TS\\" + maxFileName); string _HDDVD_Framerate = MI.Get(StreamKind.Video, 0, "FrameRate"); Log.Info("Blu-Ray Player Launcher: HD-DVD Framerate via Mediainfo: - {0}", _HDDVD_Framerate); switch (_HDDVD_Framerate) { case "23.976": fps = 23.976; break; case "24": fps = 24; break; case "25": fps = 25; break; case "29.970": // HD-DVDs are sometimes reported as 29.97hz even if they are 24hz. fps = 23.976; // probably due hd-dvds need are in 29.97hz format with interlaced and telecine flags (repeat_first_field, top_field_first and progressive_frame for MPEG-2). break; // dirty workaround: set refresh rate to 23.976hz, possibly makes real 29.97hz discs (if available) stutter case "50": fps = 50; break; case "59.94": fps = 59.94; break; } } catch (Exception e) { Log.Error("Blu-Ray Player Launcher: SetRefreshRate - failed to get refresh rate from disk!"); Log.Error("Blu-Ray Player Launcher: SetRefreshRate - exception {0}", e); return; } if (fps != -1) { try { Log.Info("Blu-Ray Player Launcher: calling SetRefreshRateBasedOnFPS() - {0}Hz", fps); RefreshRateChanger.SetRefreshRateBasedOnFPS(fps, "", RefreshRateChanger.MediaType.Video); _refreshRateChangeSuccessful = true; } catch (Exception e) { Log.Error("Blu-Ray Player Launcher: SetRefreshRate - exception {0}", e); } } else { Log.Error("Blu-Ray Player Launcher: Invalid Refresh Rate: {0} fps", fps); _refreshRateChangeSuccessful = false; } }
/// <summary> /// Handles the g_Player.PlayBackStarted event /// </summary> public void OnVideoStarted(g_Player.MediaType type, string s) { // do not handle e.g. visualization window, last.fm player, etc if (type == g_Player.MediaType.Video || type == g_Player.MediaType.TV) { _currentName = s; String baseName = Path.Combine(Path.GetDirectoryName(s), Path.GetFileNameWithoutExtension(s)); // text based subtitles String [] textSubtitleFormatsFileAndEmbedded = { "aqt", "srt", "ssa", "mpl", "txt", "dks", "js", "jss", "pjs", "asc", "ass", "smi", "psb", "lrc", "ovr", "rt", "rtf", "zeg", "sbt", "sst", "ssts", "stl", "vkt", "vsf", "pan", "s2k" }; String [] imageSubtitleFormatsFile = { "idx", "sub", "scr", "son" }; String[] imageSubtitleFormatsEmbedded = { "vobsub", "dvb subtitle", "pgs", "rle", "xsub", }; subTitleType = eSubTitle.None; // check for file based subtitles foreach (String subFormat in textSubtitleFormatsFileAndEmbedded) { if (File.Exists(baseName + "." + subFormat)) { subTitleType = eSubTitle.TextBased; ThreadPool.QueueUserWorkItem(new WaitCallback(RunVideoStarted), type); return; } } foreach (String subFormat in imageSubtitleFormatsFile) { if (File.Exists(baseName + "." + subFormat)) { subTitleType = eSubTitle.ImageBased; ThreadPool.QueueUserWorkItem(new WaitCallback(RunVideoStarted), type); return; } } // check for embedded subtitles MediaInfo mi = new MediaInfo(); mi.Open(s); int sct = mi.Count_Get(StreamKind.Text); for (int i = 0; i < sct; i++) { String format = mi.Get(StreamKind.Text, i, "Format").ToLowerInvariant(); if (textSubtitleFormatsFileAndEmbedded.Contains(format)) { subTitleType = eSubTitle.TextBased; break; } if (imageSubtitleFormatsEmbedded.Contains(format)) { subTitleType = eSubTitle.ImageBased; break; } } mi.Close(); ThreadPool.QueueUserWorkItem(new WaitCallback(RunVideoStarted), type); } }