First, I try FFMPEG Wrapper but it gets an error after found an easy solution.
You can use this nugget package:
Install-Package Microsoft.WindowsAPICodePack-Shell -Version 1.1.0
In your project add two namespaces.
using Microsoft.WindowsAPICodePack.Shell;
using.Microsoft.WindowsAPICodePack.Shell.PropertySystem;
ShellFile so = ShellFile.FromFilePath(your file path);
double nanoseconds;
double.TryParse(so.Properties.System.Media.Duration.Value.ToString(),
out nanoseconds);
if (nanoseconds > 0)
{
double seconds = Convert100NanosecondsToMilliseconds(nanoseconds) / 1000;
int ttl_seconds = Convert.ToInt32(seconds);
TimeSpan time = TimeSpan.FromSeconds(ttl_seconds);
}
public static double Convert100NanosecondsToMilliseconds(double nanoseconds)
{
return nanoseconds * 0.0001;
}
Here i store seconds in TimeSpan so its directly give hours:minutes:seconds.