简体   繁体   English

Pydub 找不到 ffmpeg 尽管它已安装并在路径中

[英]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.

相关问题 OSX-找不到在我的路径中添加python的内容 - OSX - can't find what's adding python to my path Python找不到使用pip安装的软件包 - Python can't find packages installed with pip 通过 brew 安装了 mysql 但终端找不到它。 在 macos 上别名的正确方法是什么? - Installed mysql via brew but terminal can't find it. What's the proper way to alias it on a macos? brew installed gcc 找不到 brew installed gmp - brew installed gcc can't find brew installed gmp zsh 既不能在 ~/bin 中找到也不能执行自定义用户脚本,尽管它们是可执行的并且在 $PATH 环境变量中 - zsh can neither find nor execute custom user scripts in ~/bin although they are executable and in the $PATH environment variable 未检测到已安装的ffmpeg。 无法转换音频(Python 2.7,Mac OS X) - installed ffmpeg not detected. Can't convert audio (python 2.7, mac os x) 找到 Homebrew 安装的 Python 的路径 - Find path of Python installed by Homebrew Groovy为什么即使在我的PATH上也找不到该程序? - Why can't Groovy find this program even though it's on my PATH? Excel VBA 在路径中找不到文件 - Excel VBA can't find files in path Python在我的路径中找不到geckodriver - Python can't find geckodriver in my path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM