How can I get the length of a video file from the console?

ffprobe -i some_video -show_entries format=duration -v quiet -of csv="p=0"

will return the video duration in seconds.


Something similar to:

ffmpeg -i input 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,//

This will deliver: HH:MM:SS.ms. You can also use ffprobe, which is supplied with most FFmpeg installations:

ffprobe -show_format input | sed -n '/duration/s/.*=//p'

… or:

ffprobe -show_format input | grep duration | sed 's/.*=//')

To convert into seconds (and retain the milliseconds), pipe into:

awk '{ split($1, A, ":"); print 3600*A[1] + 60*A[2] + A[3] }'

To convert it into milliseconds, pipe into:

awk '{ split($1, A, ":"); print 3600000*A[1] + 60000*A[2] + 1000*A[3] }'

If you want just the seconds without the milliseconds, pipe into:

awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }'

Example:

enter image description here