问题
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
回答1:
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;
}
回答2:
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.
来源:https://stackoverflow.com/questions/46968928/how-to-get-video-duration-from-mp4-m3u8-or-any-other-file