在 python 中使用 pydub 将 webm 转换为 mp3 时遇到问题
Trouble with converting webm into mp3 with pydub in python
所以基本上我想在 webm 中转换我从 youtube 下载的歌曲并转换成 mp3
当我想用 song.export("neco.mp3")
导出歌曲时,它也不起作用
我在工作文件夹中有 ffmpeg.exe 和 ffprobe.exe
这是代码
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")
这里是控制台的输出
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:\Users\BIBRAIN\AppData\Local\Programs\Python\Python38\lib\site-packages\pydub\audio_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:\Users\BIBRAIN\AppData\Local\Temp\tmpo20ooz_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!
我认为这是编解码器的问题,但我不知道该怎么做
与 ffmpeg.exe (4.3.1)、
有类似的问题
但是 ffmpeg-20200802-b48397e-win64-static 一切正常,
因为那里的标准容器中没有使用 mp3_mf
(WAV/MP3 在你的问题中,AVI 在我的问题中)。
所以如果你不能切换到不同的 ffmpeg 版本,
你应该强制它使用 libmp3lame,而不仅仅是 mp3
以及 (System?)-codec mp3_mf :
的使用
所以不要使用:-f mp3
而是使用(或添加):-c:a libmp3lame
所以基本上我想在 webm 中转换我从 youtube 下载的歌曲并转换成 mp3
当我想用 song.export("neco.mp3")
导出歌曲时,它也不起作用
我在工作文件夹中有 ffmpeg.exe 和 ffprobe.exe
这是代码
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")
这里是控制台的输出
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:\Users\BIBRAIN\AppData\Local\Programs\Python\Python38\lib\site-packages\pydub\audio_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:\Users\BIBRAIN\AppData\Local\Temp\tmpo20ooz_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!
我认为这是编解码器的问题,但我不知道该怎么做
与 ffmpeg.exe (4.3.1)、
有类似的问题
但是 ffmpeg-20200802-b48397e-win64-static 一切正常,
因为那里的标准容器中没有使用 mp3_mf
(WAV/MP3 在你的问题中,AVI 在我的问题中)。
所以如果你不能切换到不同的 ffmpeg 版本,
你应该强制它使用 libmp3lame,而不仅仅是 mp3
以及 (System?)-codec mp3_mf :
的使用
所以不要使用:-f mp3
而是使用(或添加):-c:a libmp3lame