torchaudio: Failed to intialize FFmpeg extension (fix)
ImportError: Failed to intialize FFmpeg extension. Tried versions: ['6', '5', '4', ''] (torchaudio's spelling) means torchaudio found no FFmpeg it was built for. On torchaudio 2.8.0 we got it with no FFmpeg and with FFmpeg 7 installed; FFmpeg 6 fixed it.
1. The error
torch and torchaudio 2.8.0, reading a 1-second WAV with StreamReader:
from torchaudio.io import StreamReader
r = StreamReader("tone.wav")
r.add_basic_audio_stream(frames_per_chunk=16000)
for (chunk,) in r.stream():
print(chunk.shape)
With no FFmpeg installed:
Traceback (most recent call last):
...
File ".../site-packages/torio/_extension/utils.py", line 122, in _find_ffmpeg_extension
raise ImportError(
ImportError: Failed to intialize FFmpeg extension. Tried versions: ['6', '5', '4', '']. Enable DEBUG logging to see more details about the error.
Then with conda-forge FFmpeg 7 shared libraries on LD_LIBRARY_PATH: exactly the same error. The list ['6', '5', '4', ''] is the hint: torchaudio 2.8.0 only has extensions built for FFmpeg 4, 5 and 6, and FFmpeg 7 (libavcodec.so.61) is not one of them. Current apt/brew/conda installs often give you 7 or 8.
2. Fix: install FFmpeg 6 (or 5, 4) shared libraries
We had no root, so we put conda-forge FFmpeg 6 in a micromamba prefix:
micromamba create -p ./ff6 -c conda-forge "ffmpeg=6"
LD_LIBRARY_PATH=./ff6/lib python b4.py
b4.py:2: UserWarning: torio.io._streaming_media_decoder.StreamingMediaDecoder has been deprecated. This deprecation is part of a large refactoring effort to ...
r = StreamReader("tone.wav")
torch.Size([16000, 1])
Same venv, same script; only the FFmpeg major version changed (libavcodec.so.60). In a conda env, conda install -c conda-forge "ffmpeg<7" does the same without LD_LIBRARY_PATH. On Windows you need the shared (DLL) build.
3. Or move to torchaudio 2.9 + TorchCodec
The warning above says StreamReader is deprecated; torchaudio 2.9 removed torchaudio.io, and TorchCodec (which accepts FFmpeg 4–8) replaces it. Tested code: No module named torchaudio.io. TorchCodec has its own load error if FFmpeg or versions are wrong: Could not load libtorchcodec.
Related: No module named torchaudio.backend · torchaudio has no attribute info
Frequently asked questions
Why does it fail even though FFmpeg is installed?
In our test torchaudio 2.8.0 tried only FFmpeg 6, 5 and 4. With FFmpeg 7 libraries it raised the same ImportError as with none; FFmpeg 6 worked.
Is it intialize or initialize?
torchaudio prints "intialize" (sic). Search engines also match "Failed to initialize FFmpeg extension"; it is the same error.
Written with AI assistance. Measured on 2026-10-24 on Linux with CPython 3.11.17, torch/torchaudio 2.8.0 (PyPI wheels), conda-forge FFmpeg 6 and 7. Output pasted unedited except shortened site-packages paths, a cut traceback and shortened warning lines. PlainTables is our extension; torchaudio and FFmpeg are free.