Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with AudioSegment.from_mp3 #62

Closed
sopekmir opened this issue Jun 15, 2014 · 56 comments
Closed

Problems with AudioSegment.from_mp3 #62

sopekmir opened this issue Jun 15, 2014 · 56 comments

Comments

@sopekmir
Copy link

Hello James,
I have Python2.7 (Win) and got latest pydub.
When trying to open mp3 file using:
song = AudioSegment.from_mp3("b.mp3")
(while double checking with os.listdir that I do have the file in current folder),
I'm getting:

song = AudioSegment.from_mp3("b.mp3")

Traceback (most recent call last):
File "<pyshell#5>", line 1, in
song = AudioSegment.from_mp3("b.mp3")
File "build\bdist.win32\egg\pydub\audio_segment.py", line 318, in from_mp3
return cls.from_file(file, 'mp3')
File "build\bdist.win32\egg\pydub\audio_segment.py", line 302, in from_file
retcode = subprocess.call(convertion_command, stderr=open(os.devnull))
File "C:\Python27\lib\subprocess.py", line 486, in call
return Popen(_popenargs, *_kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 672, in init
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 882, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

What's the problem?
Additionaly while I do first time: from pydub import AudioSegment
I'm getting:
Warning (from warnings module):
File "C:\Python27\lib\site-packages\pydub-0.9.2-py2.7.egg\pydub\utils.py", line 122
RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work

The repeated import goes without warning.

So - what it can be that I can't open plain mp3 file ?

my email is: sopekmir@makolab.pl

@jiaaro
Copy link
Owner

jiaaro commented Jun 15, 2014

Have you installed ffmpeg? If so it's possible it's not in your search path. That warning means pydub was unable to locate the ffmpeg binary, which is used to handle format conversions.

You can set the ffmpeg path explicitly:

import pydub

pydub.AudioSegment.converter = r"C:\\path\\to\\ffmpeg.exe"

@vladcebo
Copy link

vladcebo commented Aug 3, 2014

I have exactly the same issue there:
Python 2.7.8 on win32. ffmpeg is installed and is in my PATH.

from pydub import AudioSegment
AudioSegment.ffmpeg = "C:\\ffmpeg\\bin\\ffmpeg.exe"
song = AudioSegment.from_mp3("song.mp3")

error:

Warning (from warnings module):
  File "E:\Programming\Python 2.7\lib\site-packages\pydub-0.9.2-py2.7.egg\pydub\utils.py", line 122
RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work

Traceback (most recent call last):
  File "C:\Documents and Settings\Vlad\Рабочий стол\test\main.py", line 3, in <module>
    song = AudioSegment.from_mp3("ss.mp3")
  File "build\bdist.win32\egg\pydub\audio_segment.py", line 318, in from_mp3
    return cls.from_file(file, 'mp3')
  File "build\bdist.win32\egg\pydub\audio_segment.py", line 302, in from_file
    retcode = subprocess.call(convertion_command, stderr=open(os.devnull))
  File "E:\Programming\Python 2.7\lib\subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "E:\Programming\Python 2.7\lib\subprocess.py", line 702, in __init__
    errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr)
  File "E:\Programming\Python 2.7\lib\subprocess.py", line 850, in _get_handles
    c2pwrite = self._make_inheritable(c2pwrite)
  File "E:\Programming\Python 2.7\lib\subprocess.py", line 884, in _make_inheritable
    _subprocess.DUPLICATE_SAME_ACCESS)
WindowsError: [Error 6] 

@jiaaro
Copy link
Owner

jiaaro commented Nov 7, 2014

There was a bug after we switched to use AudioSegment.converter instead of AudioSegment.ffmpeg where assigning ffmpeg did not work. It's been resolved in v0.9.4

Going forward, you should assign to AudioSegment.converter though ;)

@jiaaro jiaaro closed this as completed Nov 7, 2014
@mosynaq
Copy link

mosynaq commented Sep 26, 2016

I assign the path to 'ffmpeg.exe' to both AudioSegment.converter and AudioSegment.ffmpeg but i receive the same error:
C:\Python34\python.exe "D:/path/to/project/SplitWavFiles.py" C:\Python34\lib\site-packages\pydub\utils.py:165: 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)

And here is my code:

