简体   繁体   English

在Windows Server 2008中查找电影数据速率

[英]Find out movie data rate in Windows Server 2008

I am trying to find out the data rate for a movie file (mp4 or wmv) in Windows Server 2008. I have tried using the Windows API Code Pack and also the Shell32 COM objects in C#. 我试图找出Windows Server 2008中的电影文件(mp4或wmv)的数据速率。我尝试使用Windows API代码包以及C#中的Shell32 COM对象。 This worked perfectly in Windows 7, but it does not give me back any information in Windows Server 2008. 这在Windows 7中完美运行,但它不会在Windows Server 2008中提供任何信息。

In Windows 7 Explorer, I can add a column to the details list of items in a folder to see file properties such as Data Rate, Bit Rate, and Duration. 在Windows 7资源管理器中,我可以在文件夹中的项目的详细信息列表中添加一列,以查看文件属性,如数据速率,比特率和持续时间。 When attempting to do this in Windows Server 2008, nothing shows up in these columns. 尝试在Windows Server 2008中执行此操作时,这些列中不会显示任何内容。 If I run my program using the Windows API Code Pack to find out the data rate of files on a Windows 7 machine and point it to analyze the files on a Windows Server 2008 machine over the network, then I can get the data rate property, but it takes a lot longer to find out these properties over the network than when doing it locally. 如果我使用Windows API代码包运行我的程序来查找Windows 7计算机上文件的数据速率并指向它通过网络分析Windows Server 2008计算机上的文件,那么我可以获得数据速率属性,但是通过网络查找这些属性需要花费更长的时间,而不是在本地进行。

Please let me know if there is a way to find out the data rate using C# in Windows Server 2008! 如果有办法在Windows Server 2008中使用C#查找数据速率,请告诉我们! Thanks! 谢谢!

You could try with ffmpeg's library. 您可以尝试使用ffmpeg的库。 You have some C# wrappers available for it. 你有一些C#包装器可用。 Check out this SO post . 看看这篇SO帖子

MediaInfo 媒体信息

1: Create a C# project 1:创建一个C#项目

2: Include into the project this (click me) file 2:在项目中包含此(单击我)文件

3: Create a nice wrapper class to extract the values: 3:创建一个很好的包装类来提取值:

here is one for you; 这是给你的;

public class MediaQuery
{
    public Dictionary<string, string> QueryFile(string filePath)
    {
        MediaInfo mediaInfo = new MediaInfo();
        string version = mediaInfo.Option("Info_Version");
        if (!File.Exists(filePath))
            throw new Exception("File Not Found");
        try
        {
            mediaInfo.Option("Inform", "XML");
            mediaInfo.Option("Complete", "1");
            mediaInfo.Open(filePath);

            string xml = mediaInfo.Inform();
            IEnumerable<XElement> el = XElement.Parse(xml, LoadOptions.None).Elements();
            XElement general = el.FirstOrDefault(e => e.Attribute("type").Value == "General");
            XElement video = el.FirstOrDefault(e => e.Attribute("type").Value == "Video");
            XElement audio = el.FirstOrDefault(e => e.Attribute("type").Value == "Audio");
            Dictionary<string, string> values = new Dictionary<string, string>();
            values = GetValues(general, "General");
            values = GetValues(video, "Video", values);
            values = GetValues(audio, "Audio", values);
            return values;
        }
        catch (Exception ex)
        {
            throw new Exception("Problem Querying File", ex);
        }
    }

    private Dictionary<string, string> GetValues(XElement xElement, string rootType)
    {
        Dictionary<string, string> values = new Dictionary<string, string>();
        return GetValues(xElement, rootType, values);
    }
    private Dictionary<string, string> GetValues(XElement xElement, string rootType, Dictionary<string, string> values)
    {
        foreach (XElement element in xElement.Elements())
        {
            string key = rootType + "/" + element.Name.ToString();
            if (!values.ContainsKey(key))
                values.Add(key, element.Value.ToString());
            else
            {
                int count = 1;
                key = rootType + "/" + element.Name.ToString() + count.ToString();
                while (values.ContainsKey(key))
                {
                    count++;
                    key = rootType + "/" + element.Name.ToString() + count.ToString();
                }
                values.Add(key, element.Value.ToString());
            }
        }
        return values;
    }
}

Stick that file in the same project. 将该文件粘贴在同一个项目中。

4: Download Current version of MediaInfo: Download Page .Pick the verison that best suits you ( DLL only ). 4:下载当前版本的MediaInfo: 下载页面。选择最适合您的版本(仅限DLL)。 Make sure the .dll is in the executing directory of the application. 确保.dll位于应用程序的执行目录中。

5: Usage: 5:用法:

MediaQuery query = new MediaQuery();
Dictionary<string, string> results = query.QueryFile(@"C:\text.mov");
string videoBitRate;

if (results.TryGetValue("Video/Bit_rate", out videoBitRate) == false)
{ 
   throw new Exception("Video bit rate not found"); 
}
else
{
   // Do whatever you want with this....
   Console.writeline("Video bitrate:" + videoBitRate);
}

it's a quite a simple answer: Windows server 2008 has no mpeg-4 multiplexer, so you cant get any mp4 info on your machine with default configuration of your server. 这是一个非常简单的答案:Windows Server 2008没有mpeg-4多路复用器,因此您无法在服务器上使用服务器的默认配置获取任何mp4信息。

-in your computer you can notice that if you stand with your mouse cursor on a video file you will able to see basic file info like duration... - 在您的计算机中,您可以注意到,如果您将鼠标光标放在视频文件上,您将能够看到基本文件信息,例如持续时间......

-at your server you might find out that if you do the same on an mp4 media file you will not able to see this information...(duration and dimensions) - 你的服务器上你可能会发现,如果你在mp4媒体文件上做同样的事情,你将无法看到这些信息......(持续时间和尺寸)

the answer for that issue is to go to server manager under the administrative tools in your windows server 2008 r2 from the start menu. 该问题的答案是从开始菜单中转到Windows Server 2008 r2中管理工具下的服务器管理器。

from there you need to choose features in the left side. 从那里你需要选择左侧的功能。 after that you need to prees add features and select DESKTOP EXPERIENCE and install. 之后,您需要预先添加功能并选择DESKTOP EXPERIENCE并安装。

this is the primary thing you need do do for you machine to be able to read mp4 info. 这是你需要做的主要事情,你的机器能够读取mp4信息。 after that you need to mime type for your mp4 media files. 之后你需要为mp4媒体文件设置mime类型。 install codecs. 安装编解码器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM