将 .m4a 文件转换为 .mp3 时出现此错误
I am getting this error while converting .m4a files to .mp3
我在如图所示运行脚本时遇到此错误
TEST.py
from pydub import AudioSegment
wav_audio = AudioSegment.from_file("Broken Summer.m4a", format="m4a")
wav_audio.export("audio1.mp3", format="mp3")
错误如下图
C:\Python\lib\site-packages\pydub\utils.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:\Python\lib\site-packages\pydub\utils.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:\Python\lib\site-packages\pydub\audio_segment.py", line 685, in from_file
info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
File "C:\Python\lib\site-packages\pydub\utils.py", line 274, in mediainfo_json
res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
File "C:\Python\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Python\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
运行前pip install ffmpeg
pip install ffmpeg-python
即使添加了 ffmpeg 的依赖项,也很可能无法读取文件。由于 pydub 不读取 .m4a 文件。主要是因为 'ffmpeg' 不通过 'libav' 库支持这种类型的文件。
我也有这个问题。
我得到了解决方案。
如果你已经安装了ffmpeg或者ffmpeg-python。卸载它。因为它不会工作
运行 这个命令
pip uninstall ffmpeg
pip uninstall ffmpeg-python
现在转到这个linkhttps://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
我在如图所示运行脚本时遇到此错误
TEST.py
from pydub import AudioSegment
wav_audio = AudioSegment.from_file("Broken Summer.m4a", format="m4a")
wav_audio.export("audio1.mp3", format="mp3")
错误如下图
C:\Python\lib\site-packages\pydub\utils.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:\Python\lib\site-packages\pydub\utils.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:\Python\lib\site-packages\pydub\audio_segment.py", line 685, in from_file
info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
File "C:\Python\lib\site-packages\pydub\utils.py", line 274, in mediainfo_json
res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
File "C:\Python\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Python\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
运行前pip install ffmpeg
pip install ffmpeg-python
即使添加了 ffmpeg 的依赖项,也很可能无法读取文件。由于 pydub 不读取 .m4a 文件。主要是因为 'ffmpeg' 不通过 'libav' 库支持这种类型的文件。
我也有这个问题。
我得到了解决方案。 如果你已经安装了ffmpeg或者ffmpeg-python。卸载它。因为它不会工作 运行 这个命令
pip uninstall ffmpeg
pip uninstall ffmpeg-python
现在转到这个linkhttps://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