MPAInfo - MPEG Audio Information

Build Status

This Ruby gem parses MPEG Audio (MP2 / MP3) headers in order to get information about the audio bitstream. This includes:

  • Bitrate
  • Samplerate
  • MPEG Audio Version and Layer
  • Number of samples
  • Duration
  • The Copyright/Original flags


Add this line to your application's Gemfile:

gem 'mpainfo'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mpainfo


Use the MPAInfo::Header class to parse a 4-byte MPEG Audio header:

require 'mpainfo''testcase.mp3', 'rb') do |file|
  data =
  header =
  puts "Bitrate: #{header.bitrate} kbps"
  puts "Samplerate: #{header.samplerate} Hz"

  # Or display a short summary:
  puts header.to_s


After checking out the repo, run bundle exec bundle install to install the development dependencies. Then, run rake test to run the tests.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at


The gem is available as open source under the terms of the MIT License.