我尝试使用libary pydub将文件夹中的每个文件从mp4转换为mp3但是当我这样做时会返回错误FileNotFoundError: [WinError 2] The system cannot find the file specified
。我不确定我如何能更具体地了解该文件。
这是我的代码:
from pydub import AudioSegment
import os
import os.path
folder = 'C:/Users/Magnus/Desktop/test/'
videos = []
for file in [f for f in os.listdir(folder) \
if os.path.isfile(os.path.join(folder, f))]:
AudioSegment.from_file(folder + file).export(folder + file, format="mp3")
C:/Users/Magnus/Desktop/test/
内部我的文件看起来像M83_-_Bibi_The_Dog_(Audio).mp4
完整追溯:
Traceback (most recent call last):
File "C:\Users\Magnus\Desktop\youtube-playlist-downloader.py", line 64, in <module>
AudioSegment.from_file(os.path.join(folder, file)).export(os.path.join(folder, file), format="mp3")
File "C:\Users\Magnus\AppData\Local\Programs\Python\Python35\lib\site-packages\pydub\audio_segment.py", line 505, in from_file
p = subprocess.Popen(conversion_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "C:\Users\Magnus\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Users\Magnus\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
同时将folder + file
替换为os.path.join(folder, file)
也无法正常工作
答案 0 :(得分:0)
我有类似的错误。我正在使用anaconda。
此错误看起来不像文件错误,但由于:
未安装ffmpeg。 (或)
ffmpeg没有被添加到环境变量中。(连同FFmpeg甚至你的python.exe和conda.exe都应该在env变量中)
执行以下步骤:
在Windows上:
您可以将其用作参考:https://github.com/jiaaro/pydub