[FFmpeg-user] Help please using FFprobe to find duration in minutes (rounded up).
Moritz Barsnick
barsnick at gmx.net
Wed Aug 3 22:46:59 EEST 2016
On Wed, Aug 03, 2016 at 19:35:01 +0000, batguano999 wrote:
> Please can somebody suggest a way how to extract the duration of a file using FFprobe, in minutes, rounded up.
>
> I found this with a web search but it's old and looks clumsy.
> ffmpeg -i foo.ts 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] }'
A bit. ffprobe is capable of printing only desired fields, check the
lovely example in the wiki:
https://trac.ffmpeg.org/wiki/FFprobeTips#Formatcontainerduration
This command prints the (container) duration in seconds:
$ ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 foo.ts
(You might want to add "2>/dev/null". Or just leave it if you use
backticks or the likes.)
You could compare that floating point value against seconds instead of
minutes, or do your math to get the minutes. (I probably wouldn't do
the math with awk, but either directly with the shell, or with bc. But
that's just me.)
Moritz
More information about the ffmpeg-user
mailing list