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

ffmpeg extension fails with unexpected options: threads for encoders that natively do not support threading. #3893

Open
JacekDuszenko opened this issue Mar 20, 2025 · 0 comments

Comments

@JacekDuszenko
Copy link

🐛 Describe the bug

Torchaudio ffmpeg cpp extension crashes when used with encoders that do not have threading capabilities e.g. mulaw. Easily reproducable by running the following script:

import io

from torchaudio.io import StreamReader

wave_i2_data = b"".join(
    [
        b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
        b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
    ]
)

io_bytes = io.BytesIO(wave_i2_data)
s = StreamReader(
    src=io_bytes,
    format="s16le",
    option={"sample_rate": str(8000)},
)
s.add_basic_audio_stream(
    frames_per_chunk=1024,
    sample_rate=8000,
    format="s16p",
    decoder="pcm_mulaw",
    decoder_option=None,
    num_channels=1,
)

Fails with:

  File "repro.py", line 18, in <module>
    s.add_basic_audio_stream(
  File ".venv/lib/python3.10/site-packages/torio/io/_streaming_media_decoder.py", line 681, in add_basic_audio_stream
    self.add_audio_stream(
  File ".venv/lib/python3.10/site-packages/torio/io/_streaming_media_decoder.py", line 778, in add_audio_stream
    self._be.add_audio_stream(
RuntimeError: Unexpected options: threads

The reason for that is the code sets the threads entry unconditionally in

if (!av_dict_get(opts, "threads", nullptr, 0)) {

while codecs without support for threading do not delete the entry afterwards. To fix the 'threads' keyword need to be deleted manually.

Versions

PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: macOS 15.2 (arm64)
GCC version: Could not collect
Clang version: 16.0.0 (clang-1600.0.26.6)
CMake version: version 3.31.6
Libc version: N/A

Python version: 3.10.16 (main, Feb 12 2025, 15:03:04) [Clang 19.1.6 ] (64-bit runtime)
Python platform: macOS-15.2-arm64-arm-64bit
Is CUDA available: N/A
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

CPU:
Apple M4 Max

Versions of relevant libraries:
[pip3] numpy==1.26.4
[conda] Could not collect

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

1 participant