这将帮助您获得您想要的内容,即“Windows资源管理器中显示的比特率”,但不是来自QT元数据。如果由于某些原因不合适,也许它可以作为备用方案,直到您能够找到基于Atom的答案或用作与QT Atom结果进行比较的内容。
简而言之,如果您想获取资源管理器显示的内容,请从资源管理器获取。
using Shell32;
class ShellInfo
{
const int PerceivedType = 9;
static int[] info = {0, 9, 11, 27, 28};
public static Dictionary<string, string> GetMediaProperties(string file)
{
Dictionary<string, string> xtd = new Dictionary<string, string>();
Shell32.Shell shell = new Shell32.Shell();
Shell32.Folder folder;
folder = shell.NameSpace(Path.GetDirectoryName(file));
foreach (var s in folder.Items())
{
if (folder.GetDetailsOf(s, 0).ToLowerInvariant() ==
Path.GetFileName(file).ToLowerInvariant())
{
if (folder.GetDetailsOf(s, PerceivedType).ToLowerInvariant() ==
"video")
{
foreach (int n in info)
{
xtd.Add(folder.GetDetailsOf(folder.Items(), n),
folder.GetDetailsOf(s, n));
}
}
break;
}
}
return xtd;
}
}
使用方法:
Dictionary<string, string> myinfo
myinfo = ShellInfo.GetMediaProperties(filepath)
测试文件是来自苹果网站的QT mov示例,因此没有什么特别之处。在资源管理器中查看:
GetMediaProperties
的结果:
返回结果:
返回的比特率也与MediaProps
和MediaTab
返回的音频比特率匹配(两者都使用MediaInfo.DLL
来收集所有媒体属性值)。
前35个Shell扩展属性已经有很好的文档说明。我认为从Windows 7开始,这个数字增加到了291个(!)。其中许多是针对特定文件类型的,例如照片、电子邮件等。以下是一些可能会引起兴趣的属性:
282:数据速率
283:帧高度
284:帧速率
285:帧宽度
286:总比特率
数据速率(282)是视频比特率(与MediaInfo相匹配);总比特率(286)是音频和视频比特率的组合。
Windows 8(更新)
尽管上述代码似乎在Windows 7上运行良好,但对于运行Windows 8的计算机,在以下行上避免System.InvalidCastException
:
Shell shell = new Shell();
以下代码需要运行以实例化
Shell
和
Folder
COM对象:
Type shellType = Type.GetTypeFromProgID("Shell.Application");
Object shell = Activator.CreateInstance(shellType);
Folder folder = (Folder)shellType.InvokeMember("NameSpace",
BindingFlags.InvokeMethod, null, shell,
new object[] { Path.GetDirectoryName(file) });
在Visual Studio论坛的在Windows 8中实例化Shell32.Shell对象的解决方案问题中找到了答案。
此外,在Windows 8上,似乎添加了更多属性,因此最大索引现在为309(带有一些空条目),上述提到的属性具有不同的索引:
298:数据速率
299:帧高度
300:帧速率
301:帧宽度
303:总比特率
似乎Shell32返回的结果中有一些字符阻止了直接将其转换为整数值。对于比特率:
string bRate = myinfo["Bit rate"]; // get return val
bRate = new string(bRate.Where(char.IsDigit).ToArray()); // tidy up
int bitRate = Convert.ToInt32(bRate);