Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way we can get video duration before upload?

I want to limit the user to upload only videos with duration up to 30 sec.Is there any Way?

like image 704
Kalidas Rajeev Avatar asked Nov 18 '17 07:11

Kalidas Rajeev


People also ask

How do you find the duration of a video tag?

To display the duration in a pretty fashion, you'll need to use parseInt and modulus ( % ): // Assume "video" is the video node var i = setInterval(function() { if(video. readyState > 0) { var minutes = parseInt(video. duration / 60, 10); var seconds = video.

Why is video duration NaN?

The Video duration function returns “NaN” if no video is set whereas if the video is streamed and has no predefined length, it returns “Inf” (Infinity).

How do I get the length of a video in laravel?

$video_file = $getID3->analyze('path-to-your-video'); // Get the duration in string, e.g.: 4:37 (minutes:seconds) $duration_string = $video_file['playtime_string']; // Get the duration in seconds, e.g.: 277 (seconds) $duration_seconds = $video_file['playtime_seconds'];


1 Answers

Try this

<form action="#" method="post" enctype="multipart/form-data">
  File: <input type="file" name="fup" id="fup" /><br>
  Duration: <input type="text" name="f_du" id="f_du" size="5" /> seconds<br>
  <input type="submit" value="Upload" />
</form>
<audio id="audio"></audio>

<script>
// Code to get duration of audio /video file before upload - from: http://coursesweb.net/

//register canplaythrough event to #audio element to can get duration
var f_duration =0;  //store duration
document.getElementById('audio').addEventListener('canplaythrough', function(e){
  //add duration in the input field #f_du
  f_duration = Math.round(e.currentTarget.duration);
  document.getElementById('f_du').value = f_duration;
  URL.revokeObjectURL(obUrl);
});

//when select a file, create an ObjectURL with the file and add it in the #audio element
var obUrl;
document.getElementById('fup').addEventListener('change', function(e){
  var file = e.currentTarget.files[0];
  //check file extension for audio/video type
  if(file.name.match(/\.(avi|mp3|mp4|mpeg|ogg)$/i)){
    obUrl = URL.createObjectURL(file);
    document.getElementById('audio').setAttribute('src', obUrl);
  }
});
</script>
like image 84
Channa Avatar answered Sep 26 '22 08:09

Channa