from pydub import AudioSegment
AudioSegment.converter = "D:/path/to/ffmpeg/ffmpeg.exe"
sound = AudioSegment.from_wav("./S11.WAV")

@jiaaro
Copy link
Owner

jiaaro commented Sep 26, 2016

@mosynaq That warning indicates that ffmpeg wasn't found in the path. If you then assign AudioSegment.converter to the correct value, you should be able to ignore the warning and continue normally.

If you are still getting a file not found error, it could be S11.WAV which is not being found.

Or if you just want to get rid of the runtime warning, you can add D:\\path\\to\\ffmpeg\\ to your PATH so that it can be found automatically (which would make assigning AudioSegment.converter unnecessary)

@WiliTest
Copy link

I could not get rid of the error, but it's working with it.

@jiaaro
Copy link
Owner

jiaaro commented Jan 20, 2017

@WiliTest yeah, it's a runtime warning (not error) - if you know it won't cause a problem in your specific application and configuration it's safe to ignore. It's just there to inform users that the auto detection was not successful so they will need to set converter manually.

You can suppress runtime warnings in the python interpreter (in a shipping product for instance) by running your program with the -W option like python -W ignore my_script_using_pydub.py

You can also put ffmpeg.exe in the directory your program runs in since that is one place pydub looks for it.

@WiliTest
Copy link

thanks for your reply Jiaaro, I understand. And thanks a lot for your work, the module is awesome!

@nikesh0822
Copy link

nikesh0822 commented May 2, 2017

@WiliTest, @jiaaro , Hello. I have the following error. How could I resolve this?

`I'm listening

Found audio
Google Speech Recognition thinks you said hello mirror
Traceback (most recent call last):
File "bot.py", line 254, in
bot.start()
File "bot.py", line 45, in start
self.__acknowledge_action()
File "bot.py", line 143, in __acknowledge_action
self.__text_action(self.nlg.acknowledge())
File "bot.py", line 154, in __text_action
self.speech.synthesize_text(text)
File "/home/pi/AI-Smart-Mirror/speech.py", line 55, in synthesize_text
song = AudioSegment.from_mp3("tmp.mp3")
File "/usr/local/lib/python2.7/dist-packages/pydub/audio_segment.py", line 514, in from_mp3
return cls.from_file(file, 'mp3')
File "/usr/local/lib/python2.7/dist-packages/pydub/audio_segment.py", line 497, in from_file
p = subprocess.Popen(conversion_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 710, in init
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
`
*The above error was on raspberry pi 3

@jiaaro
Copy link
Owner

jiaaro commented May 2, 2017

@nikesh0822 That stack trace is very likely because ffmpeg is not installed or can't be found. Have you tried manually setting the converter as suggested earlier in this thread?

@nikesh0822
Copy link

nikesh0822 commented May 2, 2017

hey @jiaaro , I did install ffmpeg but may be I went wrong somewhere while manually setting the converter. But thanks for the help, I fixed it. I had a line
song = song = AudioSegment.from_mp3("tmp.mp3") as mentioned above and replaced it with
import subprocess
subprocess.Popen(['mpg123','-q', 'tmp.mp3']).wait()
and that worked well.
Thanks anyways @jiaaro

@ahwangyuwei
Copy link

libav

apt-get install libav-tools libavcodec-extra-53

OR

ffmpeg

apt-get install ffmpeg libavcodec-extra-53

@lgming
Copy link

lgming commented Nov 20, 2017

hey @jiaaro ,i set the path like this. But i still not work on centos:

