Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Benchmarking MP3::Tag vs. MP3::Info

by dha (Acolyte)
on Jul 21, 2006 at 04:03 UTC ( #562763=perlmeditation: print w/replies, xml ) Need Help??

While idly thinking about coding an mp3 sorting program, I decided to look at my options for reading mp3 tags.

Turns out that (unless my benchmarking is off) MP3::Info is much faster than MP3::Tag. pudge was quite pleased...

If the following benchmark is completely off, I can only claim exhaustion, as it was wirtten at an hour when I should have been asleep. :-)

#!/usr/local/bin/perl use MP3::Info; use MP3::Tag; use Benchmark; use strict; use warnings; my $track = shift; timethese( shift || 10000, { info => sub { my $tag = get_mp3tag($track); my $tracknum = $tag->{TRACKNUM}; }, autotag => sub { my $mp3 = MP3::Tag->new($track); my $tracknum = ( $mp3->autoinfo )[1]; }, manualtag => sub { my $mp3 = MP3::Tag->new($track); $mp3->get_tags; if ( exists $mp3->{ID3v1} ) { # read some information from the tag my $id3v1 = $mp3 ->{ID3v1}; # $id3v1 is only a shortcut for $mp3 +->{ID3v1} my $tracknum = $mp3->{ID3v1}->track; } if ( exists $mp3->{ID3v2} ) { # read some information from the tag my $tacknum = $mp3->{ID3v2}->get_frame("TRCK"); # delete the tag completely from the file $mp3->{ID3v2}->remove_tag; } $mp3->close(); } } );

Replies are listed 'Best First'.
Re: Benchmarking MP3::Tag vs. MP3::Info
by b10m (Vicar) on Jul 21, 2006 at 06:44 UTC

    It would be nice to also post the results of your benchmarking, for those who don't have the modules/don't want to have the modules installed ...

    --
    b10m

    All code is usually tested, but rarely trusted.
      My apologies. I guess my underlying assumption was that if you didn't have them installed, you wouldn't actually care. :-)
      ~/mp3tools 12:46:27% perl tagbench.pl Perlcast_Interview_001_brian_foy +.mp3 Benchmark: timing 10000 iterations of autotag, info, manualtag... autotag: 269 wallclock secs (66.60 usr 70.78 sys + 8.18 cusr 56.58 + csys = 202.14 CPU) @ 72.79/s (n=10000) info: 12 wallclock secs ( 8.44 usr + 1.06 sys = 9.50 CPU) @ 10 +52.63/s (n=10000) manualtag: 202 wallclock secs (25.07 usr 65.54 sys + 8.18 cusr 56.49 + csys = 155.28 CPU) @ 110.36/s (n=10000)
Re: Benchmarking MP3::Tag vs. MP3::Info
by xdg (Monsignor) on Jul 21, 2006 at 10:30 UTC

    Regarding MP3::Info, be careful if you plan on setting any tags, as you may not get what you expect. From the docs:

    set_mp3tag (FILE, TITLE, ARTIST, ALBUM, YEAR, COMMENT, GENRE [, TRACKN +UM]) set_mp3tag (FILE, $HASHREF) ID3v2 support may come eventually. Note that if you set a tag on a + file with ID3v2, the set tag will be for ID3v1[.1] only, and if you +call get_mp3tag on the file, it will show you the (unchanged) ID3v2 t +ags, unless you specify ID3v1.

    I'm assuming this is why the "manualtag" example is removing the ID3v2 tag.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Benchmarking MP3::Tag vs. MP3::Info
by revdiablo (Prior) on Jul 21, 2006 at 16:12 UTC

    You might also want to include Audio::File::Tag and MPEG::ID3v2Tag, if you want to have a more complete show-down. Incidentally, I'd like to note that I've used all these modules, and found them all wanting for one reason or another. I've thought about writing my own, or extending the ones that are already there... but -- probably the same reason the original modules aren't perfect -- it's a sort of pain in the butt. In any event, if you have any problems, please share, and I might be able to suggest alternatives. :-)

Re: Benchmarking MP3::Tag vs. MP3::Info
by dsully (Acolyte) on Jul 21, 2006 at 18:06 UTC
    Hi - I'm now the owner of MP3::Info, after taking it over from pudge. Myself, working on behalf of my employer - Slim Devices, have made significant performance improvements to the MP3::Info codebase. As well as supporting & parsing tags such as RVAD (Volume Adjustment), TXXX frames and more. There's also support for reading APE tags stuck in the ID3v1 space which many use for Reply Gain information.

      Cool. I love my two Slim Devices. Any chance it will support writing ID3v2 any time soon?

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

        Unfortunately not.. Just not on the priority list. SlimServer never writes tags.. and I've not had a need for it myself.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://562763]
Approved by Zaxo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2022-05-18 00:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (68 votes). Check out past polls.

    Notices?