Getting MP4 File Duration with DirectShow

自作多情 提交于 2019-12-01 14:15:07
Roman R.

You are approaching the problem correctly. You need to build a good pipeline starting from source .MP4 file and up to video and audio renderers. Then IMediaPosition.Duration will get you what you want. Currently you are getting VFW_E_UNSUPPORTED_STREAM because you cannot build the pipeline.

Note that there is no good support for MPEG-4 in DirectShow in clean Windows, you need a third party parser installed to add missing blocks. This is the likely cause of your problem. There are good Free DirectShow Mpeg-4 Filters available to fill this gap.

The code sample under the link Getting length of video is basically valid too, however it uses deprecated component which in additional make additional assumptions onto the media file in question. Provided that there is support for .MP4 in the system, IMediaPosition.Duration is to give you what you look for.

You can use get_Duration() from IMediaPosition interface.

This return a double value with the video duration in seconds.

    Double Lenght;

    m_FilterGraph = new FilterGraph()

//Configure the FilterGraph()

    m_mediaPosition = m_FilterGraph as IMediaPosition;
    m_mediaPosition.get_Duration(out Length);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!