Programmatically get video duration

2019-07-26 22:29发布

问题:

I'd need to get the video duration of a mp4 video (video format AVC)

I'm using DirectShowLib 2.1

I downloaded a couple of codecs but I'm still getting code -2147220891 (an error code that I don't know what it means) doing

 graphBuilder.RenderFile(filePath, null);

Any idea how to get the duration of this kind of video?

回答1:

-2147220891 is 0x80040265 in hex. A search for that error code revealed this thread

0x80040265 isn't really "unknown". Strictly, it is VFW_E_UNSUPPORTED_STREAM, which means that your AVI files contain at least one stream (e.g., the video) that you do not have the right codec for.

So it looks like you still haven't found the right codec.

Does the file play in Windows Media Player or VLC (for example)?



回答2:

If you just need the duration of a file, you can try using IMediaDet. I have an example of usage here: http://wpfmediakit.codeplex.com/SourceControl/changeset/view/41623#245585