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
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.
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.
There is a better, faster and low CPU/HD footprint solution, just with mediainfo without relying into awk:
mediainfo --Inform="General;%Duration%" input.m4v
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With