Reputation: 86600
I'm trying to export a file as mp3 in pydub, but I get this error:
Automatic encoder selection failed for output stream #0:0. Default encoder for format mp3 is probably disabled. Please choose an encoder manually
How do I select an encoder manually, what is the default encoder, and how could I enable it?
PS: My Pydub opens mp3 files without any problem. I'm using Windows and Libav.
Upvotes: 6
Views: 11328
Reputation: 31
I had the same problem as Emiel, where the ffmpeg
version available in Anaconda did have an mp3 encoder. I solved the problem another way, by installing this version of ffmpeg
from the conda-forge
channel. I used:
conda install -n <anaconda-env> -c conda-forge ffmpeg
Now using ffmpeg -codecs | grep mp3
the mp3 encoders show up:
DEA.L. mp3 MP3 (MPEG audio layer 3) (decoders: mp3float mp3 ) (encoders: libmp3lame libshine )
Upvotes: 3
Reputation: 388
The other solution did not work for me. The problem for me was that the ffmpeg
version that came installed with Anaconda did not seem to be compiled with an encoder. So instead of:
DEA.L. mp3 MP3 (MPEG audio layer 3) (decoders: mp3 mp3float mp3_at ) (encoders: libmp3lame )
I saw:
DEA.L. mp3 MP3 (MPEG audio layer 3) (decoders: mp3 mp3float mp3_at )
Without the (encoders: ...)
part.
My solution was to do this:
ffmpeg -codecs | grep mp3
, to check if there is any encoder (there isn't!).conda uninstall ffmpeg
brew install ffmpeg --with-libmp3lame
ffmpeg -codecs | grep mp3
, to check if there is any encoder (now there is!).Upvotes: 7
Reputation: 76898
you can find which codecs are available with ffmpeg -codecs
or avconv -codecs
and on the line with mp3
you'll see something like:
DEA.L. mp3 MP3 (MPEG audio layer 3) (decoders: mp3 mp3float mp3_at ) (encoders: libmp3lame )
D
means ffmpeg can decode
E
means it can encode
A
means it's an audio codec
L
means it's a lossy encoding
but the most important part is the encoders: …
portion
I think you'll need to pick one of the encoders listed and tell pydub to use it (I'm not sure why, this isn't required on my machine - but it probably depends on your ffmpeg installation)
from pydub import AudioSegment
sound = AudioSegment.from_file(…)
sound.export("/path/to/output.mp3", codec="libmp3lame")
Upvotes: 3