Error when exporting with pydub - how to install mp3 codecs for pydub?

3.2k views Asked by At

Im using this library for first time so Im not sure if this is a bug or Im not correctly doing something.

I want to export a file into mp3, the loading works perfectly:

wav=AudioSegment.from_wav(Path)  #If I execute only this line, there are no errors.

But when I try to export my file to mp3:

wav.export(r"WavOut.mp3",format="mp3")

It throws the following error:

WindowsError: [Error 2] The system cannot find the file specified

Full error report: http://pastebin.com/3CpZBkEK

I believe I am using the correct syntax. It creates the mp3 output file but absolutely empty, and the imput path is correct since:

os.startfile(Path) #Will work

Also, I registered ffmpeg, in windows path as:

;c:\ffmpeg\bin   #It is currently callable from any cmd prompt in windows.

What can be failing? Thanks!


After more testing, I found out its an encoding problem. If I set the output as "wav" it works. But I dont really know how should I install an mp3 encoder for it to work with pydub, so I changed the question to ask that, since its the real problem. ffmpeg is installed so I dont know what else to do :\

1

There are 1 answers

1
Jiaaro On BEST ANSWER

I think it's unable to find the ffmpeg binary. Python has wave support built in, so pydub doesn't require ffmpeg to open/close/modify wave files.

Try assigning the location of the ffmpeg binary before you use it like so:

from pydub import AudioSegment
AudioSegment.converter = "c:\ffmpeg\bin\ffmpeg.exe"

wav = AudioSegment.from_wav(Path)  #If I execute only this line, there are no errors.
wav.export(r"WavOut.mp3",format="mp3")

edit: We've change changed the name of the property from AudioSegment.ffmpeg to AudioSegment.converter because we now support both ffmpeg and avconv.

Please check which your version uses before assigning to this property (it's "converter" starting in the 0.9.0 release)