Mp3Info

The fastest PHP library to extract mp3 meta information (duration, bitrate, samplerate and so on) and tags (id3v1, id3v2).

View on GitHub

Mp3Info

The fastest PHP library to get mp3 tags&meta.

Latest Stable Version Total Downloads Latest Unstable Version License

This class extracts information from mpeg/mp3 audio:

tag id3v1 id3v2
song song TIT2
artist artist TPE1
album album TALB
year year TYER
comment comment COMM
track track TRCK
genre genre TCON

Content

  1. Usage
  2. Performance
  3. Console scanner
  4. API
    • Audio information
    • Class methods
    • Settings
  5. Technical information

Usage

After creating an instance of Mp3Info with passing filename as the first argument to the constructor, you can retrieve data from object properties (listed below).

use wapmorgan\Mp3Info\Mp3Info;
// To get basic audio information
$audio = new Mp3Info('./audio.mp3');

// If you need parse tags, you should set 2nd argument this way:
$audio = new Mp3Info('./audio.mp3', true);

And after that access object properties to get audio information:

echo 'Audio duration: '.floor($audio->duration / 60).' min '.floor($audio->duration % 60).' sec'.PHP_EOL;
echo 'Audio bitrate: '.($audio->bitRate / 1000).' kb/s'.PHP_EOL;
// and so on ...

To access id3v1 tags use $tags1 property. To access id3v2 tags use $tags2 property. Also, you can use combined list of tags $tags, where id3v2 and id3v1 tags united with id3v1 keys.

// simple id3v1 tags
echo 'Song '.$audio->tags1['song'].' from '.$audio->tags1['artist'].PHP_EOL;
// specific id3v2 tags
echo 'Song '.$audio->tags2['TIT2'].' from '.$audio->tags2['TPE1'].PHP_EOL;

// combined tags (simplies way to get as more information as possible)
echo 'Song '.$audio->tags['song'].' from '.$audio->tags['artist'].PHP_EOL;

Performance

Console scanner

To test Mp3Info you can use built-in script that scans dirs and analyzes all mp3-files inside them. To launch script against current folder:

php bin/scan ./

API

Audio information

Property Description Values
$codecVersion MPEG codec version 1 or 2
$layerVersion Audio layer version 1 or 2 or 3
$audioSize Audio size in bytes. Note that this value is NOT equals file size. int
$duration Audio duration in seconds.microseconds like 3603.0171428571 (means 1 hour and 3 sec)
$bitRate Audio bit rate in bps like 128000 (means 128kb/s)
$sampleRate Audio sample rate in Hz like 44100 (means 44.1KHz)
$isVbr Contains true if audio has variable bit rate boolean
$hasCover Contains true if audio has a bundled image boolean
$channel Channel mode 'stereo' or 'dual_mono' or 'joint_stereo' or 'mono'
$tags1 Audio tags ver. 1 (aka id3v1). [“song” => “Song name”, “year” => 2009]
$tags2 Audio tags ver. 2 (aka id3v2), only text ones. [“TIT2” => “Long song name”, …]
$tags Combined audio tags (from id3v1 & id3v2). Keys as in tags1. [“song” => “Long song name”, “year” => 2009, …]
$coverProperties Information about a bundled with audio image. [“mime_type” => “image/jpeg”, “picture_type” => 1, …]
$_parsingTime Contains time spent to read&extract audio information in sec.msec  

Class methods

Settings

You can adjust some variables to reconfigure before instantiating of object:

Technical information

Supporting features:

Used sources: