Audio::Digest::MP3 - Get a message digest for the audio stream out of an MP3 file (skipping ID3 tags)


  use Audio::Digest::MP3;
  my $streaminfo = Audio::Digest::MP3->scan($filepath, 'MD5');
  printf "%s: %s (%s) %s\n", $file,


Sometimes you want to know if you have duplicate MP3 files on your disks. But as soon as you start editing the ID3 tags, the file contents changes, and you can no longer trust a plain MD5 checksum on the file, nor the file size, to compare them.

This module scans the MP3 file, only including the audio stream (undecoded!) to calculate the message digest.

While it scans, it compiles more metadata about the file, such as playing time, either in seconds or as formatted string, bitrate (in kbits/sec), stream size in bytes, and whether the file is a CBR or a VBR file.

In short: lots of info that you can use to compare MP3 files, but excluding any info coming out of the ID3 tags.

By default, it uses Digest::MD5 to calculate the digest, but if you specify 'SHA1' (or any other specifier for a message digest module, that is compatible with Digest) it'll use that instead.

It uses MPEG::Audio::Frame, a Pure Perl module, to extract the stream from the file. Average processing speed on my computer is about 1-2MB/sec.



The message digest for the stream

my $info = Audio::Digest::MP3->scan($filepath)
my $info = Audio::Digest::MP3->scan($filepath, 'MD5')
my $info = Audio::Digest::MP3->scan($filepath, 'SHA1')

This class method scans the audio stream for an MP3 file, calculating its message digest and various other meta data, and constructing a summary data structure in the form of an object. When used as a string, this object returns the hex digest string.

Default digest type is MD5.


Get the playing time for an MP3 file, either as a number (seconds) or as a time formatted string (playing_time). For the latter you can pass a parameter specifying the number of decimals for roundoff of fractional seconds. If this number is negative, trailing zeros as well (as a trailing decimal point) are dropped. Default is -1.


The integer number of audio frames


The number of bytes in the audio stream.


Returns the average bitrate in kbits/sec. If the file is a CBR file, this is the bitrate used for the file – this value may be slightly different from the quotient of stream size over playing time.


Returns a boolean on whether this file is a constant bitrate file, or a variable bitrate file.


The basic idea is, if it ever becomes feasable, to add support for other compressed audio file formats, for example for Ogg Vorbis under Audio::Digest::Ogg, and next, to provide a unifying interface as Audio::Digest, that would figure out by itself what kind of audio file it is, and which in turn invokes the proper module to calculate its stream digest.

As things are looking now, I do not plan on ever adding support for DRM-infected files.


None by default.





Bart Lateur, <>


Copyright (C) 2006-2009 by Bart Lateur

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.0 or, at your option, any later version of Perl 5 you may have available.