Cannot load torchcodec

May be a version issue with ffmpeg in the Windows environment.


Diagnosis: Windows cannot find compatible FFmpeg DLLs for TorchCodec, or your Torch↔TorchCodec versions don’t match. The probe core7 → core6 → core5 → core4 failing is TorchCodec’s normal fallback when the FFmpeg runtime it needs isn’t available. (GitHub)

Causes

  • FFmpeg runtime DLLs missing or not discoverable. Having ffmpeg.exe on PATH is not enough; the loader must see avcodec-*.dll, avformat-*.dll, avutil-*.dll. (docs.pytorch.org)

  • Unsupported FFmpeg major on Windows. TorchCodec supports FFmpeg 4–7 on all platforms and FFmpeg 8 on macOS/Linux. Using 8 on Windows fails with current wheels. (GitHub)

  • Torch↔TorchCodec mismatch or RC/nightly torch. Follow the version matrix: 0.8 ↔ torch 2.9, 0.7 ↔ torch 2.8, Python 3.10–3.13. Mismatches trigger the exact error you pasted. (GitHub)

  • Homebrew or custom FFmpeg builds with incompatible layouts (mac users). Known incompatibility reported; conda-forge FFmpeg works. (GitHub)

Fixes (pick one path, do it end-to-end)

A) Windows, CPU-only, stable


# fresh venv

python -m venv .venv

.\.venv\Scripts\Activate.ps1

pip install -U pip

# choose a matched pair (pick one)

pip install "torch==2.9.*" "torchcodec==0.8.*"

# or

# pip install "torch==2.8.*" "torchcodec==0.7.*"

# install shared FFmpeg DLLs via conda-forge (<8 on Windows)

# run this in an Anaconda/Miniconda prompt

conda install -y -c conda-forge "ffmpeg<8"

# make DLLs visible to Python (adjust path to your conda root)

set PATH=C:\Miniconda3\Library\bin;%PATH%

# sanity checks

python - <<'PY'

import torch, torchcodec, platform, subprocess

print("torch", torch.__version__, "torchcodec", torchcodec.__version__, "py", platform.python_version())

subprocess.run(["ffmpeg","-version"], check=True)

PY

Why this works: TorchCodec requires FFmpeg 4–7 on Windows and matched Torch↔TorchCodec versions; conda-forge provides the needed DLLs in Library\bin. (GitHub)

B) Windows, CUDA

Use conda for both Torch and TorchCodec and conda-forge FFmpeg.


conda create -n tcuda python=3.10 -y

conda activate tcuda

# install torch for your CUDA per pytorch.org

conda install -c conda-forge "ffmpeg<8"

conda install -c conda-forge "torchcodec=*=*cuda*"

Windows CUDA support is experimental and conda-first in the docs. (GitHub)

C) macOS/Linux notes

If you used Homebrew FFmpeg on mac and see the same error, switch to conda-forge FFmpeg. FFmpeg 8 is supported on macOS/Linux starting TorchCodec 0.8. (GitHub)

Quick triage checks

  • Print versions. If they don’t match the table, reinstall with a supported pair.

python -c "import torch,torchcodec,platform;print(torch.__version__, torchcodec.__version__, platform.python_version())" (GitHub)

  • Confirm FFmpeg runtime is on PATH for the same shell that launches Python.

ffmpeg -version should succeed. If it does but TorchCodec still fails, you likely pointed to a static or CLI-only FFmpeg without DLLs. (docs.pytorch.org)

  • Avoid RC/nightly Torch with stable TorchCodec; #912 documents the loader error with 2.9 RC. (GitHub)

Minimal workaround if you can’t fix FFmpeg now

Preconvert MP3 → WAV and pass the WAV to your pipeline:


ffmpeg -i lsy_audio_2023_58s.mp3 -ar 16000 -ac 1 -y lsy_audio_2023_58s.wav

This sidesteps MP3 decoding but does not fix the root cause. (GitHub)

Context and background

  • TorchCodec loads FFmpeg at runtime and tries majors 7→6→5→4. The error you saw is the expected probe sequence when the needed FFmpeg DLLs are missing or incompatible. The README and downstream reports show the same pattern. (GitHub)

  • Windows support is recent and labeled beta; the releases and Windows tracker call out rough edges. Expect stricter version discipline. (GitHub)

Short, curated references

Primary docs

  • TorchCodec README: FFmpeg 4–7 on all platforms, 8 on macOS/Linux; version matrix; Windows notes. (GitHub)

  • Torchaudio install page: how to install FFmpeg and how discovery works on Windows. (docs.pytorch.org)

Issue reports matching your symptoms

  • HF Datasets 4.0: exact Could not load libtorchcodec probe trace when FFmpeg libs are missing or versions mismatch. (GitHub)

  • TorchCodec #912: loader failure with Torch 2.9 RC. Confirms mismatch cause. (GitHub)

  • macOS Homebrew FFmpeg incompatibility: use conda-forge FFmpeg. (GitHub)