Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining MP3 Length

Status
Not open for further replies.

AbidingDude

Programmer
Oct 7, 2012
74
0
0
US
So I've just spent a good chunk of time learning the basics of ID3 tags. I was able to make a basic routine to read them. The main purpose of that was to specifically look at the TLEN frame. I wanted to make a simple routine to determine MP3 times and add them up. After playing around with a few different files I realized something - ID3 tags are not a necessary part of the file, so I found some of my MP3s did not have a TLEN frame. Is there another way to determine song length of an MP3 file?
 
If you're going to play it and have something lined out already, simply loading it will get a song length.

Or you'd have to continue into the data and start reading/counting frames.


As I understand it, whatever the bit rate on the frame header is is going to represent one second of actual data. Of course, you have VBR files, so you have to read through a file completely to diagnose those.

You'll have to play a little bit to get the exact way things work going for any file you encounter. But it'll be a decent start.
 
Glenn9999 said:
If you're going to play it and have something lined out already, simply loading it will get a song length.

Right. No I'm looking to add up MP3 times. I'm trying to work on a program such that I can pass it a list of MP3 files, and it will sum up the track lengths.

Glen9999 said:
Or you'd have to continue into the data and start reading/counting frames.


As I understand it, whatever the bit rate on the frame header is is going to represent one second of actual data. Of course, you have VBR files, so you have to read through a file completely to diagnose those.

You'll have to play a little bit to get the exact way things work going for any file you encounter. But it'll be a decent start.

Looks like now I'll have to learn parsing actual MP3 data. That link was helpful though!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top