I am trying to read metadata from a file. I only need the Video -> Length property, however I am unable to find a simple way of reading this information.
I figured this would be fairly easy since it is visible by default in Explorer, however this looks to be way more complicated than I anticipated. The closest I came was using:
Microsoft.DirectX.AudioVideoPlayback.Video video = new Microsoft.DirectX.AudioVideoPlayback.Video(str);
double duration = video.Duration;
However this throws a LoaderLock exception, and I don't know how to deal with it.
Any ideas?
use MCI
its easy to use and works even on NT:
Getting duration of video file in Win Rt App or Metro C#:
using DirectShowLib (http://directshownet.sourceforge.net/)
You can use our wrapper for ffprobe Alturos.VideoInfo. You can use it simply by installing the
nuget
package. Also the ffprobe binary is required.Example
Take a look at this SO question - Solid FFmpeg wrapper for C#/.NET which links to several ffmpeg .Net implementations. ffmpeg works with most video formats/codecs. That way you don't need to worry about the codec being installed on the machine.
Or look at https://mediaarea.net/en/MediaInfo.
I had the same issue with a small video preview app.
The issue is Managed Debugging Assisstants. This is an issue when using The Managed DirectX 1.1 libraries in VS2005 or 2008. Microsoft has moved on to focus on MDX2 and then XNA rather than Managed DirectX 1 so don't hope too much for a patch.
The easy workaround is to disable the LoaderLock Exception handling while debugging that solution. This should have no real effect on the program anyways since this error only shows up in a debug environment.
To disable go to Debug -> Exceptions -> Managed Debugging Assistants and uncheck LoaderLock.
More info here:http://vivekthangaswamy.blogspot.com/2006/11/loaderlock-was-detected-error-when.html