gol*_*die 9 python selenium ffmpeg ffprobe pydub
我正在研究验证码解算器,我需要使用 ffmpeg,尽管没有任何效果。Windows 10 用户。
第一次运行代码时警告:
C:\Users\user\AppData\Roaming\Python\Python310\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)
Run Code Online (Sandbox Code Playgroud)
然后,当我尝试运行该脚本并且它需要 ffprobe 时,出现以下错误:
C:\Users\user\AppData\Roaming\Python\Python310\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 "D:\Scripts\captcha\main.py", line 164, in <module>
main()
File "D:\Scripts\captcha\main.py", line 155, in main
captchaSolver()
File "D:\Scripts\captcha\main.py", line 106, in captchaSolver
sound = pydub.AudioSegment.from_mp3(
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\pydub\audio_segment.py", line 796, in from_mp3
return cls.from_file(file, 'mp3', parameters=parameters)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\pydub\audio_segment.py", line 728, in from_file
info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\pydub\utils.py", line 274, in mediainfo_json
res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
File "C:\Program Files\Python310\lib\subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files\Python310\lib\subprocess.py", line 1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)
我尝试正常下载它,编辑环境变量,将它们粘贴到与脚本相同的文件夹中,使用 pip 安装,手动测试 ffmpeg 以查看它是否有效,并且确实将 mkv 转换为 mp4,但是我的脚本无意运行
kes*_*esh 10
如果您还没有安装 ffmpeg/ffprobe 作为@Rotem 回答,您可以使用我的ffmpeg-downloader包:
pip install ffmpeg-downloader
ffdl install --add-path
Run Code Online (Sandbox Code Playgroud)
该--add-path选项将已安装的 FFmpeg 文件夹添加到用户的系统路径。重新打开 Python 窗口,您的程序将可以使用 ffmpeg 和 ffprobe。
正如您从错误消息中看到的,问题出在 和 上,ffprobe而不是ffmpeg。
确保 和ffprobe.exe都ffmpeg.exe位于可执行路径中。
ffprobe.exe和放在ffmpeg.exe与 Python 脚本相同的文件夹中(D:\Scripts\captcha\在您的情况下)。ffprobe.exe其他选项是将和的文件夹添加ffmpeg.exe到 Windows 系统路径。调试Pydub源代码(pydub-0.25.1):
该代码在以下代码中失败:
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
# no special security
None, None,
int(not close_fds),
creationflags,
env,
os.fspath(cwd) if cwd is not None else None,
startupinfo)
Run Code Online (Sandbox Code Playgroud)
在哪里args = 'ffprobe -of json -v info -show_format -show_streams test.mp3'
我们从以下地点到达那里:
info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
从:
prober = get_prober_name()
下面是该方法的源代码get_prober_name:
def get_prober_name():
"""
Return probe application, either avconv or ffmpeg
"""
if which("avprobe"):
return "avprobe"
elif which("ffprobe"):
return "ffprobe"
else:
# should raise exception
warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
return "ffprobe"
Run Code Online (Sandbox Code Playgroud)
该which方法查找命令是否在执行路径中(None如果未找到则返回)。
正如您从 Pydub 源代码中看到的那样,ffprobe.exe应该位于执行路径中。
注意
为了设置 FFmpeg 路径,我们还可以应用类似的内容:
import pydub
pydub.AudioSegment.converter = 'c:\\FFmpeg\\bin\\ffmpeg.exe'
sound = pydub.AudioSegment.from_mp3("test.mp3")
Run Code Online (Sandbox Code Playgroud)
但 FFprobe 没有这样的选项。