File Exchange

image thumbnail

mp3read and mp3write

version (2.13 MB) by Dan Ellis
Improved reading and writing of mp3 files


Updated 21 Apr 2010

View License

These versions of mp3read and mp3write are direct drop-in replacements for wavread and wavwrite to access MPEG audio mp3 files. Features include:
- aims to duplicate complete syntax of wavread and wavwrite
- also supports on-the-fly downsampling and channel merging of mpg123
- optimized for very long mp3 files - only decodes the needed portion
- uses popen for encoding to avoid a large temporary file (when available - see my popenw mex)
- attempts to preserve time alignment of files through read/write loop by removing "warm up" samples
- package includes helper binaries for Linux, Windows, Mac-PPC, Mac-Intel, and Mac-Intel-64bit

Cite As

Dan Ellis (2020). mp3read and mp3write (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (40)

Deyan Dobromirov

Could you please replace `findstr` with `strfind`. It gives out warnings that it deprecated.





i get the same problem as Onno reported with mac 10.6.8 and Version R2011a, although permissions are correct.

I am thinking: Maybe there is an issue with the options of the system command which are passed with the cmd argument at line 371 of the mp3read.m, because they are not permitted to be run from other than internal programs?

If anybody has an idea, please share! I am gonna try it under windows us well to see if the same comes up...

Best regards,


...continuation: line 371 of the mp3read.m and the command "cmd" delivers all the options) cause the problem, because they are not permitted to be run from other than internal programs?

If anybody has an idea, please share! I am gonna try it under windows us well to see if the same comes up...




I am using Mac and Matlab 2012b. The code seems to work however I get the error message:

unable to execute (..) /mp3readwrite/mp3info.maci64" -r m -p "%Q %u %b %r
%v * %C %e %E %L %O %o %p" "sound.mp3" (/bin/bash: (...)/mp3readwrite/mp3info.maci64: Permission denied)

If i look at the permissions for this (mp3info.maci64) file then I see that I can read and write. Anyone any idea how to solve this?


its good






Really useful... i've used it in my project... Thanks to u and of course to "Luigi Rosa" < >


Thank you, I very much need this


Regarding the error with mysystem(cmd):
The cmd variable defines how the mp3info/mpg123 is called on your machine. I got the mp3read working by changing the corresponding lines (somewhere around line 180 and 312 in the code) to:

cmd = ['mp3info -r m -p "%Q %u %b %r %v * %C %e %E %L %O %o %p" "', FILE,'"'];
cmd=['mpg123', downsampstr, chansstr, skipstr, lenstr,' -q -w "', tmpfile,'" "',FILE,'"'];

This should work if you installed the mp3info/mpg123 normally and I expect the mp3write can be fixed in a similar manner.

(Sidenote: Sorry for the low ratings, apparently I'm really bad at clicking textboxes on a trackpad.)




I am getting a similar to the error described above I m using 64 bit Ubuntu and trying to execute mp3read but it gives me this error :-

??? Error using ==> mp3read>mysystem at 373
unable to execute "/home/ajayram/Documents/MusicWork/Codes/mp3info.glnxa64" -r
m -p "%Q %u %b %r %v * %C %e %E %L %O %o %p" "test.mp3"
(/bin/bash: /home/ajayram/Documents/MusicWork/Codes/mp3info.glnxa64: No such
file or directory

Error in ==> mp3read at 188
w = mysystem(cmd);


I have no clue as to how to get around this issue.


I'm using this on a 65-bit Ubuntu (10.04.4 LTS) and I keep on getting the following error when I run the demo file:
??? Error using ==> mp3write>mysystem at 168
unable to execute
--quiet -h "/tmp/tmp632.wav" "piano.mp3"
No such file or directory

Error in ==> mp3write at 156

Error in ==> demo_mp3readwrite at 45

I'm certain that this is because I'm missing the lame.glnxa64 file for 64 bit version.

PLEASE HELP ME!! It is much appreciated.

sunil chhipa

sunil chhipa

great work............

bei liu

It's good,bur I dont know hwo to use it.


Thank you

Jesse van Muijden

works fine with Matlab 7.10.0 (R2010a) on Windows XP Pro SP3. Thank you!

Mr Smart

Ilaria Milesi


I got 'Out of Memory' error. Please advice me. Thanks.


and I got this error with mp3read

>> mp3read([mp3_list(i).name])
??? Error using ==> mp3read>mysystem at 373
unable to execute "C:\Documents and Settings\mfiles\mp3readwrite\mpg123.exe" -q -w "\tmp\tmp127.wav"
"DJ.mp3" ()

Error in ==> mp3read at 330

brigitte audrey

very good stuff. thanks for sharing

Gökhan Vural

It works very nice overally. However, it gives ".mp3 is corrupt or is not a standard MP3 file." error for some songs. Indeed, files're not corrupt.
Does anybody know the reason of it ?

T myself

Great tool! Works nice. Thank you.

Jorge Moragues

As Mahocan said, the corresponding 'SIZ' command does not work properly and it returns a wrong number of samples of the file.

Has anybody solved this problem?



I can recommend this program! IT worked very good. Thanks

loch zeng

This is a good tools

Aaron Clarke

I tried it and it worked great right away. Nice program!

suraj prakash

its cool.

Jose Uy

It doesn't seem to work with mp3's downloaded from itunes. Does the AAC encoding have anything to do with this?

hrushikesh kulkarni

great i am very thankful to you

Mahocan Ganemur

Good job!

Mahocan Ganemur


Thanks for building such a useful tool. I just tried the command "SIZ = MP3READ(FILE,'size')" on MATLAB. The resulting "total number of audio samples" value given by the command is not correct. For example in the file that I test, there are 237 931 198 total audio samples, while the command has given the result as 193 625 280. I tried on another mp3 file that is relatiely small. The correct size of this file is 41 133 311, while the command has given as 40 912 128. I cannot get the correct value of the total number of audio samples in the mp3 file with this command. Any suggestions on this issue? Thanks in advance.

Daryush Mehta

Forgot to mention that in my setup (WinXP SP2, Matlab 2006b), the default bit rate for mp3write turns out to be 64 kbps, not 128 kbps that's mentioned in the help file.

Daryush Mehta

Works great! Commenting in the code helps the reader well. I am running Windows XP SP2 and Matlab 7.3.0 (R2006b).

As Dan Ellis notes on his website <>, two functions are available to prevent Lame from having to access a large temporary file; instead, a "pipeline" is open to the lame codec. I was able to compile Dan Ellis' popenw.c and popenr.c files ('mex popenw.c' and 'mex popenr.c' at Matlab command prompt) to give platform-specific mex files. But, when I ran the mp3write code, no error was given and no mp3 file was created. If anyone can get this functionality working, please share it!

Also, definitely read the mp3write help file to note that you can specify the bit rate by changing the last integer in
mp3write(x,fs,'filename','--quiet -h -b 128');'

Should prove to be very useful. Thanks for writing them.


- updated binaries for maci64 (static link) and windows (http works)
- expands '~' in file names
- returns correct SR when reading over http:

Updated to use and include more recent versions of mpg123 and lame. I've done my best to fix inconsistencies with the 'size' return, but for some MP3s this relies on header info I can't probe.

This version enables the ability of mpg123 to read mp3 files from URLs.

- updated interaction of sample limits and predelay compensation in mp3read to make it more consistent
- increased buffer to provide more tolerance of bad blocks in stream

- fix to writing stereo files on Windows
- mp3read(...,'size') now more accurate (but not perfect owing to limitations in mp3info)
- various cleanups to reduce mlint errors

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux