我在运行如所示的脚本时遇到此错误
测试
from pydub import AudioSegment
wav_audio = AudioSegment.from_file("Broken Summer.m4a", format="m4a")
wav_audio.export("audio1.mp3", format="mp3")
错误如下所示
C:Pythonlibsite-packagespydubutils.py:170: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)
C:Pythonlibsite-packagespydubutils.py:198: RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
Traceback (most recent call last):
File "C:/Users/karti/Documents/Python Programs/ChatApplication/deezer.py", line 13, in <module>
wav_audio = AudioSegment.from_file("Broken Summer.m4a", format="m4a")
File "C:Pythonlibsite-packagespydubaudio_segment.py", line 685, in from_file
info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
File "C:Pythonlibsite-packagespydubutils.py", line 274, in mediainfo_json
res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
File "C:Pythonlibsubprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:Pythonlibsubprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
即使添加了ffmpeg的依赖项,文件也很可能无法读取。由于pydub不读取.m4a文件。主要是因为"ffmpeg"不支持通过"libav"库的这种类型的文件。
我在这方面也遇到了麻烦。
pip在操作前安装ffmpeg。
pip install ffmpeg-python
我得到了解决方案。如果您已经安装了ffmpeg或ffmpeg-python。卸载它。因为它不起作用运行此命令
pip uninstall ffmpeg
pip uninstall ffmpeg-python
现在转到此链接https://ffmpeg.org/download.html
从这里下载ffmpeg并将其安装在C:\ffmpeg中然后转到"环境变量",在"路径"中添加一个新路径,名称为-C:\ffmpeg\bin由于此路径包含ffmpeg.exe就是
现在假设您有TEST.m4a文件,要将其转换为TEST.mp3只需复制并粘贴文件名,然后运行以下脚本。注意:bewlo.py文件应该与TEST.m4a在同一目录中,否则您需要在"CurrentFileName"变量中添加正确的路径现在只需创建一个.py文件并粘贴此代码
import subprocess
CurrentFileName = 'TEST.m4a'
FinalFileName = 'TEST.mp3'
try:
subprocess.call(['ffmpeg', '-i', f'{CurrentFileName}', f'{FinalFileName}'])
except Exception as e:
print(e)
print('Error While Converting Audio')
ch = input('Press Enter to Close')
这完全符合我的要求。:(如果我的答案不清楚,请在这里告诉我,或者你可以给我发邮件-kartikeyvaish99@gmail.com