使用Dropzone.js获取视频文件的持续时间

Get the duration of video file with Dropzone.js

本文关键字:文件 持续时间 视频 获取 Dropzone js 使用      更新时间:2023-09-26

我正在使用Dropzone.js上传内容。

我一直在寻找一种方法来获得视频文件的持续时间,如其他属性可以在这个库中访问,如"大小,宽度,高度和名称",但我没有找到任何东西。

谁能帮帮我?

您需要使用外部库,服务器上的一些扩展/应用程序。例如ffprobe。用javascript检查视频时长是不可能的。

如果你只使用标准的html5格式,如mp4,你可以使用callback:

Dropzone.options.filedrop = {
  init: function () {
    this.on("complete", function (file) {
      if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
        console.log(file); // here you can check where is filename etc.
        $('<video>').attr('src', value); // create video tag, and check it
      }
    });
  }
};