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

Installation

Add this line to your application's Gemfile:

gem 'mpainfo'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mpainfo

Usage

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

require 'mpainfo'

File.open('testcase.mp3', 'rb') do |file|
  data = file.read(4)
  header = MPAInfo::Header.new(data)
  puts "Bitrate: #{header.bitrate} kbps"
  puts "Samplerate: #{header.samplerate} Hz"

  # Or display a short summary:
  puts header.to_s
end

Development

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 rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/njh/ruby-mpainfo.

License

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