How do I get the duration of a video file using C#?

How do I get the duration of a video file using C#?

By : user3855121
Date : January 02 2021, 06:48 AM

Share : facebook icon twitter icon
Windows Store app, Is it any way to find Video Duration from Storage File? Other that getting duration from Media Elemen

Windows Store app, Is it any way to find Video Duration from Storage File? Other that getting duration from Media Elemen

By : Vijay Kumar
Date : March 29 2020, 07:55 AM
wish help you to fix your issue While checking with media element the duration is getting only after the media opened event. , getting duration of video file in Win Rt App or Metro C#
code :
StorageFile videoFile; 
string path = ApplicationData.Current.LocalFolder.Path; 
videoFile = await StorageFile.GetFileFromPathAsync(presentationItem.Slide_path_local);     
Windows.Storage.FileProperties.VideoProperties x = await videoFile.Properties.GetVideoPropertiesAsync(); 
Duration videoDuration = x.Duration;
Get video duration when input a video file

Get video duration when input a video file

By : blue blazes
Date : March 29 2020, 07:55 AM
will help you In modern browsers, You can use the URL API's URL.createObjectURL() with an non appended video element to load the content of your file.
code :
var myVideos = [];

window.URL = window.URL || window.webkitURL;

document.getElementById('fileUp').onchange = setFileInfo;

function setFileInfo() {
  var files = this.files;
  var video = document.createElement('video');
  video.preload = 'metadata';

  video.onloadedmetadata = function() {
    var duration = video.duration;
    myVideos[myVideos.length - 1].duration = duration;

  video.src = URL.createObjectURL(files[0]);;

function updateInfos() {
  var infos = document.getElementById('infos');
  infos.textContent = "";
  for (var i = 0; i < myVideos.length; i++) {
    infos.textContent += myVideos[i].name + " duration: " + myVideos[i].duration + '\n';
<div id="input-upload-file" class="box-shadow">
  <span>upload! (ღ˘⌣˘ღ)</span>
  <input type="file" class="upload" id="fileUp" name="fileUpload">
<pre id="infos"></pre>
How to get duration of video when I am using filereader to read the video file?

How to get duration of video when I am using filereader to read the video file?

By : user3596363
Date : March 29 2020, 07:55 AM
will help you You can do something like this for that to work:
read the file as ArrayBuffer (this can be posted directly to server as a binary stream later) wrap it in a Blob object create an object URL for the blob and finally set the url as the video source.
code :
var fileEl = document.querySelector("input");
fileEl.onchange = function(e) {

  var file = e.target.files[0],                               // selected file
      mime = file.type,                                       // store mime for later
      rd = new FileReader();                                  // create a FileReader
  rd.onload = function(e) {                                   // when file has read:
    var blob = new Blob([e.target.result], {type: mime}),     // create a blob of buffer
        url = (URL || webkitURL).createObjectURL(blob),       // create o-URL of blob
        video = document.createElement("video");              // create video element

    video.preload = "metadata";                               // preload setting
    video.addEventListener("loadedmetadata", function() {     // when enough data loads
          .innerHTML = "Duration: " + video.duration + "s";   // show duration
      (URL || webkitURL).revokeObjectURL(url);                // clean up

      // ... continue from here ...

    video.src = url;                                          // start video load
  rd.readAsArrayBuffer(file);                                 // read file object
<input type="file"><br><div></div>
how to get video file duration in C#

how to get video file duration in C#

By : user3795708
Date : March 29 2020, 07:55 AM
I hope this helps you . Quick and dirty way with ffmpeg: run ffmpeg -i "c:\ds.mpeg" and parse the output.
How to get duration of a video file?

How to get duration of a video file?

By : Srinivasa Rao
Date : March 29 2020, 07:55 AM
may help you . I'm a beginner in Android programming. , Use MediaMetadataRetriever to retrieve media specific data:
Related Posts Related Posts :
  • Looking for a .Net ORM
  • Cost of SortedDictionary.Count
  • All possible combinations of n items selected randomly from a set of x items (algorithm)
  • Displaying process percentage on DOS screen
  • C# Importing Large Volume of Data from CSV to Database
  • c# control location precision
  • Printing to Zebra printer gives faint and blurry images
  • How to avoid stepping into dll code file?
  • Programmaticaly prevent Vista desktop search (WDS) from indexing pst files placed on mapped network drives
  • Is there anyway to reduce IsolatedStorage capacity in Silverlight?
  • C#: How to print a unicode string to console?
  • Frequency Table with Random Values
  • My Visual Studio 2008 web application keeps throwing a .Net error when I first run it, but refreshing fixes it
  • TCP Connection Creation and Closing Event Hooking
  • Find changed properties of a class
  • C#: Object with custom marshaller not containing data after PInvoke call
  • Version Control System with API. Need to get metrics
  • Performance comparison of Dictionaries
  • How to get process name and title of the top window on Windows / C#
  • How to save the ListView contents to a text file?
  • Why not .NET-style delegates rather than closures in Java?
  • Get CLSID by PIA interface Type
  • Visual Studio 2008 C# - Recover solution from application manifest possible?
  • Is a good practice to initialize private data members from within ctor by calling the associated properties instead of t
  • Inserting into a bitstream
  • How do you write byte[] array using log4.net
  • Clickonce + .NET client profile 4 framework + offline
  • Show form that showDialog from mainForm won't block it, but closing mainForm will close it
  • Developing a GPS car tracking system
  • dynamic log4net appender name?
  • Visual studio formatting issue
  • IndexOutOfRangeException when a stream is a multiple of the buffer size
  • How to deal with calculated values with Dependency Properties on a custom WPF control
  • counting from textbox,asp.net
  • Threading best practice when using SFTP in C#
  • how to load PDF file in website page using C#
  • Parent child class relationship design pattern
  • MessageQueue.BeginReceive() null ref error - c#
  • A C# collection, which behaves like C++ set or priority_queue?
  • Animating WPF buttons from inside a style
  • WPF Grid : GridSplitter event
  • Server 2008 Task Scheduler Mapped Drive Access C#
  • Cast problem with LINQ
  • Combo box Item source = ObservableCollection & I need a '-None-' dummy entry at the top
  • Which GUI control is suitable for this purpose?
  • Trying to access App.config file for mail settings but fails to work
  • Invoke PowerShell script from c# in runspace and get line number where error occured
  • How to show html contents with a RichTextBox?
  • FTP monitoring and downloading of new files
  • MEF + Plug-In not updating
  • Efficient handling of super wide, but not so tall, bitmap?
  • .NET 3.0 Unit Testing getting System.MethodAccessException calling .NET 2.0
  • Web Services vs Persistent Sockets
  • How do I dynamically reference incremented properties in C#?
  • Windows Installer (C#) error code 2869
  • Exception "The operation is not valid for the state of the transaction" using TransactionScope
  • Tools for listing database accesses from .NET code
  • Excel VSTO set selection
  • Creating a subscription based website in ASP.NET
  • Merging Resources Dictionaries
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk