Skip to content
Advertisement

Trouble with converting webm into mp3 with pydub in python

so basically I want to convert song what I downloaded from youtube in webm and convert to into mp3

when I wanted export song just with song.export("neco.mp3") it didn’t work too

I have in workfolder ffmpeg.exe and ffprobe.exe

here is the code

from pydub import AudioSegment

song = AudioSegment.from_file(downloaded.webm,"webm")
print("Loaded")
song.export("neco.mp3", format="mp3", bitrate="320k")
print("Converted and saved")

here is the output of the console

Loaded
Traceback (most recent call last):
  File "e:/martan/projekty/Python/programek na pisnicky/songDownloader.py", line 188, in <module>
    song.export("neco.mp3", format="mp3", bitrate="320k")
  File "C:UsersBIBRAINAppDataLocalProgramsPythonPython38libsite-packagespydubaudio_segment.py", line 911, in export
    raise CouldntEncodeError(
pydub.exceptions.CouldntEncodeError: Encoding failed. ffmpeg/avlib returned error code: 1

Command:['ffmpeg', '-y', '-f', 'wav', '-i', 'C:\Users\BIBRAIN\AppData\Local\Temp\tmpo20ooz_z', '-b:a', '320k', '-f', 'mp3', 'C:\Users\BIBRAIN\AppData\Local\Temp\tmpiqpl57g7']

Output from ffmpeg/avlib:

ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 10.2.1 (GCC) 20200726
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, wav, from 'C:UsersBIBRAINAppDataLocalTemptmpo20ooz_z':
  Duration: 00:03:54.71, bitrate: 3072 kb/s
    Stream #0:0: Audio: pcm_s32le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s32, 3072 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (pcm_s32le (native) -> mp3 (mp3_mf))
Press [q] to stop, [?] for help
[mp3_mf @ 00000000004686c0] could not find any MFT for the given media type
[mp3_mf @ 00000000004686c0] could not create MFT
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

I think it is something with codec but I have no idea what to do

Advertisement

Answer

Had a similar problem with ffmpeg.exe (4.3.1),
but everything works fine with ffmpeg-20200802-b48397e-win64-static,
since mp3_mf is not used in the standard container there (WAV/MP3 in your problem, AVI in my problem).

So if you can’t switch to a different ffmpeg version,
you should force it to use libmp3lame, not just mp3
and the use of (System?)-codec mp3_mf :
So don’t use: -f mp3
Instead use (or add): -c:a libmp3lame

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement