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
In case you have
ffmpeg
installed, most likely you would haveffprobe
installed too.The command will return an integer value.
Output example:
190
Using
awk
To handle different formats, use this:
Its Working for me try it :)
2383 is correct. There are 60 seconds in a minute, not 100. 43/60 = .71
https://www.google.com/#q=39+minutes+43.08+seconds+in+seconds
There is a better, faster and low CPU/HD footprint solution, just with mediainfo without relying into awk:
You can use
it will return an xml like this
then filter by the video stream i.e. usually that with attribute index ="0" and get the value of the attribute "duration" which is already in seconds.