2

I have many folders of mp3 files, and I would like to have a list of the combined duration of all the mp3s in each folder. That would be the ideal solution, but some means of doing a directory print attaching the individual mp3 duration would also be good. Any help would be much appreciated. I am running Windows 7 Home Premium, but have access to a number of other Windows/Mac OS.

Edit - I actually found an solution using the export function in the freeware program Tagscanner.

5 Answers5

5

If you're working on Mac OS or any Unix system you can install ffmpeg and use the following command to extract the duration of a single file:

ffmpeg -i filename.mp3 2>&1 | egrep "Duration" | cut -d ' ' -f 4 | sed s/,//

That would for example return "00:08:17.4".

You can use this in a shell script of course, so for example this would list all of the mp3 files in a folder and their duration to the right.

#!/bin/bash
# call me with mp3length.sh directory
# e.g. ./mp3length . 
# or ./mp3length my-mp3-collection

for file in $1/*.mp3 do echo -ne $file "\t" ffmpeg -i "$file" 2>&1 | egrep "Duration"| cut -d ' ' -f 4 | sed s/,// done

The following script returns total duration in hours:

#!/bin/bash
# call me with mp3length.sh directory
# e.g. ./mp3length .
# or ./mp3length my-mp3-collection

list-individual-times() { for file in $1/*.mp3 do echo -ne $file "\t" ffmpeg -i "$file" 2>&1 | egrep "Duration"| cut -d ' ' -f 4 | sed s/,// done }

TOTAL_HOURS=$(list-individual-times $1 | cut -f2 | xargs -I hhmmss date -u -d "jan 1 1970 hhmmss" +%s | awk '{s+=$1}END{print s/3600}') echo "Total hours: ${TOTAL_HOURS}"

slhck
  • 235,242
5

You can get it easily with oneliner:

$ for file in *.mp3; do mp3info -p "%S\n" "$file"; done | paste -sd+ | sed 's+\(.*\)+(\1)/60+' | bc

Explaining:

  • mp3info: gets individual mp3 length in seconds
  • paste: merge column result with + as separator
  • sed: put () around sum and divides by 60 (minutes
  • bc: perform arithmetic operation
albfan
  • 561
3

You can add a column to the file list in Wİndows Explorer. Add "Length" property colum to folder. Then select all off the mp3 files in the folder. You can see total length in the bottom summary pane of win.exp...

(Not the whole solution to your question but you said "any help would be appreciated :D)

spinodal
  • 1,649
1

A little late in the day (decade!), but I wanted to do exactly the same thing. Thanks to Windows Powershell, here is a little script that I wrote today.

$path = '~\MS Subbulakshmi\1. Toronto 1977\'
$shell = New-Object -COMObject Shell.Application
$folder = $path
$shellfolder = $shell.Namespace($folder)
$total_duration = [timespan] 0
foreach($file in Get-ChildItem $folder)
{
    $shellfile = $shellfolder.ParseName($file.Name)
    $total_duration = $total_duration + [timespan]$shellfolder.GetDetailsOf($shellfile, 27);
}
Write-Host "Total Duration of $folder is $total_duration"

The output would be something like this

Total Duration of ~\MS Subbulakshmi\1. Toronto 1977\ is 01:52:28

0

I'm on a mac and this is what i did:

  1. Installed mp3info via brew -> brew install mp3info
  2. Added an alias to my ~/.profile, like this:
alias mp3length='for file in *.mp3; do mp3info -p "%S\n" "$file"; done | awk '\''{sum+=$1;}END{print "Total length: " sum/60 " minutes";}'\'''

Now mp3length will sum the lenghts of all the mp3 files in any directory and print out the result in minutes.