2

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?

Jason Berkan
  • 8,734
  • 7
  • 29
  • 39
Harun
  • 5,109
  • 4
  • 38
  • 60
  • This answer to a slightly different question I asked would probably work for you: http://stackoverflow.com/questions/3936816/querying-an-audio-video-file-for-information/3938722#3938722 – TRiG Oct 18 '10 at 14:35
  • And MP4 files can contain a variety of codecs. Could be H.264 (quite likely), or could well be something else. – TRiG Oct 18 '10 at 14:36
  • Hi, While searching to find why my code doesn't work for mp4, i found the following statement: "It doesn't matter whether it's in a container or not, it only matters whether you have a parser/reader for it. There is no stock DirectShow parser to read raw H.264 files and no third-party one I can think of. Also, whether IMediaSeeking would work with such a raw file is implementation-dependent. Last, most H.264-related filters use MPEG2Video or VideoInfo2 and neither works with MediaDet, so you would have to build the graph yourself." can u help me? – Harun Oct 22 '10 at 05:30

1 Answers1

1

I'd simply use MediaInfo. There is a CLI for it as well so you can call it from your code and get this info. It pretty much handles all kinds of codecs and containers.

Shiv Kumar
  • 9,599
  • 2
  • 36
  • 38