2

I am using ng2-file-upload for uploading videos and maximum duration of uploading is 15 minutes. So how can I get it's duration just before uploading it to server? These extensions are allowed only :- -.MOV -.MPEG4 -.AVI -.FLV -.3FPP -.WebM and -.MPEGS. Please reply if anyone knew it.

Garima
  • 1,566
  • 2
  • 11
  • 14
  • Can your tools (Angular, etc) check byte values? You have to check the bytes of the file's metadata section for each format. Also those video formats have **specifications** posted online. For example search `FLV format specifications`. Open an _x_-format video file with hex editor to see its bytes. If you can find duration manually, then next write code to do it. – VC.One Aug 31 '17 at 20:08
  • Using ng2-file-upload I only get the size of the video. How can I find it's duration? – Garima Sep 01 '17 at 09:22
  • The size means how many total bytes it contains. If you know what is an array, then bytes are just one big array of numbers. You need to check the number values at indexes like example `myVideoBytes[0]` or `myVideoBytes[15]`. Check the format specifications since MOV puts duration bytes at different place to AVI, which also is different for FLV etc.. To handle user selecting a file, are you using HTML5's `File` API or via PHP? – VC.One Sep 01 '17 at 09:58

1 Answers1

0

You can include vanilla Javascript in your Angular application to do this.

The following will give you a duration (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>
Mick
  • 24,231
  • 1
  • 54
  • 120