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

On Windows, FFmpeg can't be found by TorchAudio for Python > 3.8 - workaround available until TorchAudio addresses it #138

Open
DanMakingWithAI opened this issue Oct 1, 2024 · 2 comments

Comments

@DanMakingWithAI
Copy link

Though it wasn't causing any issues in usage, on Windows (10) I was finding my output logs to be full of (handled) exceptions from torch audio like:

DEBUG:torio._extension.utils:Loading FFmpeg6
DEBUG:torio._extension.utils:Failed to load FFmpeg6 extension.
Traceback (most recent call last):
  File "C:\Users\XXXXXX\.venv\gijiroku\Lib\site-packages\torio\_extension\utils.py", line 116, in _find_ffmpeg_extension
    ext = _find_versionsed_ffmpeg_extension(ffmpeg_ver)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXXXXX\.venv\gijiroku\Lib\site-packages\torio\_extension\utils.py", line 108, in _find_versionsed_ffmpeg_extension
    _load_lib(lib)
  File "C:\Users\XXXXXX\.venv\gijiroku\Lib\site-packages\torio\_extension\utils.py", line 94, in _load_lib
    torch.ops.load_library(path)
  File "C:\Users\XXXXXX\.venv\gijiroku\Lib\site-packages\torch\_ops.py", line 1032, in load_library
    ctypes.CDLL(path)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1008.0_x64__qbz5n2kfra8p0\Lib\ctypes\__init__.py", line 379, in __init__  
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: Could not find module 'C:\Users\XXXXXX\.venv\gijiroku\Lib\site-packages\torio\lib\libtorio_ffmpeg6.pyd' (or one of its dependencies). Try using the full path with constructor syntax.

and so on as it carried on trying lower and lower version numbers.

I thought it odd as I have ffmpeg installed and accessible in my PATH.

Long story short, it looks like it's a bug with the current version of torch audio - open issue at pytorch/audio#3789 - whereby the path is not checked for DLLs on Windows if Python version is > 3.8)

I followed the first part of the advice given at pytorch/audio#3789 (comment) - as that can be done in client code (they also dipped into torchaudio code to fix it there but I'd rather not) and so have added this code to my imports:

import sys
if sys.platform == 'win32':
    from torchaudio._extension.utils import _init_dll_path

and called it just before initialising anything in the library (e.g. get_engine() or TextToAudioStream()):

if sys.platform == 'win32':
    _init_dll_path()

Probably an imperfect solution, but those exceptions no longer occur for me at least and I thought it worth sharing.

@KoljaB
Copy link
Owner

KoljaB commented Oct 1, 2024

Thanks a lot, good insights I haven't been aware of.

@freeng
Copy link

freeng commented Nov 1, 2024

worked

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

3 participants