The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

MPEG::Audio::Frame - a class for weeding out MPEG audio frames out of a file handle.

SYNOPSIS

        use MPEG::Audio::Frame;

        open FILE,"file.mp3";

        while(my $frame = MPEG::Audio::Frame->read(\*FILE)){=
                print $frame->offset(), ": ", $frame->bitrate(), "Kbps/", $bitrate->sample()/1000, "KHz\n"; # or something.
        }

DESCRIPTION

A very simple, pure Perl module which allows parsing out data from mp3 files, or streams, and chunking them up into different frames. You can use this to accurately determine the length of an mp3, filter nonaudio data, or chunk up the file for streaming via datagram. Virtually anything is possible.

METHODS

read GLOB

This is the constructor method. It receives a reference to a filehandle, and reads the next (hopefully) valid frame it can find on the stream,

asbin

Returns the binary data extracted from the handle. This is (definately|probably) a valid MPEG 1 or 2 audio frame.

content

Returns the content of the frame, minus the header and the crc. This is (definately|probably) a valid MPEG 1 or 2 audio frame entity.

Returns a folded hash in list context, or a 4 byte long binary string in scalar context. The hash represents the header, split into it's parts, with bits translated into '0' and '1'. The binary string is (definately|probably) a valid MPEG 1 or 2 audio frame header.

crc

Returns the bytes of the checksum, as extracted from the handle. This is (definately) a valid checksum, unless there was none in the frame, in which case it will be undef. It (definately|probably) applies to the frame.

length

Returns the length, in bytes, of the entire frame. This is the length of the content, plus the four bytes of the header, and the two bytes of the crc, if applicable.

bitrate

Returns the bitrate in kilobits. Note that 128Kbps means 128000, and not 131072.

sample

Returns the sample rate in Hz.

seconds

Returns the length, in floating seconds, of the frame.

framerate

Should this frame describe the stream, the framerate would be the return value from this method.

broken

This would, had it been implemented, report wether or not the crc of the frame is valid. Since it's not documented thoroughly, and I don't know how to make my encoders add a sum to frames it doesn't. Patches would be greatly appreciated.

pad

Wether or not the frame was padded.

TIED HANDLE USAGE

You can also read frame objects via the <HANDLE> operator by tying a filehandle to this package in the following manner:

        tie 'MPEG::Audio::Frame',\*FH;
        while(<FH>){
                print "frame at ", $_->offset(), "\n";
        }

Way cool.

HISTORY

There is no history you need to know of.

He who controls the past controls the future. I'm a megalomaniac. Muahahaha.

AUTHOR

Yuval Kojman <nothingmuch@altern.org>

COPYRIGHT

        Copyright (c) 2003 Yuval Kojman. All rights reserved
        This program is free software; you can redistribute
        it and/or modify it under the same terms as Perl itself.