views:

33

answers:

0

I've tried using directshowlib-2005 by installing k-lite mega codec pack. It can't find the duration of an mp4 file or f4v file (avi, wmv and flv has no problem). I use ImediaSeeking interface of directshowlib-2005 to find duration. But in case of mp4 and f4v the GetDuration method returns zero.

I know it is a codec problem, but I do not know which codec is to be installed to get duration of mp4 as well as f4v files.

The code I am using is shown below:

static public bool GetVideoLength(string fileName, out long length)
    {
        DirectShowLib.FilterGraph graphFilter = new DirectShowLib.FilterGraph();
        DirectShowLib.IGraphBuilder graphBuilder;
        //DirectShowLib.IMediaPosition mediaPos=null;
        DirectShowLib.IMediaSeeking mediaPos;
        length = 4294967296;

        try
        {
            graphBuilder = (DirectShowLib.IGraphBuilder)graphFilter;
            graphBuilder.RenderFile(fileName, null);
            //mediaPos = (DirectShowLib.IMediaPosition)graphBuilder;
            mediaPos = (DirectShowLib.IMediaSeeking)graphBuilder;                
           // mediaPos.get_Duration(out length);
            mediaPos.GetDuration(out length);

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {               
            mediaPos = null;
            graphBuilder = null;
            graphFilter = null;               

        }
    }

Can anyone please help me by telling me the exact codec which should be installed to find the duration as mentioned above?