jiaaro / pydub

Manipulate audio with a simple and easy high level interface
http://pydub.com
MIT License
8.57k stars 1.02k forks source link

form mp3 to amr Error #371

Open 872822645 opened 5 years ago

872822645 commented 5 years ago

from pydub import AudioSegment def trans_mp3_to_wav(filepath): song = AudioSegment.from_mp3(filepath) song.export(out_f="haha.amr",format="amr") trans_mp3_to_wav("haha.mp3")

haha.zip

the wrong infomation : Traceback (most recent call last): File "C:/Users/sunlei/PycharmProjects/DemoExcel/DemoMp3.py", line 13, in trans_mp3_to_wav("haha.mp3") File "C:/Users/sunlei/PycharmProjects/DemoExcel/DemoMp3.py", line 12, in trans_mp3_to_wav song.export(out_f="haha.amr",format="amr") File "C:\Python\lib\site-packages\pydub\audio_segment.py", line 877, in export p.returncode, conversion_command, p_err)) pydub.exceptions.CouldntEncodeError: Encoding failed. ffmpeg/avlib returned error code: 1

Command:['ffmpeg', '-y', '-f', 'wav', '-i', 'C:\Users\sunlei\AppData\Local\Temp\tmpitp4bywb', '-f', 'amr', 'C:\Users\sunlei\AppData\Local\Temp\tmpzwoxp96t']

Output from ffmpeg/avlib:

b"ffmpeg version N-93431-g6dc1da416e Copyright (c) 2000-2019 the FFmpeg developers\r\n built with gcc 8.2.1 (GCC) 20190212\r\n 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-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-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt\r\n libavutil 56. 26.100 / 56. 26.100\r\n libavcodec 58. 47.105 / 58. 47.105\r\n libavformat 58. 26.101 / 58. 26.101\r\n libavdevice 58. 7.100 / 58. 7.100\r\n libavfilter 7. 48.100 / 7. 48.100\r\n libswscale 5. 4.100 / 5. 4.100\r\n libswresample 3. 4.100 / 3. 4.100\r\n libpostproc 55. 4.100 / 55. 4.100\r\nGuessed Channel Layout for Input Stream #0.0 : mono\r\nInput #0, wav, from 'C:\Users\sunlei\AppData\Local\Temp\tmpitp4bywb':\r\n Duration: 00:00:01.80, bitrate: 256 kb/s\r\n Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 Hz, mono, s16, 256 kb/s\r\nStream mapping:\r\n Stream #0:0 -> #0:0 (pcm_s16le (native) -> amr_nb (libopencore_amrnb))\r\nPress [q] to stop, [?] for help\r\n[libopencore_amrnb @ 000001a7cc77ef80] Only 8000Hz sample rate supported\r\nError 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\r\nConversion failed!\r\n"

sarveshgupta67890 commented 4 years ago

uninstall it and again install ffmpeg and pydub I also got the issue solved like that

GreyAlien502 commented 4 years ago

The relevant error output is the "Only 8000Hz sample rate supported" part. This is because amr files can only store 8000Hz audio, but your song file is at a different sample rate. This can be solved by converting your sample to 8000Hz before exporting as follows: song.set_frame_rate(8000).export(out_f="haha.amr",format="amr")