views:

790

answers:

4

hi I wants to get video file duration in C#. I have the to get video file duration but code works only local computer. If i deploy my code on server and upload a video file then this code gives error. I m using the following code to get video time.

using QuartzTypeLib;

 string file1 = "c://ds.mpeg"
        IMediaPosition m_objMediaPosition = null;
        FilgraphManager m_objFilterGraph = new FilgraphManager();
        m_objFilterGraph.RenderFile(filename);
        m_objMediaPosition = m_objFilterGraph as IMediaPosition;

        int s = (int)m_objMediaPosition.Duration;
        int h = s / 3600;
        int m = (s - (h * 3600)) / 60;
        s = s - (h * 3600 + m * 60);

        string time = String.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s);
        lblmsg.Text = time.ToString();
        m_objMediaPosition = null;
        m_objFilterGraph = null;

Have u any code which return time duration of a uploaded video file.

A: 

Sounds like the control you are using is trying to reference the graphics hardware in some way to perform this function. i.e. using the UI to be able to enumerate this information.

Perhaps you can look at the MediaElement control in WPF?

Sebastian Gray
A: 

What you mean by deploying your code to the server? Are you use the above code in a ASP.NET app?

If possible provide the complete code.

+1  A: 

try using DirectShowLib

Chen Kinnrot
A: 

Quick and dirty way with ffmpeg: run ffmpeg -i "c:\ds.mpeg" and parse the output.

RA