[英]Pydub can't find ffmpeg although it's installed and in path
I'm attempting to open some MP3 files to find their lengths (as part of a larger project).我正在尝试打开一些 MP3 文件以找到它们的长度(作为更大项目的一部分)。 I've installed pydub and ffmpeg has been installed via brew.
我已经安装了 pydub 并且 ffmpeg 已经通过 brew 安装。 ffmpeg is available in my path, and typing ffmpeg in a terminal launches it successfully - the audio file I'm referencing is present and I can run ffmpeg -i on it to get information about it.
ffmpeg 在我的路径中可用,并且在终端中输入 ffmpeg 会成功启动它 - 我引用的音频文件存在,我可以在其上运行 ffmpeg -i 以获取有关它的信息。 The program can open and play the audio file (using pygame), so I'm sure it's not a file issue.
该程序可以打开和播放音频文件(使用 pygame),所以我确定这不是文件问题。
However, attempting to open any files with AudioSegment leads to 'Couldn't find ffmpeg or avconv - defaulting to ffmpeg but may not work' being displayed, and any attempt to open a file using AudioSegment leads to an exception.但是,尝试使用 AudioSegment 打开任何文件会导致显示“找不到 ffmpeg 或 avconv - 默认为 ffmpeg 但可能不起作用”,并且任何使用 AudioSegment 打开文件的尝试都会导致异常。
I've tried setting the path to ffmpeg explicitly using AudioSegment.converter - both trying to point to '/usr/local/bin/ffmpeg' and also to the true location (the previous one is a symlink).我已经尝试使用 AudioSegment.converter 显式设置 ffmpeg 的路径 - 既试图指向 '/usr/local/bin/ffmpeg' 也试图指向真实位置(前一个是符号链接)。
from pydub import AudioSegment
AudioSegment.converter = '/usr/local/bin/ffmpeg' # tried with and without
print(len(AudioSegment.from_mp3('mp3_audio.mp3')))
I get FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe': 'ffprobe'我得到 FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe': 'ffprobe'
This was hard work to figure out.这是很难弄清楚的。 But here it is.
但它在这里。
On Mac, run brew install ffmpeg
在 Mac 上,运行
brew install ffmpeg
Then you need to find where it has written the binary to.然后您需要找到它将二进制文件写入的位置。 It will be buried in
/usr/local/Cellar
directory and will be based on the version number of the install.它将被埋在
/usr/local/Cellar
目录中,并将基于安装的版本号。 In my case it was就我而言,它是
/usr/local/Cellar/ffmpeg/4.2.1_2/bin/ffmpeg
You then need to add this path into your Python script as follows然后,您需要将此路径添加到您的 Python 脚本中,如下所示
from pydub import AudioSegment
AudioSegment.converter = '/usr/local/Cellar/ffmpeg/4.2.1_2/bin/ffmpeg'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.