Click here to Skip to main content
12,817,838 members (37,348 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# Video
I want to get some information of an mp4 file(such as duration,file size,title and so on) , I try to use Shell32 , but it does not support mp4 format , I have found some dlls in the website , but all they are not COM component , then I try to use IBMToolkitForMpeg4SDK.jar , and then meets some problems Exception in thread "main" Unrecognized extension of file:

e:\1.mpeg at I4g.d(Unknown Source) at I4g.a(Unknown Source) at I4i.a(Unknown Source) at I4b.a(Unknown Source) at Source) at AVgenSample.getMp4Duration( at AVgenSample.main(

So I want to get the information of mp4 file , anyone have any methods , please help!Thsnks all!
Posted 17-May-12 17:58pm
Updated 17-May-12 19:04pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1 DirectShowLib,I use the version DirectShowLibV2-1
its website:
and download page:
2.using the lib in c#
3.code using MediaDet class


    using System.Runtime.InteropServices;
    using DirectShowLib;
    using DirectShowLib.DES;


public static string GetDuration(string fileName)
                var mediaDet = (IMediaDet)new MediaDet();
                // find the video stream in the file
                int index;
                var type = Guid.Empty;
                for (index = 0; index < 1000 && type != MediaType.Video; index++)
                    mediaDet.get_StreamType(out type);
                // retrieve some measurements from the video
                double frameRate;
                mediaDet.get_FrameRate(out frameRate);
                var mediaType = new AMMediaType();
                var videoInfo = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.formatPtr, typeof(VideoInfoHeader));
                var width = videoInfo.BmiHeader.Width;
                var height = videoInfo.BmiHeader.Height;
                double mediaLength;
                mediaDet.get_StreamLength(out mediaLength);
                //var frameCount = (int)(frameRate * mediaLength);
                //var duration = frameCount / frameRate;
                return mediaLength.ToString();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 18 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100