Quantcast
Channel: Technology Portal » Multimedia
Viewing all articles
Browse latest Browse all 2

Find Codec of Media File Programatically

$
0
0

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
 * ashwin.rayaprolu@gmail.com
 * 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";
            MI.Open(args[0]);

            ToDisplay += "\r\n\r\nInform with Complete=false\r\n";
            MI.Option("Complete");
            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";
            MI.Close();

            Console.WriteLine(ToDisplay);
        }
    }
}

You Can checkout Sample C# project from following SVN location

https://linkwithweb.googlecode.com/svn/trunk/Utilities/FindMediaType



Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images