How to get video duration from mp4, wmv, flv, mov videos

MonsterMMORPG picture MonsterMMORPG · Apr 17, 2012 · Viewed 60k times · Source

Alright. Actually i need mostly the mp4 format. But if it is possible to get for other types as well that would be nice. I just need to read the duration of the file. How can i do that with C# 4.0 ?

So the thing i need is like this video is like : 13 minutes 12 seconds

I can use 3 third party exes too. Like they save the information about the file to a text file. I can parse that text file.

Thank you.

Answer

nickknissen picture nickknissen · Apr 17, 2012

You could also use windows media player, although it don't support alle file types you requested

using WMPLib;

public Double Duration(String file)
    {
        WindowsMediaPlayer wmp = new WindowsMediaPlayerClass();
        IWMPMedia mediainfo = wmp.newMedia(file);
        return mediainfo.duration;
    }
}