Perl script to parse MPEG audio header

I’ve written a Perl script which will parse MPEG audio headers and display them in a human-readable format.

For example, if you run it on ding.mpeg (download from GitHub) you get this output:

>perl mpegaudioheader.pl ding.mpeg
Frame header: 11111111 111 (should be all ones)
MPEG Audio version ID: 11 (MPEG version 1 (ISO/IEC 11172-3))
Layer description: 10 (layer II)
Protection bit: 0 (protected by CRC (16-bit CRC follows header))
Bitrate index: 1011 (224 kbps)
Sample rate index: 00 (44100 Hz)
Padding bit: 0 (frame is not padded)
Private bit: 0 (application specific)
Channel mode: 00 (stereo)
Mode extension (if channel mode is joint stereo:) 00 (bands 4 to 31)
Copyright: 0 (audio is not copyrighted)
Original: 0 (copy of original media)
Emphasis: 00 (none)

Here’s the source for the Perl script on GitHub

Note this script assumes that the very first bytes of the file are the MPEG audio header, and makes no effort to dig into the file to find the audio header.

EDIT 2015-10-31: moved script to https://github.com/mvaneerde/blog/blob/master/scripts/mpegaudioheader.pl

One thought on “Perl script to parse MPEG audio header

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s