Input of type file to obtain the duration of a video


Good morning; It is possible to obtain the duration of a video by capturing it with input type="file"

<input type="file" class="" id="mivideo" name="mivideo>

either with JavaScript or jQuery or PHP

asked by daniel 19.06.2018 в 02:26

1 answer


You can use duration to get the duration of a video:

var x = document.getElementById("myVideo").duration;

You get the duration in seconds, so in your case you should evaluate that it does not exceed 180 seconds (3 minutes).

I'll attach an example:

function myFunction() {
    var x = document.getElementById("video").duration;
    document.getElementById("demo").innerHTML = x;

<video id="video" width="320" height="240" controls controlsList="nodownload">
    <source src=""  type='video/webm; codecs="vp8, vorbis"'>
    <source src="" type='video/mp4; codecs="avc1,mp4a"'>
<button onclick="myFunction()">Obtener duración</button>

<p id="demo"></p>


I hope I help you.

answered by 19.06.2018 в 20:15