Louise Louise - 1 year ago 130
Linux Question

How to extract duration time from ffmpeg output?

To get a lot of information about a media file one can do

ffmpeg -i <filename>

where it will output a lot of lines, one in particular

Duration: 00:08:07.98, start: 0.000000, bitrate: 2080 kb/s

I would like to output only
, so I try

ffmpeg -i file.mp4 | grep Duration| sed 's/Duration: \(.*\), start/\1/g'

But it prints everything, and not just the length.

ffmpeg -i file.mp4 | grep Duration
outputs everything.

How do I get just the duration length?

Answer Source

ffmpeg is writing that information to stderr, not stdout. Try this:

ffmpeg -i file.mp4 2>&1 | grep Duration | sed 's/Duration: \(.*\), start/\1/g'

Notice the redirection of stderr to stdout: 2>&1


Your sed statement isn't working either. Try this:

ffmpeg -i file.mp4 2>&1 | grep Duration | awk '{print $2}' | tr -d ,
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download