/// <summary> /// 获取视频信息 (wmv 10ms,其他 100ms) /// </summary> /// <param name="VideoName"></param> /// <returns></returns> public static VedioInfo GetMediaInfo(string vediopath) { VedioInfo vedioInfo = new VedioInfo(); if (File.Exists(vediopath)) { MediaInfo MI = new MediaInfo(); MI.Open(vediopath); //全局 string format = MI.Get(StreamKind.General, 0, "Format"); string bitrate = MI.Get(StreamKind.General, 0, "BitRate/String"); string duration = MI.Get(StreamKind.General, 0, "Duration/String1"); string fileSize = MI.Get(StreamKind.General, 0, "FileSize/String"); //视频 string vid = MI.Get(StreamKind.Video, 0, "ID"); string video = MI.Get(StreamKind.Video, 0, "Format"); string vBitRate = MI.Get(StreamKind.Video, 0, "BitRate/String"); string vSize = MI.Get(StreamKind.Video, 0, "StreamSize/String"); string width = MI.Get(StreamKind.Video, 0, "Width"); string height = MI.Get(StreamKind.Video, 0, "Height"); string risplayAspectRatio = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio/String"); string risplayAspectRatio2 = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio"); string frameRate = MI.Get(StreamKind.Video, 0, "FrameRate/String"); string bitDepth = MI.Get(StreamKind.Video, 0, "BitDepth/String"); string pixelAspectRatio = MI.Get(StreamKind.Video, 0, "PixelAspectRatio"); string encodedLibrary = MI.Get(StreamKind.Video, 0, "Encoded_Library"); string encodeTime = MI.Get(StreamKind.Video, 0, "Encoded_Date"); string codecProfile = MI.Get(StreamKind.Video, 0, "Codec_Profile"); string frameCount = MI.Get(StreamKind.Video, 0, "FrameCount"); //音频 string aid = MI.Get(StreamKind.Audio, 0, "ID"); string audio = MI.Get(StreamKind.Audio, 0, "Format"); string aBitRate = MI.Get(StreamKind.Audio, 0, "BitRate/String"); string samplingRate = MI.Get(StreamKind.Audio, 0, "SamplingRate/String"); string channel = MI.Get(StreamKind.Audio, 0, "Channel(s)"); string aSize = MI.Get(StreamKind.Audio, 0, "StreamSize/String"); string audioInfo = MI.Get(StreamKind.Audio, 0, "Inform") + MI.Get(StreamKind.Audio, 1, "Inform") + MI.Get(StreamKind.Audio, 2, "Inform") + MI.Get(StreamKind.Audio, 3, "Inform"); string videoInfo = MI.Get(StreamKind.Video, 0, "Inform"); MI.Close(); vedioInfo = new VedioInfo() { Format = format, BitRate = vBitRate, Duration = duration.Replace("h", "小时").Replace("mn", "分钟").Replace("ms", "毫秒").Replace("s", "秒"), FileSize = fileSize, Width = width, Height = height, DisplayAspectRatio = risplayAspectRatio, FrameRate = frameRate, BitDepth = bitDepth, PixelAspectRatio = pixelAspectRatio, Encoded_Library = encodedLibrary, FrameCount = frameCount, AudioFormat = audio, AudioBitRate = aBitRate, AudioSamplingRate = samplingRate, Channel = channel }; } if (!string.IsNullOrEmpty(vedioInfo.Width) && !string.IsNullOrEmpty(vedioInfo.Height)) { vedioInfo.Resolution = vedioInfo.Width + "x" + vedioInfo.Height; } vedioInfo.Extension = Path.GetExtension(vediopath).ToUpper().Replace(".", ""); vedioInfo.FileName = Path.GetFileNameWithoutExtension(vediopath); return(vedioInfo); }
public static string MediaInfo(string VideoName) { string info = "无视频信息"; if (File.Exists(VideoName)) { MediaInfo MI = new MediaInfo(); MI.Open(VideoName); //全局 string container = MI.Get(StreamKind.General, 0, "Format"); string bitrate = MI.Get(StreamKind.General, 0, "BitRate/String"); string duration = MI.Get(StreamKind.General, 0, "Duration/String1"); string fileSize = MI.Get(StreamKind.General, 0, "FileSize/String"); //视频 string vid = MI.Get(StreamKind.Video, 0, "ID"); string video = MI.Get(StreamKind.Video, 0, "Format"); string vBitRate = MI.Get(StreamKind.Video, 0, "BitRate/String"); string vSize = MI.Get(StreamKind.Video, 0, "StreamSize/String"); string width = MI.Get(StreamKind.Video, 0, "Width"); string height = MI.Get(StreamKind.Video, 0, "Height"); string risplayAspectRatio = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio/String"); string risplayAspectRatio2 = MI.Get(StreamKind.Video, 0, "DisplayAspectRatio"); string frameRate = MI.Get(StreamKind.Video, 0, "FrameRate/String"); string bitDepth = MI.Get(StreamKind.Video, 0, "BitDepth/String"); string pixelAspectRatio = MI.Get(StreamKind.Video, 0, "PixelAspectRatio"); string encodedLibrary = MI.Get(StreamKind.Video, 0, "Encoded_Library"); string encodeTime = MI.Get(StreamKind.Video, 0, "Encoded_Date"); string codecProfile = MI.Get(StreamKind.Video, 0, "Codec_Profile"); string frameCount = MI.Get(StreamKind.Video, 0, "FrameCount"); //音频 string aid = MI.Get(StreamKind.Audio, 0, "ID"); string audio = MI.Get(StreamKind.Audio, 0, "Format"); string aBitRate = MI.Get(StreamKind.Audio, 0, "BitRate/String"); string samplingRate = MI.Get(StreamKind.Audio, 0, "SamplingRate/String"); string channel = MI.Get(StreamKind.Audio, 0, "Channel(s)"); string aSize = MI.Get(StreamKind.Audio, 0, "StreamSize/String"); string audioInfo = MI.Get(StreamKind.Audio, 0, "Inform") + MI.Get(StreamKind.Audio, 1, "Inform") + MI.Get(StreamKind.Audio, 2, "Inform") + MI.Get(StreamKind.Audio, 3, "Inform"); string videoInfo = MI.Get(StreamKind.Video, 0, "Inform"); info = System.IO.Path.GetFileName(VideoName) + "\r\n" + "容器:" + container + "\r\n" + "总码率:" + bitrate + "\r\n" + "大小:" + fileSize + "\r\n" + "时长:" + duration + "\r\n" + "\r\n" + "视频(" + vid + "):" + video + "\r\n" + "码率:" + vBitRate + "\r\n" + "大小:" + vSize + "\r\n" + "分辨率:" + width + "x" + height + "\r\n" + "宽高比:" + risplayAspectRatio + "(" + risplayAspectRatio2 + ")" + "\r\n" + "帧率:" + frameRate + "\r\n" + "位深度:" + bitDepth + "\r\n" + "像素宽高比:" + pixelAspectRatio + "\r\n" + "编码库:" + encodedLibrary + "\r\n" + "Profile:" + codecProfile + "\r\n" + "编码时间:" + encodeTime + "\r\n" + "总帧数:" + frameCount + "\r\n" + "\r\n" + "音频(" + aid + "):" + audio + "\r\n" + "大小:" + aSize + "\r\n" + "码率:" + aBitRate + "\r\n" + "采样率:" + samplingRate + "\r\n" + "声道数:" + channel + "\r\n" + "\r\n====详细信息====\r\n" + videoInfo + "\r\n" + audioInfo + "\r\n" ; MI.Close(); } return(info); }