Find Codec of Media File Programatically

Recently while working in some Media related project i had a task of finding which media i’m working on. I mean to find out if my player supports running that media. For that i need to work on a solution which can find a media type by reading file headers etc…

I have been shuffling between GSpot Codec Library / VLC / Mediainfo but i found out that Mediainfo is more Developer Friendly and can be easily Integrated into the application

Here is sample code which read details about media

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using MediaInfoLib;

 * Ashwin Kumar
 * 4/12/2011
 * Sample Command Line program to read and display Media type
 * Usage MediaInfoRead 
 * */
namespace MediaInfoRead
    class MediaInfoRead
        public static void Main(string[] args)
            String ToDisplay = "";
            MediaInfo MI = new MediaInfo();
            //An example of how to use the library
            ToDisplay += "\r\n\r\nOpen\r\n";

            ToDisplay += "\r\n\r\nInform with Complete=false\r\n";
            ToDisplay += MI.Inform();

            ToDisplay += "\r\n\r\nInform with Complete=true\r\n";
            MI.Option("Complete", "1");
            ToDisplay += MI.Inform();

            ToDisplay += "\r\n\r\nCustom Inform\r\n";
            MI.Option("Inform", "General;File size is %FileSize% bytes");
            ToDisplay += MI.Inform();

            ToDisplay += "\r\n\r\nGet with Stream=General and Parameter='FileSize'\r\n";
            ToDisplay += MI.Get(0, 0, "FileSize");

            ToDisplay += "\r\n\r\nGet with Stream=General and Parameter=46\r\n";
            ToDisplay += MI.Get(0, 0, 46);

            ToDisplay += "\r\n\r\nCount_Get with StreamKind=Stream_Audio\r\n";
            ToDisplay += MI.Count_Get(StreamKind.Audio);

            ToDisplay += "\r\n\r\nGet with Stream=General and Parameter='AudioCount'\r\n";
            ToDisplay += MI.Get(StreamKind.General, 0, "AudioCount");

            ToDisplay += "\r\n\r\nGet with Stream=Audio and Parameter='StreamCount'\r\n";
            ToDisplay += MI.Get(StreamKind.Audio, 0, "StreamCount");

            ToDisplay += "\r\n\r\nClose\r\n";


You Can checkout Sample C# project from following SVN location


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s