Command line tool to identify audio file specs

12

3

I'm looking for an audio file equivalent to ImageMagick's identify command.

For example, with identify, I can get brief information about a bunch of images:

% identify b*
banner1.jpg JPEG 134x614 134x614+0+0 8-bit DirectClass 38.4kb 
banner.jpg[1] JPEG 772x307 772x307+0+0 8-bit DirectClass 37.5kb 
bg2.jpg[2] JPEG 103x1500 103x1500+0+0 8-bit DirectClass 43kb 
bg_control_nav.png[3] PNG 13x39 13x39+0+0 8-bit DirectClass 1.73kb 
bg_direction_nav.png[4] PNG 104x52 104x52+0+0 8-bit DirectClass 3.3kb 

I would like to get similar information about my audio files.

My eventual goal is to create a script to go through my whole mp3 library and identify those ripped at lower bitrates and then use that data to re-rip my CDs (or purchase better quality versions from Amazon or iTunes).

Solutions for OS X/Linux preferred to Windows solutions

Doug Harris

Posted 2012-06-21T14:26:13.397

Reputation: 23 578

Mediainfo is great and has a command line interface. – Marc.2377 – 2017-07-10T22:59:04.180

Interesting but a GUI app doesn't work for this need. – Doug Harris – 2017-07-12T21:07:59.277

And another one: MediaInfo

– slhck – 2012-06-21T18:46:19.203

Answers

10

On OS X you might just use mdls or mdfind.

$ mdls 01\ Kindred.mp3 
kMDItemAlbum                   = "Kindred EP"
kMDItemAudioBitRate            = 320000
kMDItemAudioChannelCount       = 2
kMDItemAudioSampleRate         = 44100
kMDItemAudioTrackNumber        = 1
kMDItemAuthors                 = (
    Burial
)
kMDItemComment                 = "HDB059"
kMDItemContentCreationDate     = 2012-03-19 21:20:59 +0000
kMDItemContentModificationDate = 2012-06-04 16:07:09 +0000
kMDItemContentType             = "public.mp3"
kMDItemContentTypeTree         = (
    "public.mp3",
    "public.audio",
    "public.audiovisual-content",
    "public.data",
    "public.item",
    "public.content"
)
kMDItemDateAdded               = 2012-04-02 19:49:07 +0000
kMDItemDisplayName             = "01 Kindred.mp3"
kMDItemDurationSeconds         = 686.08
kMDItemFSContentChangeDate     = 2012-06-04 16:07:09 +0000
kMDItemFSCreationDate          = 2012-03-19 21:20:59 +0000
kMDItemFSCreatorCode           = ""
kMDItemFSFinderFlags           = 0
kMDItemFSHasCustomIcon         = 0
kMDItemFSInvisible             = 0
kMDItemFSIsExtensionHidden     = 0
kMDItemFSIsStationery          = 0
kMDItemFSLabel                 = 0
kMDItemFSName                  = "01 Kindred.mp3"
kMDItemFSNodeCount             = 27457838
kMDItemFSOwnerGroupID          = 20
kMDItemFSOwnerUserID           = 501
kMDItemFSSize                  = 27457838
kMDItemFSTypeCode              = ""
kMDItemKind                    = "MP3 audio"
kMDItemLogicalSize             = 27457838
kMDItemMediaTypes              = (
    Sound
)
kMDItemMusicalGenre            = "Dubstep"
kMDItemPhysicalSize            = 27459584
kMDItemRecordingYear           = 2012
kMDItemTitle                   = "Kindred"
kMDItemTotalBitRate            = 320000

mdfind -onlyin ~/Music 'kMDItemFSName==*.mp3&&kMDItemAudioBitRate<=192000'

Lri

Posted 2012-06-21T14:26:13.397

Reputation: 34 501

2Upvotes for all answers so far, but this one gets the checkmark because (a) it's native to OS X and (b) uses existing spotlight metadata info and that mdfind command is crazy fast. – Doug Harris – 2012-06-21T17:35:25.023

Combining both and producing a list of album names with substandard bit rates: mdfind -0 -onlyin ~/Music 'kMDItemFSName==*.mp3&&kMDItemAudioBitRate<=192000'| xargs -0 mdls -name kMDItemAlbum | sort | uniq – Doug Harris – 2012-06-21T18:39:58.570

8

For easy to parse output, try ffprobe -show_format 2>/dev/null from FFmpeg.

On OS X, you can install it through Homebrew via brew install ffmpeg.

