Torchaudio is not able to access FFmpeg

username: Dylen
cooked: <p>I am new to torchaudio, and I am trying to use StreamReader to get data from my microphone, but I cannot get it to start because it can’t access FFmpeg.</p>
<pre><code class="lang-auto">from torchaudio.io import StreamReader

streamer = StreamReader(
    src='audio=@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{A531F508-ED15-42F3-A46F-9C8ADB26C05A}',
    format='dshow',
)
for i in range(streamer.num_src_streams):
    print(streamer.get_src_stream_info(i))
</code></pre>
<pre><code class="lang-auto">ImportError                               Traceback (most recent call last)
Cell In[2], line 4
      1 import matplotlib.pyplot as plt 
      2 from torchaudio.io import StreamReader
----&gt; 4 streamer = StreamReader(
      5     src='audio=@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{A531F508-ED15-42F3-A46F-9C8ADB26C05A}',
      6     format='dshow',
      7 )

File d:\Python\torchaudio\.venv\Lib\site-packages\torio\io\_streaming_media_decoder.py:526, in StreamingMediaDecoder.__init__(self, src, format, option, buffer_size)
    524     self._be = ffmpeg_ext.StreamingMediaDecoderFileObj(src, format, option, buffer_size)
    525 else:
--&gt; 526     self._be = ffmpeg_ext.StreamingMediaDecoder(os.path.normpath(src), format, option)
    528 i = self._be.find_best_audio_stream()
    529 self._default_audio_stream = None if i &lt; 0 else i

File d:\Python\torchaudio\.venv\Lib\site-packages\torio\_extension\utils.py:25, in _LazyImporter.__getattr__(self, item)
     24 def __getattr__(self, item):
---&gt; 25     self._import_once()
     26     return getattr(self.module, item)

File d:\Python\torchaudio\.venv\Lib\site-packages\torio\_extension\utils.py:39, in _LazyImporter._import_once(self)
     37 def _import_once(self):
     38     if self.module is None:
---&gt; 39         self.module = self.import_func()
     40         # Note:
     41         # By attaching the module attributes to self,
     42         # module attributes are directly accessible.
     43         # This allows to avoid calling __getattr__ for every attribute access.
     44         self.__dict__.update(self.module.__dict__)

File d:\Python\torchaudio\.venv\Lib\site-packages\torio\_extension\utils.py:143, in _init_ffmpeg()
    141 def _init_ffmpeg():
    142     ffmpeg_vers = _get_ffmpeg_versions()
--&gt; 143     ext = _find_ffmpeg_extension(ffmpeg_vers)
    144     ext.init()
    145     if ext.get_log_level() &gt; 8:

File d:\Python\torchaudio\.venv\Lib\site-packages\torio\_extension\utils.py:122, in _find_ffmpeg_extension(ffmpeg_vers)
    120         _LG.debug("Failed to load FFmpeg%s extension.", ffmpeg_ver, exc_info=True)
    121         continue
--&gt; 122 raise ImportError(
    123     f"Failed to intialize FFmpeg extension. Tried versions: {ffmpeg_vers}. "
    124     "Enable DEBUG logging to see more details about the error."
    125 )

ImportError: Failed to intialize FFmpeg extension. Tried versions: ['6', '5', '4', '']. Enable DEBUG logging to see more details about the error.
</code></pre>
<p>Is the error I get. I am on windows and the version I have installed for FFmpeg is 6.1.1.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/5/c/5c6248c2905b59e297694ca713c09a9c7010b06d.png" data-download-href="https://discuss.pytorch.org/uploads/default/5c6248c2905b59e297694ca713c09a9c7010b06d" title="ffmpeg"><img src="https://discuss.pytorch.org/uploads/default/original/3X/5/c/5c6248c2905b59e297694ca713c09a9c7010b06d.png" alt="ffmpeg" data-base62-sha1="dbgv0XkImQjgcorFOxVnc7TcH8x" width="690" height="295" data-dominant-color="11315F"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">ffmpeg</span><span class="informations">849×363 10.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
I have tried to look this up but I cannot find anyone with a similar issue. I am on windows 10 too, any help would be appreciated.<br>
Thank you.</p>

username: nitta
cooked: <p>I have the same probrem. I turn on DEBUG msg.</p>
<pre><code class="lang-auto">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.
</code></pre>

username: nitta
cooked: <p><a href="https://pytorch.org/audio/2.3.0/installation.html" rel="noopener nofollow ugc">Installing pre-built binaries — Torchaudio 2.3.0 documentation (pytorch.org)</a></p>
<blockquote>
<p>When searching for FFmpeg installation, TorchAudio looks for library files which have names with version numbers. That is, <code>libavutil.so.&lt;VERSION&gt;</code> for Linux, <code>libavutil.&lt;VERSION&gt;.dylib</code> for macOS, and <code>avutil-&lt;VERSION&gt;.dll</code> for Windows.</p>
</blockquote>

username: FurkanGozukara
cooked: <p><a class="mention" href="/u/nitta">@nitta</a> so how do we install those on windows?</p>

username: FurkanGozukara
cooked: <p>I can’t find a way to install these on windows python 3.10 venv please help</p>
<p>ty</p>
<aside class="onebox stackexchange" data-onebox-src="https://stackoverflow.com/questions/79280663/how-to-download-ffmpeg-utilities-into-python-venv-with-pip-or-manual-way-for-tor">
  <header class="source">

      <a href="https://stackoverflow.com/questions/79280663/how-to-download-ffmpeg-utilities-into-python-venv-with-pip-or-manual-way-for-tor" target="_blank" rel="noopener nofollow ugc">stackoverflow.com</a>
  </header>

  <article class="onebox-body">
      <a href="https://stackoverflow.com/users/310370/furkan-g%c3%b6z%c3%bckara" target="_blank" rel="noopener nofollow ugc">
    <img alt="Furkan G&amp;#246;z&amp;#252;kara" src="https://i.sstatic.net/v83Lhiyo.jpg?s=256" class="thumbnail onebox-avatar" width="256" height="256">
  </a>

<h4>
  <a href="https://stackoverflow.com/questions/79280663/how-to-download-ffmpeg-utilities-into-python-venv-with-pip-or-manual-way-for-tor" target="_blank" rel="noopener nofollow ugc">How to download ffmpeg utilities into Python venv with pip or manual way for torchaudio</a>
</h4>

<div class="tags">
  <strong>python, ffmpeg, pip, python-venv</strong>
</div>

<div class="date">
  asked by
  
  <a href="https://stackoverflow.com/users/310370/furkan-g%c3%b6z%c3%bckara" target="_blank" rel="noopener nofollow ugc">
    Furkan G&amp;#246;z&amp;#252;kara
  </a>
  on <a href="https://stackoverflow.com/questions/79280663/how-to-download-ffmpeg-utilities-into-python-venv-with-pip-or-manual-way-for-tor" target="_blank" rel="noopener nofollow ugc">12:57PM - 14 Dec 24 UTC</a>
</div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


username: Papier101
cooked: <p>You can install shared FFmpeg e.g. using winget: <code>winget install --id=Gyan.FFmpeg.Shared -v "6.1.1" -e</code>, ensure ffmpeg is on PATH with the correct version. Then torchaudio should find the necessary files.</p>