42

What is the terminal command that can used to find the bitrate of an mp3 file?

Is there any other option available other than mpg321 -t name.mp3?

devav2
  • 35,738
  • 17
  • 79
  • 82

5 Answers5

50

MediaInfo is further solution to do that (not only on mp3).

sudo apt-get install mediainfo

Example:

mediainfo Aphrodite_-_Superman_\(dnb\).mp3 | grep "Bit rate"

Output:

Bit rate mode                            : Constant
Bit rate                                 : 192 Kbps

Another Example:

mediainfo Aphrodite_-_Superman_\(dnb\).mp3 | grep 'Bit rate  '

Another Output:

Bit rate                                 : 192 Kbps

Get exactly the audio bitrate via mediainfo in bps:

mediainfo --Output='Audio;%BitRate%' '/MY/MEDIA/FILE.MP3'

or in Kbps:

mediainfo --Output='Audio;%BitRate/String%' '/MY/MEDIA/FILE.MP3'
muru
  • 193,181
  • 53
  • 473
  • 722
BuZZ-dEE
  • 13,993
  • 18
  • 63
  • 80
  • 1
    You could just specify `--Output=JSON` to get the output formatted as JSON. This is useful if you're using `mediainfo` inside another app. – Chris Aug 20 '19 at 13:52
43

Simply put:

file song.mp3

Note: file is included with Ubuntu.


For alias lovers, insert this at the end of your ~/.bashrc file:

bitrate () {
    echo `basename "$1"`: `file "$1" | sed 's/.*, \(.*\)kbps.*/\1/' | tr -d " " ` kbps
}

Open a new Terminal window. You may now run the following command:

bitrate song.mp3
SirCharlo
  • 39,016
  • 10
  • 75
  • 82
  • 2
    wow. Simple `file` command did the trick. – devav2 Oct 05 '12 at 19:32
  • 13
    Be warned: if the file is variable bit rate (VBR), file will report only the one of the many bit rates present. (I think it's the first frame's bit rate.) The answer could be deceptive if most of the file is at a very different rate. If you want to know the average bit rate, see apacheuk's answer. – Alan De Smet Feb 05 '14 at 04:44
  • +1 Any chance you could add a brief summary to this answer, explaining how it works? – voices Dec 21 '15 at 22:40
  • 2
    For some reason `file` doesn't work with a whole lot of MP3s I have which are properly identified by `exiftool` and even better by `mediainfo`. – jamadagni Mar 27 '16 at 10:10
  • Doesn't work for most of my files on Ubuntu 16.04. As stated above, I'm pretty sure its due to file not understanding VBR files correctly. "file" just says "Audio file with ID3 version 2.3.0" – slacy Oct 04 '16 at 21:33
28

Install mp3info package

sudo apt-get install mp3info

To find the bitrate use

mp3info -r a -p "%f %r\n" *.mp3 

will give the info you need, also has some other useful functions man mp3info for more info

devav2
  • 35,738
  • 17
  • 79
  • 82
apacheuk
  • 928
  • 5
  • 9
  • 1
    mp3info does not support ID3v2 tagging. – Ian Sep 13 '13 at 17:15
  • 2
    @Ian: true as that may be, it's irrelevant to this question or this answer. – Johann Jun 24 '15 at 05:14
  • 1
    If you are curious about the bit rate alone, then yes -- it's irrelevant. If you found this answer because you were working on a script that needed the bitrate in addition to other fields from your mp3 files (some of which only have ID3v2 tags) then this information would prevent you from going down a dead end with `mp3info` -- a program that does not always extract info from mp3s. – Ian Jun 24 '15 at 12:31
12

You can install the package libimage-exiftool-perl:

sudo apt-get install libimage-exiftool-perl

Then run:

exiftool -AudioBitrate GoldLion.mp3

It will output something like:

Audio Bitrate : 192 kbps
SirCharlo
  • 39,016
  • 10
  • 75
  • 82
carey
  • 151
  • 3
11

The best info, by-far, is provided by ffprobe (part of the ffmpeg package). mpg123 is also nice, but hard to grep output, which is probably why you were asking for something else.

$ mpg123 -t example.mp3 2>&1 | grep -A1 -E "^MPEG"
MPEG 2.5 L III cbr32 11025 mono

$ ffprobe example.mp3 2>&1 | grep Stream
    Stream #0:0: Audio: mp3, 11025 Hz, mono, s16p, 32 kb/s

For pro-use, do this:

# ffprobe -v quiet -print_format json -show_format -show_streams example.mp3

{
    "streams": [
        {
            "index": 0,
            "codec_name": "mp3",
            "codec_long_name": "MP3 (MPEG audio layer 3)",
            "codec_type": "audio",
            "codec_time_base": "1/11025",
            "codec_tag_string": "[0][0][0][0]",
            "codec_tag": "0x0000",
            "sample_fmt": "s16p",
            "sample_rate": "11025",
            "channels": 1,
            "channel_layout": "mono",
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/14112000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 55294344,
            "duration": "3.918250",
            "bit_rate": "32000",
            "disposition": {
                "default": 0,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0,
                "timed_thumbnails": 0
            }
        }
    ],
    "format": {
        "filename": "example.mp3",
        "nb_streams": 1,
        "nb_programs": 0,
        "format_name": "mp3",
        "format_long_name": "MP2/3 (MPEG audio layer 2/3)",
        "start_time": "0.000000",
        "duration": "3.918250",
        "size": "17260",
        "bit_rate": "35240",
        "probe_score": 51,
        "tags": {
            "title": "Sound Effects - Female Operatic La 1 - Opera singer sings La.",
            "artist": "Download Sound Effects - SoundDogs - AOS",
            "album": "http://www.Sounddogs.com",
            "track": "0",
            "copyright": "(c) 2010 Sounddogs.com, All Rights Reserved",
            "genre": "SFX - Humans; Vocalizations",
            "comment": "Royalty Free Sound Effects - Sounddogs.com",
            "date": "2008"
        }
    }
}
not2qubit
  • 606
  • 8
  • 14