1

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#. This worked perfectly in Windows 7, but it does not give me back any information in 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. When attempting to do this in Windows Server 2008, nothing shows up in these columns. 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.

Please let me know if there is a way to find out the data rate using C# in Windows Server 2008! Thanks!

Misha
  • 571
  • 5
  • 17

3 Answers3

2

You could try with ffmpeg's library. You have some C# wrappers available for it. Check out this SO post.

Community
  • 1
  • 1
LavaScornedOven
  • 737
  • 1
  • 11
  • 23
  • Thank you very much, I tried this and it worked for the most part, but got some incorrect bit rate values for some of the movie files.. – Misha Oct 03 '12 at 04:58
  • You can always report a bug at ffmpeg.org, but who knows if and when it will be fixed. Well... At least you can try. :) – LavaScornedOven Oct 03 '12 at 08:07
  • I think it could possibly be a problem with the wrapper, because all the wrapper does is 'ffmpeg -i ', and then parses the output to find the bitrate.. on a list of 500 files, where 250 of them are 1632kb/s and the other 250 are 850kb/s, the wrapper is reporting that over 400 are less than 1000kb/s....so I need to debug the output for the 500 files, just need to find some more time to do this :) thanks for the help! – Misha Oct 03 '12 at 15:55
  • Sure, glad to be of help. If you agree, it would be great if you could accept my answer and share some of the goodness. (I'm collecting points for bounties of my own.) – LavaScornedOven Oct 03 '12 at 19:40
  • FFMpeg was actually giving me inaccurate results..when using the MediaInfo solution, I received the correct bit rate results, but it took forever to get these values.. – Misha Oct 04 '12 at 22:49
2

MediaInfo

1: Create a C# project

2: Include into the project this (click me) file

3: Create a nice wrapper class to extract the values:

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 ). Make sure the .dll is in the executing directory of the application.

5: Usage:

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);
}
user989056
  • 1,275
  • 2
  • 15
  • 33
  • Thank you I will try this tomorrow morning! – Misha Oct 03 '12 at 04:57
  • I have not tried this yet...but it seems like it would work and I appreciate the help! – Misha Oct 03 '12 at 23:40
  • This worked well, gave me accurate results compared to FFMpeg. But this worked very very slowly and would take forever to scan a directory of thousands of files. – Misha Oct 04 '12 at 22:48
  • Yes, I feared it may not be the best solution to your problem given the large quantity of files you have. MediaInfo gathers a lot more data than just the data rate, some of which requires that the file be analysed for a period of time. I have found that MediaInfo creates reliable and accurate results but as you say, it is not fast. – user989056 Oct 05 '12 at 08:06
0

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.

-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)

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.

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.

this is the primary thing you need do do for you machine to be able to read mp4 info. after that you need to mime type for your mp4 media files. install codecs.

Shahar Meshulam
  • 148
  • 1
  • 6