$ ffprobe *.mp3 -show_format 2>/dev/null
[FORMAT]
filename=02. Salvadoro Dali.mp3
nb_streams=2
format_name=mp3
format_long_name=MPEG audio layer 2/3
start_time=0.000000
duration=300.254667
size=7206112
bit_rate=191999
TAG:title=Salvadoro Dali
TAG:artist=Siela
TAG:track=2/10
TAG:album=Dali
TAG:date=2005
TAG:genre=Gothic rock
TAG:replaygain_album_peak=1.188815
TAG:replaygain_track_peak=1.178607
TAG:replaygain_track_gain=-9.00 dB
TAG:replaygain_album_gain=-9.12 dB
TAG:album_artist=Siela
[/FORMAT]

In a script:

find -iname '*.mp3' | while read -r file; do
    bitrate=$(ffprobe "$file" -show_format 2>/dev/null |
              awk -F"=" '$1 == "bit_rate" {print $2}')
    if (( bitrate <= 128000 )); then
        echo "[$bitrate] $file"
    fi
done

user1686

Posted 2012-06-21T14:26:13.397

Reputation: 283 655

5

EDIT: just found a Linux program

Under Linux, mp3info:

mp3info -p "%Q %L %v %o %r" test.mp3
output:
48000 III 1.000000 joint stereo

I know you want a Linux solution; however, by the way you stated your question, it sounds like a Windows solution is not completely out...

Under Windows, tag.exe will do the job.

Example:

C:\mp3>tag.exe "test.mp3"
Tag - Automatic Tag from filename
Copyright (c) 2002-2003 Case.  Minor additions by Neil Popham, 2004-2007
Version 2.0.52, Compiled 2007-05-04

C:\dl\test.mp3
Format:  MPEG 1 Layer 3, Joint Stereo
Details: 44100 Hz Stereo, 128 kbps, playtime 05:24
Tag:     ID3v2

To just get the bitrate:

C:\mp3>tag.exe "test.mp3" 2>&1 | findstr /i "Details:"
Details: 44100 Hz Stereo, 128 kbps, playtime 05:24

jftuga

Posted 2012-06-21T14:26:13.397

Reputation: 2 877

4

A very simple utility is sox
Mine was pre installed on the linux system.

 soxi auidofile.wav 

Output :

 Input File     : 'Yvette_Audin_F_70_7e.wav154.wav'
 Channels       : 2
 Sample Rate    : 44100
 Precision      : 24-bit
 Duration       : 00:00:10.01 = 441254 samples = 750.432 CDDA sectors
 File Size      : 2.65M
 Bit Rate       : 2.12M
 Sample Encoding: 24-bit Signed Integer PCM

something very useful about this was it allowed me to convert stereo 2-channel to mono channel. I needed it to train a machine learning model for audio files.

EDIT: Easier method converting 2 channel audio to mono signal:

 from pydub import AudioSegment  
 song = AudioSegment.from_wav("01.wav")
 song = song.set_channels(1)
 song.export("01.wav", format='wav')

Priyank Pathak

Posted 2012-06-21T14:26:13.397

Reputation: 41

Handles all sorts of files but not mp3! – not2qubit – 2018-03-07T12:35:41.603

.mp3 is can be easily converted to .wav, using online converters. Maybe matlab have some libraries to do so. Or your windows has a sound converter for the same. maybe factory format... – Priyank Pathak – 2018-03-07T17:42:53.767

Yeah, but that's not what the OP asked for. – not2qubit – 2018-03-09T15:09:08.747

possible will leave here for future help. – Priyank Pathak – 2018-03-10T15:43:40.443

1

mp3info was developed under Linux, but should work on most UN*X variants. ... MP3Info can also display various techincal aspects of an MP3 file including playing time, bit-rate, sampling frequency and other attributes in a pre-defined or user-specifiable output format.

or

MP3::Info - Manipulate / fetch info from MP3 audio files

Perhaps

  perl -MMP3::Info \
       -e 'print ($_, ": ",MP3::Info->new($_)->bitrate, "\n") for (@ARGV)' *.mp3

(untested)

RedGrittyBrick

Posted 2012-06-21T14:26:13.397

Reputation: 70 632

1

ffprobe is your friend (also you can use avconv, mplayer; all of them return media info, but ffprobe just returns the info you need)

With stream:

ffprobe http://96.127.183.74:8604/live

Returns

...
Stream #0:0: Audio: aac (HE-AACv2), 44100 Hz, stereo, fltp, 31 kb/s

With local file:

ffprobe some_file.mp3 

Returns

...
encoder         : LAME 64bits version 3.99.5
...
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 320 kb/s

aesede

Posted 2012-06-21T14:26:13.397

Reputation: 111