如何从mp4,m3u8或任何其他文件获取视频时长

时间:2017-10-27 06:39:44

标签: c# video m3u8 nreco

我发现NReco.VideoInfo库是最好的选择,而且更简单

1]在NuGet Package Manager中找到NReco.VideoInfo库并将其导入项目中

2]之后使用NReco.VideoInfo"

导入命名空间"

3]将以下代码行添加到方法中。

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

here您可以看到其他选项

2 个答案:

答案 0 :(得分:3)

为什么不使用Windows Media Player来解决这个问题?

int

答案 1 :(得分:0)

如果你的意思是来自本地文件,下面将显示持续时间而不加载整个视频文件(在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>

同样的方法也适用于流式视频。