AudioSegment.converter ="/monchickey/ffmpeg/bin/ffmpeg"
sound = AudioSegment.from_file(wav_path + "\" + name, format="wav")

i have installed ffmpeg on centos.

@jiaaro
Copy link
Owner

jiaaro commented Nov 20, 2017

@lgming In your case I suspect it's the second line: wav_path + "\" + name

Shouldn't the slash be a forward slash? like wav_path + "/" + name ?

@lgming
Copy link

lgming commented Nov 21, 2017

@jiaaro many thanks, I make a low-level error. And thanks a lot for your work, it is awesome!

@joshuakery
Copy link

Hi,

I am not sure if I am doing this wrong, but I am having the same issue as mentioned above, and I still can't get it to work:

This is the code that I am trying to run:
from pydub import AudioSegment AudioSegment.converter = "/usr/local/Cellar/ffmpeg/4.0/bin/ffmpeg.exe" sound = AudioSegment.from_mp3("/Users/joshuakery1/Desktop/cordoba.mp3")

And this is the no such file or directory error that I'm logging because of it:
Traceback (most recent call last): File "/Users/joshuakery1/Desktop/test2.py", line 3, in <module> sound = AudioSegment.from_mp3("/Users/joshuakery1/Desktop/cordoba.mp3") File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydub/audio_segment.py", line 702, in from_mp3 return cls.from_file(file, 'mp3', parameters) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydub/audio_segment.py", line 658, in from_file info = mediainfo_json(orig_file) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydub/utils.py", line 244, in mediainfo_json res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 390, in __init__ errread, errwrite) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1025, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory

Additionally, like mentioned above, the first time I run my code with import pydub or from pydub import AudioSegment I get the warning: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydub/utils.py:174: 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)

Additionally additionally: Trying to use sound = AudioSegment.from_mp3("/Users/joshuakery1/Desktop/cordoba.mp3"), I get the warning: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pydub/utils.py:201: RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)

I am not sure if I am assigning the audiosegment converter to the right value correctly. Is there a way to confirm that it's found the ffmpeg that I've installed?

