Lone Lunatic
Lone Lunatic

Reputation: 835

Pydub installation and ffmpeg

I was trying to get raw sound data out of a .mp3 file. Therefor I used the pydub module as stated here. I created a venv for this project and installed all necessary modules. But for some reason, pydub decided to give me an FileNotFoundError:

(venv) Python-IT:LightsDev pythonit$ which python
/Users/pythonit/Documents/Programmieren/Python/LightsDev/venv/bin/python
(venv) Python-IT:LightsDev pythonit$ which pip3
/Users/pythonit/Documents/Programmieren/Python/LightsDev/venv/bin/pip3
(venv) Python-IT:LightsDev pythonit$ pip3 list 
------------- -------
ffmpeg        1.4
pip           18.1
pydub         0.23.0
pyee          5.0.0
python-ffmpeg 1.0.5
setuptools    39.0.1

My exact code looks like that:

from pydub import AudioSegment
sound = AudioSegment.from_mp3('test.mp3')
raw_data = sound._data
print(raw_data)

and I get this error:

FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe': 'ffprobe'

alongside this runtime warning:

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)

I don't know if it is me, but some similar questions stating I should install ffmpeg or python-ffmpeg won't work. I can even import the ffmpeg module but nothing happens. I can work with ffmpeg and load files but using it with pydub won't work.

EDIT: Today I changed to my windows machine and looked at the error in-depth. However I didn't manage to get it working, even with the solution provided in the comments (thank you though). I installed the ffmpeg binary as stated and i was able to get ffmpeg running in the shell, however not with pydub... I have no clue what is going on. I guess my mistake is very obvious and I am just not able to get it. Even not subprocess was able to solve this problem despite the fact, that I am able to use ffmpeg in shell. I even was able to convert the file using ffmpeg in shell...

 ffmpeg -i test.mp3 test.wav 
 > Output #0, wav, to 'test.wav':

I think I am close to solve the problem myself anyways, but thank you anyways.

Upvotes: 4

Views: 14772

Answers (2)

LakeConstanceCH
LakeConstanceCH

Reputation: 160

This error was also driving me crazy; Path was clearly the problem. There are several explanations like the one below that tell you to modify to C:\ffmpeg\bin (example: https://windowsloop.com/install-ffmpeg-windows-10/) and others that explain same did not work.

My solution was to modify the path to anaconda3 path: C:\Users\YOURPATH\anaconda3\Lib\site-packages\ffmpeg\bin

Then I needed to restart the computer for registry changes to take effect!

Don't forget that last step...

Unusual that ffmpeg can't create, use paths without user modification of registry paths (dirty)?

Upvotes: 0

Denny
Denny

Reputation: 163

Install ffmpeg to your system, not python lib:

In Ubuntu: sudo apt install ffmpeg

In Windows: Just download the ffmpeg lib, extract, and add the ***\bin path to the environment path

And Install both simpleaudio and pydub via pip to python lib (I don't know why, but it work for me)

Upvotes: 6

Related Questions