gregor42 has asked for the wisdom of the Perl Monks concerning the following question:

OK, to qualify this, you might call it Off Topic, but the result could also be a Cool New Use for Perl...

What I'm trying to figure out here is how I can programatically determine the length of an MP3 file. That is to say, the 'playing time' of the sound clip - as opposed to the file size. Clearly it can be done somehow - bringing up an MP3 file in most players will list the run-time in the standard display.

Upon hitting up Super-Seach I've found references to Apache::MP3, and the like - but no relevant info on this specific topic.

This might be useful for displaying a list of MP3's on a web site, generating statistics on uploaded MP3's that could be stored in a database, etc..

I'm wondering if someone might be able to point me in the right direction?

- Gregor42



Wait! This isn't a Parachute, this is a Backpack!
  • Comment on slightly OT - How can I calculate the length of an MP3 file

Replies are listed 'Best First'.
Re: slightly OT - How can I calculate the length of an MP3 file
by b10m (Vicar) on Apr 15, 2004 at 15:57 UTC

    CPAN is your friend (as usual). MP3::Info tells me it has "get_mp3info", which will give you the time in MM:SS and other formats too :)

    --
    b10m

    All code is usually tested, but rarely trusted.
Re: slightly OT - How can I calculate the length of an MP3 file
by simonm (Vicar) on Apr 15, 2004 at 16:00 UTC
    Searching CPAN for MP3 reveals a number of candidates.

    For example:

    use MP3::Info; my $mp3 = MP3::Info->new( $my_file_name ); print $mp3->time, $mp3->title;
Re: slightly OT - How can I calculate the length of an MP3 file
by Anonymous Monk on Apr 15, 2004 at 17:11 UTC
    I am sorry for saying this, but you have been a Perlmonk for 3 years now and you still don't know to search CPAN first? What are we teaching? How to be lazy or how to find stuff on your own?

      <<bows deeply>> I beg forgiveness from... from... <<looks around>> .... some anonymous detractor...<<shrug>>

      I plead guilty - the problem was not my own but in the spirit of compassion I tried to help someone look for an answer to a question. In my haste indeed I failed to check CPAN... Note to self, add "check CPAN first" to mantra right after "use strict"

      Many humble thanks to those monks who offered their assistance & with such alacrity and generosity.

      As I stated previously, no one had apparently asked this question on the site before, as evidenced by my failed attempt at wielding Super Search. It is my humble hope that the next fool such as I might now have the benefit of finding an answer in this way.

      To answer your question I would think that sharing knowledge free from condescention would be a precept of what we teach here also.. Though clearly I have just failed at doing so myself.

      Again, apologies.. Sumimasen!

      And again, many thanks.. Domo Arigato!

      - Gregor42



      Wait! This isn't a Parachute, this is a Backpack!