"Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning
Asked Answered
C

6

11

For a captcha solver I need to use FFmpeg on Windows 10. Warning when running the code for the first time:

C:\Users\user\AppData\Roaming\Python\Python310\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)

Running the script anyway while it required ffprobe I got:

C:\Users\user\AppData\Roaming\Python\Python310\site-packages\pydub\utils.py:198: 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)
Traceback (most recent call last):
  File "D:\Scripts\captcha\main.py", line 164, in <module>
    main()
  File "D:\Scripts\captcha\main.py", line 155, in main
    captchaSolver()
  File "D:\Scripts\captcha\main.py", line 106, in captchaSolver
    sound = pydub.AudioSegment.from_mp3(
  File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\pydub\audio_segment.py", line 796, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)
  File "C:\Users\user\AppData\Roaming\Python\Python310\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\user\AppData\Roaming\Python\Python310\site-packages\pydub\utils.py", line 274, in mediainfo_json
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
  File "C:\Program Files\Python310\lib\subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Program Files\Python310\lib\subprocess.py", line 1435, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

I tried downloading it manually, editing environment variables, pasting them in the same folder as the script and installing with pip. FFmpeg works however my script doesn't.

Cartage answered 2/12, 2022 at 5:21 Comment(1)
Can you please edit your question and the two lines of code that reproduces the issue? The question may be relevant to others, but posting only the error message without the code is unpleasant.Eatmon
J
14

If you haven't installed the ffmpeg/ffprobe as @Rotem answered, you can use my ffmpeg-downloader package:

pip install ffmpeg-downloader
ffdl install --add-path

The --add-path option adds the installed FFmpeg folder to the user's system path. Re-open the Python window and both ffmpeg and ffprobe will be available to your program.

Jodee answered 2/12, 2022 at 15:51 Comment(5)
Use yes | poetry run ffdl install --add-path to automatically accept the Y/n question during the installMonastery
This does not work for me on Windows 11 Enterprise. The pip install runs successfully, but not the ffdl install (with or without --add-path).Praedial
@Praedial - could you post an issue on GitHub so we can look at it closely?Jodee
need a restart on WindowsPension
@Pension - Technically, you just need to restart the shell window for the --add-path to take effect.Jodee
E
3

As you can see by the error message, the issue is with ffprobe and not ffmpeg.

Make sure that both ffprobe.exe and ffmpeg.exe are in the executable path.

  • One option is placing ffprobe.exe and ffmpeg.exe in the same folder as the Python script (D:\Scripts\captcha\ in your case).
  • Other option is adding the folder of ffprobe.exe and ffmpeg.exe to Windows system path.
    (Placing the EXE files in a folder that is already in the system path may also work).

Debugging Pydub source code (pydub-0.25.1):

The code fails in the following code:

hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                         # no special security
                         None, None,
                         int(not close_fds),
                         creationflags,
                         env,
                         os.fspath(cwd) if cwd is not None else None,
                         startupinfo)

Where args = 'ffprobe -of json -v info -show_format -show_streams test.mp3'

We are getting there from:

info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)

From:

prober = get_prober_name()

Here is the source code of get_prober_name method:

def get_prober_name():
    """
    Return probe application, either avconv or ffmpeg
    """
    if which("avprobe"):
        return "avprobe"
    elif which("ffprobe"):
        return "ffprobe"
    else:
        # should raise exception
        warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
        return "ffprobe"

The which method looks for the command is in the execution path (returns None if it is not found).

As you can see from Pydub sources, ffprobe.exe should be in the execution path.


  • Note
    For setting FFmpeg path we may also apply something like:

     import pydub
     pydub.AudioSegment.converter = 'c:\\FFmpeg\\bin\\ffmpeg.exe'
     sound = pydub.AudioSegment.from_mp3("test.mp3")
    

But there is no such option for FFprobe.

Eatmon answered 2/12, 2022 at 11:27 Comment(0)
B
3

Following the installation guide in the Github repository, I proceed like that:

apt-get install ffmpeg libavcodec-extra

And now it works for me.

Bridewell answered 25/10, 2023 at 11:5 Comment(0)
A
1

When using conda, simply follow the instructions at conda-forge/ffmpeg-feedstock

conda config --add channels conda-forge
conda config --set channel_priority strict
conda install ffmpeg

this will install ffmpeg into your conda environment, not globally.

Aorist answered 18/6, 2024 at 15:51 Comment(0)
S
0

sometimes the pc has several users, or there is different outlook user logged in, in such cases the location you put for C:\ffmpeg\bin on system environments is very unlikely to work, putting the ffmpeg folder in the C:\Users\YourName\... locations won't work either.

also, if none of the above mentioned comments work, just follow Rotem's comment where he/she says One option is placing ffprobe.exe and ffmpeg.exe in the same folder as the Python script (D:\Scripts\captcha\ in your case).

This worked fine for me and the animatons can now work fine.

Stocktonontees answered 24/6, 2024 at 12:4 Comment(0)
E
0

Add path of ffmpeg bin via:

os.environ["PATH"] += os.pathsep + os.path.abspath(os.path.join(os.getcwd(), 'relative path of bin'))
Enthrall answered 22/7, 2024 at 9:21 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.