(I'm also unsure if my path should be pointing to the ffmpeg file or folder. Also: I've tried using D:/path/to/ffmpeg.exe as the file path, but here again, I'm unfamiliar with how paths work and am confused. Are this and similar paths, like r"C:\\path\\to\\ffmpeg.exe" actual ways to reach the ffmpeg, or are they pseudocode that I should substitute with the literal path?)

And I am not sure if I have given a path correctly to the audio file that I'm trying to use. Is there a way to check this too?

Any answers to my questions would be much appreciated!
Thanks!

@jiaaro
Copy link
Owner

jiaaro commented May 29, 2018

@joshuakery it looks like you're on a Mac, so it would just be

AudioSegment.converter = "/usr/local/Cellar/ffmpeg/4.0/bin/ffmpeg"

only windows has ".exe" at the end of the executable name

@joshuakery
Copy link

joshuakery commented May 30, 2018

I tried that, but it still doesn't work and there's no change to the error and warnings.

Thanks for the reply. Any other ideas?

@MarkoGill
Copy link

MarkoGill commented Jun 11, 2018

@joshuakery I ran into that issue recently and previously wasn't experiencing issues. I had to add the directory containing ffprobe to PATH. Hope this helps.

@jiaaro It might be nice to add something similar to AudioSegment.converter for the prober.

@wewark
Copy link

wewark commented Jul 6, 2018

I am having the same issue.
I have downloaded ffmpeg and added it path and its warnings are gone, but it still gives
FileNotFoundError: [WinError 2] The system cannot find the file specified

@kartiksonu
Copy link

libav

apt-get install libav-tools libavcodec-extra-53

OR

ffmpeg

apt-get install ffmpeg libavcodec-extra-53

this worked for me

@agarwalkaushal
Copy link

I am having the same issue.
I have downloaded ffmpeg and added it path and its warnings are gone, but it still gives
FileNotFoundError: [WinError 2] The system cannot find the file specified

Same error for Windows! Please help.

@elahimanesh
Copy link

I am having the same issue.
I have downloaded ffmpeg and added it path and its warnings are gone, but it still gives
FileNotFoundError: [WinError 2] The system cannot find the file specified

Same error for Windows! Please help.

you need to this:
1- Download and extract libav from Windows binaries provided here. (http://builds.libav.org/windows/)
2- Add the libav /bin folder to your PATH envvar
3- pip install pydub

@juihsuanlee
Copy link

@elahimanesh
hi I have done the steps above but I still have the same error message.
please hlp me thank you

@sedthh
Copy link

sedthh commented Jan 29, 2019

same here, tried to install everything mentioned here and still got an error

@Extalionos
Copy link

I have windows.
If i use this, i have error

AudioSegment.converter = ffmpeg_catalog+'ffmpeg.exe'
AudioSegment.ffmpeg = ffmpeg_catalog+'ffmpeg.exe'
AudioSegment.ffprobe = ffmpeg_catalog+'ffprobe.exe'

But when i add "C:\ffmpeg\bin" to PATH and restart os it works.
And you must to remove lines above.

@S-Venkat-S
Copy link

I am having the same error while running the python via ATOM editor using plugins
C:\Python27\lib\site-packages\pydub\utils.py:193: RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)

When i run it in the Command Prompt It works.
If anyone having the same issue while running the python via any editors
Try running the file via command prompt.

@anshgupta1234
Copy link

I've tried fixing this problem for 2 hours and I'm almost ready to quit. I've done everything this thread has asked and more.

I added ffmpegg to PATH.

This is my code:

AudioSegment.converter = r"C:\Program Files\FFmpeg\bin"

@warwarra
Copy link

warwarra commented Jul 4, 2019

Hi, im trying to run:
sample = AudioSegment.from_file(song_dir + "/" + filename, format= "mp3")

But it returns:
pydub.exceptions.CouldntDecodeError: Decoding failed. ffmpeg returned error code: 1

Output from ffmpeg/avlib:

b"avconv version 12.3, Copyright (c) 2000-2018 the Libav developers
built on Jan 22 2019 21:47:08 with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
[mp3 @ 0x7fcaea008600] Header missing\n[mp3 @ 0x7fcaea002200] Could not find codec parameters (Audio: mp3
0 channels, s16p)
[mp3 @ 0x7fcaea002200] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from 'songs/.DS_Store':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Audio: mp3
0 channels, s16p
Output #0, wav, to 'pipe:':
Output file #0 does not contain any stream"

What can I do to fix it?

@Sobiam1
Copy link

Sobiam1 commented Oct 1, 2019

Hi

I've tried fixing this problem for 2 hours and I'm almost ready to quit. I've done everything this thread has asked and more.

I added ffmpegg to PATH.

This is my code:

AudioSegment.converter = r"C:\Program Files\FFmpeg\bin"

Hi,
Did you fix this issue with mmpeg ?

@derek-adair
Copy link

derek-adair commented Oct 1, 2019

Ooof. This is a painful thread to sift through.... its FIVE years old and people still continue to revive it. Let me tell you that pydub, ffmpeg and libav have all released MANY versions... there could be multiple different incarnations of this bug.

A lot of you aren't even including most of the relevant information to help debug these.

  1. What OS are you using?
  2. What version of python?
  3. What version of ffmpeg OR libav?
  4. What version of pydub?

Without this info, contributors are basically taking shots in the dark as to why you are getting these errors.

this thread is a dumpster fire. I'd suggest locking it w/ a link to the install instructions. @jiaaro you're a more patient maintainer than myself.

@derek-adair
Copy link

@warwarra - this is an entirely separate issue and deserves its own thread.

@amittal-tcd
Copy link

In anaconda you can resolve this issue by installing ffmpeg from conda-forge

conda install -c conda-forge ffmpeg

@CKanishka
Copy link

Thanks @amittal-tcd ,your solution did the job for me.

@nNasir
Copy link

nNasir commented Nov 19, 2019

Hi,
Does the following work for ubuntu aswell?

AudioSegment.converter = r"C:\Program Files\FFmpeg\bin"

If not, what the way around can I use it in ubuntu? I don't have admin privileges to install ffmpeg

@ispassov
Copy link

ispassov commented Mar 9, 2020

For Windows:

  • install ffmpeg
  • set environment variable - > "your ffmpeg installation directory"\ffmpeg\bin
  • log off OR restart windows

@harshittrehan
Copy link

Faced the same issue. Basically ffmpeg was missing.
Install it, add it to PATH and most importantly, restart windows.

@predict-woo
Copy link

I have python running on windows 10, and when I try to move the FFmpeg folder to anywhere else than C:\ and add a path to the file by doing

from pydub import AudioSegment
AudioSegment.converter = '/Program Files/FFmpeg/bin/ffmpeg.exe'

(yes I have tried 'AudioSegment.ffmpeg')

and try to open a mp3 file by

song = AudioSegment.from_mp3("/Users/andyy/song.mp3")

It returns me an error that says
FileNotFoundError: [WinError 2] The system cannot find the file specified

Can anyone tell me what the problem is?

The python version is 3.7

@Abuton
Copy link

Abuton commented Apr 28, 2020

You need to set path to ffmpeg.exe in your local drive (C) atleast that what I did and it worked. Also use AudioSegment.converter = r "path\to\ffmpeg.exe
Instead of AudioSegment ffmpeg don't use these use the first one.
Also I tried this on windows 10 python 3.7 and it worked

@predict-woo
Copy link

It does work when I put ffmpeg.exe into C:\\FFmpeg\bin but I need to be able to put it somewhere else so I can package it with my exe-packaged-python-file and run it on any computer that does not have ffmpeg installed

@predict-woo
Copy link

Mabye I need to add a PATH to windows pointing in that direction?

@Tensorflow-Ranger
Copy link

I faced the same issue even after adding ffmpeg to PATH. I moved ffmpeg.exe, ffplay.exe, ffprobe.exe from C:\ffmpeg\bin to the directory where the code is running and it worked.

@kunakl07
Copy link

kunakl07 commented Aug 9, 2020

I am getting this issue while using it on docker, could anyone please help

/usr/local/lib/python3.6/site-packages/pydub/utils.py:170: 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)
The mean of the call duration is 1.9663194445714285
Traceback (most recent call last):
File "./preprocess.py", line 447, in
args.grayscale
File "./preprocess.py", line 344, in main
call_annotations
File "./preprocess.py", line 115, in extract_audio
sound = AudioSegment.from_file(audio_file)
File "/usr/local/lib/python3.6/site-packages/pydub/audio_segment.py", line 622, in from_file
file, close_file = _fd_or_path_or_tempfile(file, 'rb', tempfile=False)
File "/usr/local/lib/python3.6/site-packages/pydub/utils.py", line 60, in _fd_or_path_or_tempfile
fd = open(fd, mode=mode)

