1
votes

I'm attempting to open some MP3 files to find their lengths (as part of a larger project). I've installed pydub and ffmpeg has been installed via 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. The program can open and play the audio file (using pygame), so I'm sure it's not a file issue.

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.

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).

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'

1
You don't need to install anything on a Mac to get the duration of an mp3 file, the built-in mdls command will do that for you mdls -name kMDItemDurationSeconds song.mp3Mark Setchell
Thanks @Mark Setchell, but I need to do it within Python as it's part of a project that will also need to run on Windows.djaychela

1 Answers

5
votes

This was hard work to figure out. But here it is.

On Mac, run 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. 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

from pydub import AudioSegment

AudioSegment.converter = '/usr/local/Cellar/ffmpeg/4.2.1_2/bin/ffmpeg'