Getting Duration (Playing Length) from Many MP3s

As part of a larger effort to check the validity of many MP3 files, I arrived at the question of whether the duration of these MP3s had changed. This post summarizes a few inquiries I made along those lines. (I was using a Windows 7 desktop computer.)

I saw that someone recommended TagScanner as an easy way of getting duration information on a folder full of MP3s. (In this case, I had searched for *.mp3 in the Everything file finder; I had highlighted all of the MP3s I wanted to test, and I put copies of them in a single folder.) Softpedia indicated that TagScanner was a widely used and highly rated program: 4.7 stars for the portable version, which I downloaded and ran. I clicked the folder-plus icon at the top left corner, designated the desired folder, waited for it to load, scrolled the list of files to the right, to verify that it included Length information, clicked on the file list and hit Ctrl-A to select all files, selected CSV-Excel template, and clicked Export. I neglected to specify an output file and folder, so it produced TrackList.csv in the folder containing my MP3s. Rather than open that by double-clicking on it, I opened it from within Excel via File > Open. That gave me the option of importing it as semicolon-delimited text without headers. Unfortunately, the results were somewhat chaotic — I had to use filters to determine that TagScanner was presenting the file information that people may have stuck into various tags, sometimes seemingly at random — and in any case there was no duration information.

Salmon Trout recommended using an ffmpeg command to get duration information. I downloaded and unzipped FFmpeg for Windows x64 3.2.2, but my attempt at using ffmpeg in a batch script was not successful. In response to my question, LordNeckbeard recommended using an ffprobe command instead. I ran his suggested command, with enhancements, in a batch file called MP3DURATION.BAT:

@echo off

if exist MP3Duration.txt del MP3Duration.txt

for %%i in (*.mp3) do (
  echo %%i
  echo %%i >> MP3Duration.txt
  ffprobe -loglevel error -select_streams a -show_entries stream=duration -sexagesimal -of default=noprint_wrappers=1:nokey=1 "%%i" | TEE.BAT -a MP3Duration.txt

To run that batch file, I put it, and a copy of Tee.bat and (from the FFmpeg download) ffprobe.exe in the folder where I would be running the batch script. I had already used Ultimate Windows Tweaker (as one of several ways) to add the context menu option, “Open Command Window Here,” and I used that option now. I wanted to run the batch file in a window (by typing its name on the command line) so that I could see what it was doing. Actually, for the first tests, I just put those materials and copies of a few MP3s in a subfolder. That file worked OK, but it put the filename and the duration on two separate lines.

Someone else suggested the MediaInfo command line. I wasn’t having good luck with the MediaInfo 0.7.91 GUI, but did manage to work up a MediaInfo command. I didn’t see information on MediaInfo parameters at the MediaInfo website — no doubt it was there; I just couldn’t find it — but I did manage to capture the parameters to a text file by typing the necessary command in the folder where I had saved the command-line version of MediaInfo.exe. I figured out the command by typing “mediainfo -h” which, in turn, told me to type something like “mediainfo –Info-Parameters >> MediaInfo_Parameters.txt,” saving the output to that text file. That parameters text file, in turn, guided me (with the aid of other webpages) to work up this batch file:

@echo off
mediainfo --output=General;%%FileName%%.%%FileExtension%%^|%%Duration/String3%%\r\n *.mp3 *.wav > MP3Duration.txt

I didn’t actually need a batch file — I could have just run the final command directly, replacing double %% marks with single ones — but I wanted to save the line in a convenient place for future use. The mediainfo command shown there produced output in this format:


which indicated that Filename.mp3 was nine minutes, 25 seconds, and 577 milliseconds long. For the few files I checked, this duration information seemed to match that provided by MediaTab. Persons interested in direct access to MP3 data would perhaps appreciate that the MediaInfo command line was capable of outputting nearly 1,500 data items on media files (e.g., number of audio streams, size of header, file size, bitrate, contents of many different tags, plus many video parameters).

As shown in the foregoing command, my output file was named MP3Duration.txt. In Excel, I went to File > Open > Browse. I selected that output file and indicated that it was delimited by the | character. Unfortunately, that method of importing seemed to mangle the duration field. I tried again, copying and pasting from the output text file directly into an Excel spreadsheet, and then using =FIND to separate the duration information.

That worked. For the most part, MediaInfo produced credible information on the duration of the MP3s. For a small number of files (about 1% of the total), MediaInfo failed to provide duration information on playable MP3s. These seemed mostly to be old MP3s; possibly their flaws or quality fell below its threshold somehow. In other cases, by showing no duration, MediaInfo identified files that really were unplayable.

A blank copy of the spreadsheet I used is available at the locations specified in the Conclusion of the other file.

This entry was posted in Uncategorized and tagged , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s