@hanzigs
Copy link

hanzigs commented Sep 2, 2020

I have same issue,
image

from pydub import AudioSegment
sound = AudioSegment.from_mp3("unknown.mp3")
image

Whether pydub package got withdrawn? Looks like no body getting it worked

@paqstd
Copy link

paqstd commented Oct 5, 2020

I have a similar problem. It's weird that it wasn't added to the readme ...

@RussianDraco
Copy link

I am having an issue with this as well but I have an addition, instead of doing AudioSegment.from_file(file_name) try doing AudioSegment.from_file(file_path), it sometimes works

@pzarzycki
Copy link

pzarzycki commented Sep 7, 2021

Same. Cant load .mp3 on Windows. I tried assigning AudioSegment.ffmpeg, AudioSegment.converter and even copying ffmepeg to C:/FFmpeg/bin as others suggested. Nothing works.

It worked only, when I added ffmpeg to the path:
os.environ["PATH"] += os.pathsep + r'D:\SDK\ffmpeg-4.3-win64-static\bin'

@Kalaborative
Copy link

Kalaborative commented Oct 27, 2021

My ffmpeg folder is already in PATH. Also tried setting AudioSegment.converter to the same directory. I'm on Windows, Python 3.8, the latest version of pydub.

Still getting the error: FileNotFoundError: [WinError 2] The system cannot find the file specified

I don't know what else I could possibly be doing wrong. The file is in the same directory as the python script. Even using an absolute link does nothing. Am I missing something..?

@lev007-ops
Copy link

Hey @jiaaro, i have this code:

import pydub
pydub.AudioSegment.converter = r"ffmpeg.exe"
sound = pydub.AudioSegment.from_mp3(file_src)

But on startup I get the error:

Traceback (most recent call last):
  File "c:\Users\Дом\Desktop\Py\PY\e_garant_bot\audio_2_text.py", line 21, in <module>
    print(recognition('captcha_audio5.mp3', 'test.wav'))
  File "c:\Users\Дом\Desktop\Py\PY\e_garant_bot\audio_2_text.py", line 14, in recognition
    sound = pydub.AudioSegment.from_mp3(file_src)
  File "C:\Users\Дом\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\audio_segment.py", line 796, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)
  File "C:\Users\Дом\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\audio_segment.py", line 728, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
  File "C:\Users\Дом\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\utils.py", line 274, in mediainfo_json
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
  File "C:\Users\Дом\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Дом\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Не удается найти указанный файл

translation: FileNotFoundError: [WinError 2] The specified file cannot be found

what should I do? ffmpeg is located in the script folder.
Help me please

@grpnpraveen
Copy link

@mosynaq That warning indicates that ffmpeg wasn't found in the path. If you then assign AudioSegment.converter to the correct value, you should be able to ignore the warning and continue normally.

If you are still getting a file not found error, it could be S11.WAV which is not being found.

Or if you just want to get rid of the runtime warning, you can add D:\\path\\to\\ffmpeg\\ to your PATH so that it can be found automatically (which would make assigning AudioSegment.converter unnecessary)

Thanks, this worked !

@soumodeepsen
Copy link

Ref. https://github.com/soumodeepsen/mp3_to_wav/tree/main
I hope this piece of code by me helps you.

@AlkisPis
Copy link

Have you installed ffmpeg? If so it's possible it's not in your search path. That warning means pydub was unable to locate the ffmpeg binary, which is used to handle format conversions.

You can set the ffmpeg path explicitly:

import pydub

pydub.AudioSegment.converter = r"C:\\path\\to\\ffmpeg.exe"

Well, it doesn't work with me. 'AudioSegment.from_wav()' is OK. 'AudioSegment.from_mp3()' refuses to work.

@AlkisPis
Copy link

AlkisPis commented Jul 10, 2023

In my case, Python 3.5, pydub 0.25.1, 'AudioSegment.from_mp3()' doesn;t work, whatever I do.
The problem is not the path of ffmpeg. In fact, it has nothing to do woth 'ffmgeg'. I debugged 'pydub\audio_segment.py' and the problem lies in class method 'from_mp3(). More specifically:

@classmethod`
def from_mp3(cls, file, parameters=None):
   return cls.from_file(file, 'mp3', parameters=parameters)

'file' = "1.mp3" (in current path, even if given with full path), and 'parameters' = None
Well, the 'from_file()' function raises FileNotFoundError. Which is insane. Except of course, as it often happens, if this a false error or it refers to some other file that is not found, etc. Whatever is the case, what we have here is a huge bug.

@Oreldm
Copy link

Oreldm commented Jan 3, 2024

In my case, Python 3.5, pydub 0.25.1, 'AudioSegment.from_mp3()' doesn;t work, whatever I do. The problem is not the path of ffmpeg. In fact, it has nothing to do woth 'ffmgeg'. I debugged 'pydub\audio_segment.py' and the problem lies in class method 'from_mp3(). More specifically:

@classmethod`
def from_mp3(cls, file, parameters=None):
   return cls.from_file(file, 'mp3', parameters=parameters)

'file' = "1.mp3" (in current path, even if given with full path), and 'parameters' = None Well, the 'from_file()' function raises FileNotFoundError. Which is insane. Except of course, as it often happens, if this a false error or it refers to some other file that is not found, etc. Whatever is the case, what we have here is a huge bug.

Same here. Confirmed on Windows 10.
I debugged it and I can see that we are calling on line 665 at audio_segment.py to info = mediainfo_json(orig_file)
This will essentially run res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE) . In the command we will try to run ffprobe that might not be a valid command for every computer.

I don't think this is a good way to build the library (to rely on ffprobe command), and it should be changed.
I'll try to find a solution for that.

At least for now- I will add a fix to send the right exception.

@jameswan
Copy link

I am on WIndows. This worked for me to remove this warning:
C:\Users\James\anaconda3\envs\rich_transcription\lib\site-packages\pydub\utils.py:170: 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)

Set your Environment Variables in Windows by adding this to Path:
G:\ffmpeg-20171114-91a565e-win64-static\bin

In your Python file, add this line:
AudioSegment.converter = r"G:\ffmpeg-20171114-91a565e-win64-static\bin"

@AlkisPis
Copy link

AlkisPis commented Apr 25, 2024

AudioSegment.converter = r"G:\ffmpeg-20171114-91a565e-win64-static\bin" alone does not work, simply because one must import the 'AudioSegment' module from pypub and from pybub import AudioSegment raises an error if 'ffmpeg\bin' folder is not in PATH. But then, if it is, one does not need to add AudioSegment.converter = ... in the PY file. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests