So I want to show a list of MP3 files with their durations.

ffprobe does show me the duration of a file. But its output is nasty. It puts everything into stderr and I have found no way to remove its "very helpful" information about how it was compiled.

So if I loop it through *.mp3, that information is displayed every single time.

I could write a filter script but might there be a simpler solution?


2 Answers 2


To get an output like this:

00:07:22 first.mp3
00:02:33 second.mp3
00:04:04 third.mp3


for file in *.mp3
  echo -n $(ffprobe "$file" 2>&1 | grep 'Duration' | cut -d',' -f1 | cut -d' ' -f4 | cut -d'.' -f1)
  echo " $file"


  • 2>&1 redirects stderr to stdout
  • grep ... filters just the line with the duration
  • 1st cut ... extracts Duration: 00:07:22.33
  • 2nd cut ... extracts 00:07:22.33
  • 3rd cut ... extracts 00:07:22

You can easily get rid of the information that is put into stderr with the -loglevel -quiet option. In that case you have to have to query the field you want to display.

[user@host ~]$ ffprobe -loglevel quiet -show_entries format=duration test/test.mp3 

Now this does still gives some extra information which can be stripped down and the duration in seconds.

[user@host test]$ ffprobe -loglevel quiet -show_entries format=duration \-print_format default=noprint_wrappers=1:nokey=1 -pretty test.mp3 

Here, the -print_format can be used to get rid of the extra information:

  • default=noprint_wrappers=1 will remove the [FORMAT] stuff
  • nokey=1 will remove the keyname duration=

Last but not least, you can use -pretty or just -sexagesimal to convert the duration in seconds to a HH:MM:SS.MICROSECONDS format.

To find all MP3 files in a folder you could combine find and the ffprobe command from above.

[user@host ~]$ find test/ -name '*mp3' -printf "%f:\t" -exec ffprobe -loglevel error -print_format default=noprint_wrappers=1:nokey=1 -pretty -show_entries stream=duration "{}" \;
test.mp3:   0:02:52.434286

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .