0

I found the NReco.VideoInfo library to be the best option and simpler

1] Find the NReco.VideoInfo library in NuGet Package Manager and import it in your project

2] After that import the namespace "using NReco.VideoInfo"

3] Add the below line of code into the method.

var ffProbe = new FFProbe();
var videoInfo = ffProbe.GetMediaInfo(blob.Uri.AbsoluteUri);
return videoInfo.Duration.TotalMilliseconds;

here you can see some other option

Cleptus
  • 3,446
  • 4
  • 28
  • 34
  • Check this question https://stackoverflow.com/questions/10190906/how-to-get-video-duration-from-mp4-wmv-flv-mov-videos?noredirect=1&lq=1 – Muhammad Hannan Oct 27 '17 at 06:42
  • Possible duplicate of [How to get video duration from mp4, wmv, flv, mov videos](https://stackoverflow.com/questions/10190906/how-to-get-video-duration-from-mp4-wmv-flv-mov-videos) – Hille Oct 27 '17 at 07:16

2 Answers2

3

Why don't you use the windows media player to solve this problem?

using WMPLib;

public Double getDuration(String path)
{
    WindowsMediaPlayer wmp = new WindowsMediaPlayerClass();
    IWMPMedia mediaInfo = wmp.newMedia(file);
    return mediaInfo.duration;
}
Florian Zaskoku
  • 477
  • 3
  • 13
0

If you mean from a local file, the following will show the duration without loading the entire video file (test on mp4):

var inputBox = document.getElementById("videoInput")

inputBox.onchange = function(files)  {
  alert("starting")
  var video = document.createElement('video');
  alert("video created")
  video.preload = 'metadata';
  video.onloadedmetadata = function() {
    alert("metadata loaded")
    var duration = video.duration;
    alert("duration is " + duration)
  }
  var selectedVID = document.getElementById("videoInput").files[0];
  video.src = URL.createObjectURL(selectedVID);
}
<div id="input-upload-file">
  <p>
  Video Upload Duration test
  </p>
  <input id="videoInput" type="file" class="upload" name="fileUpload">
</div>

The same approach will work on streamed videos also.

Mick
  • 24,231
  • 1
  • 54
  • 120
  • Good point! I was not sure myself why I answered like that, looking at it now, until I checked the original version before edits which also had an asp.net tag. – Mick Jun 05 '18 at 22:09