Suppose we have video file some_video.

How to get length of it from a shell script (with mplayer/transcode/gstreamer/vlc/ffmpeg/whatever)?

VIDEO_LENGTH_IN_SECONDS=`ffmpeg .... -i some_video ... | grep -o .....`
link|improve this question

64% accept rate
feedback

1 Answer

up vote 4 down vote accepted

Something similar to:

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

This will deliver: HH:MM:SS.ms.

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

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

If you don't want 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

link|improve this answer
Also tcprobe is desiged for it, but it doesn't work well on my system. – Vi. Nov 25 '11 at 16:33
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.