【发布时间】:2017-08-13 16:07:15
【问题描述】:
我正在尝试使用库 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
用os.path.join(folder, file) 替换folder + file 也不起作用
【问题讨论】:
-
上一行正确加入时,为什么还要连接?
-
您能粘贴完整的堆栈跟踪吗?
-
您似乎没有正确安装 ffmpeg。
FileNotFound错误不是针对您要转换的音频文件,而是针对 pydub 试图通过subprocess.Popen调用的外部工具。 -
做一件事,把最后一条语句分成两部分,找出错误的根源!像 z= AudioSegment.from_file(folder + file) 然后在新行中 z.export(folder + file, format="mp3") 然后找出究竟是哪一行导致了这个错误?
-
我不知道,您应该尝试自己调试(或分析)pydub/audio_segment.py 并尝试寻找运气,或者尝试在没有此操作系统的情况下单独运行此音频片段命令.file junk 试试该命令是否单独工作?
标签: python-3.x operating-system