Cannot find a solution to [WinError 2] File not found by AudioSegment.from_mp3

3k Views Asked by At

Even though there are a handful of threads on this issue, no solutions have helped me, here is the problematic lines of code:

AudioSegment.converter = r'C:/users/user_/appdata/local/packages/pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0/localcache/local-packages/python38/site-packages/ffmpeg.exe'                        
AudioSegment.ffprobe   = r'C:/users/user_/appdata/local/packages/pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0/localcache/local-packages/python38/site-packages/ffprobe.exe'
final_voice = AudioSegment.from_mp3(file_path) + AudioSegment.silent(duration=silence_duration)

I have tried different methods to solve this issue, such as adding the paths to ffmpeg.exe and ffprobe.exe but nothing changed after that, other solutions do not make much sense as I am not using the modules they have had issues with and I did not do things they have done.

If you have any ideas please share as I have not found how to do the things AudioSegment does with other modules (by the way this issue has come up in every line of code containing AudioSegment.from_mp3(file_path))

Thanks

2

There are 2 best solutions below

1
On

Adding the ffmpeg files was not an option for me so I dug a little deeper. Short answer:

Change the else clause of get_prober_name() in your local ...\site-packages\pydub\utils.py (line 199 in my current version) to return the absolute path of your ffprobe.exe. After that the following code worked for me:

from pydub import AudioSegment

AudioSegment.converter = 'D:/Stuff/Software/ffmpeg/bin/ffmpeg.exe'
AudioSegment.ffprobe =  'D:/Stuff/Software/ffmpeg/bin/ffprobe.exe' # this does nothing!

mp3_fol = "D:/mp3/"
mp3_file = AudioSegment.from_mp3(mp3_fol + "my.mp3")

I'm using Windows with a unzipped version of ffmpeg (so no installation, Path entry or similar). While the converter method seemed to acutally set a value, the ffprobe method didn't do anything.

The subprocess the script is calling simply calls 'ffprobe' as a program. Which of course will not work if this is not a registered program. So the easiest (and hopefully safest) way to circumvent this behaviour is to set the default prober name to the correct full path (as done above).

3
On

The solution is quite simple, you have to add ffmpeg.exe, ffprobe.exe and ffplay.exe into your script directory. Download these exe files from the FFMPEG download page and take them from the bin folder