Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

time length of an mp3 file

What is the simplest way to determine the length (in seconds) of a given mp3 file, without using outside libraries? (python source highly appreciated)

like image 991
Silver Dragon Avatar asked Sep 23 '08 06:09

Silver Dragon


People also ask

How do I find the length of a MP3?

Using Audio Tag. The easiest way to obtain the duration of an audio file is through the embed Audio tag, used to embed sound content in documents. It may contain one or more audio sources, represented using the src attribute or the <source> element nested on the audio tag.

How do you calculate the length of an audio file?

To determine the file size of an audio file, we have to multiply the bit rate of the audio by its duration in seconds. As a result, we get file size values in terms of kilobits and megabits.

How big is a 1 minute MP3?

1024 / 3.28 If you really don't feel like doing all the math, you can remember that, for MP3s at a bitrate of 128 Kbps, 1 minute of audio equals about 1MB.

How long are MP3 files?

The maximum file size for mp3s and wavs is just under 50MB, because 50MB is the total project size limit. When scratch uploads sounds, it first turns them into wavs. This may be increasing your file size. Try manually converting your mp3 into a wav with Audacity or something similar and see how big it becomes.


1 Answers

You can use pymad. It's an external library, but don't fall for the Not Invented Here trap. Any particular reason you don't want any external libraries?

import mad

mf = mad.MadFile("foo.mp3")
track_length_in_milliseconds = mf.total_time()    

Spotted here.

--

If you really don't want to use an external library, have a look here and check out how he's done it. Warning: it's complicated.

like image 89
Harley Holcombe Avatar answered Sep 28 '22 10:09

Harley Holcombe