Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get video duration in seconds? [duplicate]

How can I get video duration in seconds?

what I've tried:

ffmpeg -i file.flv 2>&1 | grep "Duration"
  Duration: 00:39:43.08, start: 0.040000, bitrate: 386 kb/s


mediainfo file.flv | grep Duration
Duration : 39mn 43s

this what close, but it's not so accurate, 2383 is 39.71 minutes

    ffmpeg -i file.flv 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | sed 's@\..*@@g' | awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }'
2383
like image 469
user2783132 Avatar asked Sep 25 '13 19:09

user2783132


People also ask

How do you find the duration of a reaction video?

You may add a loadedmetadata event handler to the video element. When the event is fired, the duration and dimensions of the media and tracks are known.

How do I find the length of a video in HTML?

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.


1 Answers

There is a better, faster and low CPU/HD footprint solution, just with mediainfo without relying into awk:

mediainfo --Inform="General;%Duration%" input.m4v
like image 193
Rodrigo Polo Avatar answered Sep 24 '22 03:09

Rodrigo Polo