How use get video duration

how to get the length (duration of a media file in c#)
c# get audio file duration
ffmpeg net core
ffmpeg get video duration c#
how to get video duration in java
php get video duration
python get video duration
c# get mp3 duration
using Microsoft.DirectX.AudioVideoPlayback;

Video vvideo = new Video(FileUpload.FileName.ToString());
StringBuilder sb = new StringBuilder();
error message;

"Installed an access attempt was made to the application domain."

"vvideo" instance is created error msj ://

But down found cods I found a working code in c #. but does not work

string file1 = "c://ds.mpeg"
IMediaPosition m_objMediaPosition = null;
FilgraphManager m_objFilterGraph = new FilgraphManager();
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);


I make Function everywhere it uses ;)

public string f_VideoDuration((add path)parameters)

        string sInputVideo = Page.MapPath(add path);
        string sPath = " -i " + sInputVideo ;

        Process ffmepg = new Process();
        ffmepg.StartInfo.FileName = (Server.MapPath("ffmpeg.exe"));
        ffmepg.StartInfo.UseShellExecute = false;
        ffmepg.StartInfo.RedirectStandardOutput = true;
        ffmepg.StartInfo.RedirectStandardError = true;
        ffmepg.StartInfo.CreateNoWindow = true;
        ffmepg.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        ffmepg.StartInfo.Arguments = sPath;
        ffmepg.EnableRaisingEvents = true;
        string sDuration = ffmepg.StandardError.ReadToEnd().ToString();

        sDuration = sDuration.Remove(0, sDuration.LastIndexOf("Duration: ") + 10);
        sDuration = sDuration.Substring(0, sDuration.IndexOf(","));
        return sDuration;
    catch (Exception ex)
        throw (ex);

How to get Video Duration of a file using ASP.NET C#, Using ASP.NET V4 and C# I need to upload a video file to an IIS web server. The video might be a WMV, MPEG4, or WebM file. Using the  Finding duration of Video File Using and C# Please help to find the duration,height and width of Uploaded Video using and C#? Get duration of

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.

PM> install-package Alturos.VideoInfo


var videoFilePath = "myVideo.mp4";

var videoAnalyer = new VideoAnalyzer("ffprobe.exe");
var analyzeResult = videoAnalyer.GetVideoInfo(videoFilePath);

var duration = analyzeResult.VideoInfo.Format.Duration;

How to Get Media File Duration in C#, If you've ever needed to get hold of the duration of a media file such as we can very simply ask for the video duration as a TimeSpan like this: This article shall describe the construction of a custom control used to play video on an ASP.NET web page. The control is based upon the Windows Media Player active X control; with it you can add canned or live video to a web page by setting a property or two at design time, or from the ASP.NET page itself.

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.TryParse(so.Properties.System.Media.Duration.Value.ToString(), out var 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.

NReco.VideoInfo: Get video information for .NET (ffprobe C# wrapper), FFProbe .NET wrapper extracts information about media streams (mp4,avi,mov,​mp3 files or URLs): video format, codec, duration, frame size, frame rate, tags, orientation. ffprobe updated to 3.4.1; in ASP.NET apps ffprobe is extracted to  Duration Calculator Between Two Dates Using ASP.Net C#. I have read many forum posts regarding how to calculate duration between two dates, such as year, months, days and hours but no single post provided the proper solutions so I decided to.

How to get the length (duration) of a media File in , If you have ever looked at a media file (audio or video) in the explorer window on a Windows 7 PC, you may have noticed that it displays  Install .NET and create your first web application. A web app that displays a Hello, World! message on a web page. If playback doesn't begin shortly, try restarting your device. Videos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.

VideoProperties Class (Windows.Storage.FileProperties), Provides access to the video-related properties of an item (like a file or folder). This example demonstrates how to retrieve properties of a file, including video properties like Year and Rating. C# Copy Gets the duration of the video. Height​.

HTML5 Programming for ASP.NET Developers, Notice the use of the get() method, which returns a DOM element at a To display the total length of the selected video file and its playback progress, you need