pytorch / audio

Data manipulation and transformation for audio signal processing, powered by PyTorch
https://pytorch.org/audio
BSD 2-Clause "Simplified" License
2.43k stars 636 forks source link

FFmpegBackend failed to load .wav files that contain 30 channels. #3718

Open ease-zh opened 6 months ago

ease-zh commented 6 months ago

🐛 Describe the bug

FFmpegBackend failed to load .wav files that contain 30 channels, while SoxBackend works well.

Code to reproduce:

import torchaudio
print("load with sox")
wav, sr = torchaudio.load('RWCP_type2_rir_cirline_jr1_imp070.wav', backend="sox")
print(wav.shape)

print("load with ffmpeg")
wav, sr = torchaudio.load('RWCP_type2_rir_cirline_jr1_imp070.wav')
print(wav.shape)

This will get:

load with sox
torch.Size([30, 20000])
load with ffmpeg
Traceback (most recent call last):
  File "/home/zhangyi/ASV/3D-Speaker/debug.py", line 7, in <module>
    wav, sr = torchaudio.load('RWCP_type2_rir_cirline_jr1_imp070.wav')
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data_111/miniconda3/envs/tts/lib/python3.11/site-packages/torchaudio/_backend/utils.py", line 204, in load
    return backend.load(uri, frame_offset, num_frames, normalize, channels_first, format, buffer_size)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data_111/miniconda3/envs/tts/lib/python3.11/site-packages/torchaudio/_backend/ffmpeg.py", line 336, in load
    return load_audio(os.path.normpath(uri), frame_offset, num_frames, normalize, channels_first, format)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data_111/miniconda3/envs/tts/lib/python3.11/site-packages/torchaudio/_backend/ffmpeg.py", line 100, in load_audio
    return torch.ops.torchaudio.compat_load(src, format, filter, channels_first)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data_111/miniconda3/envs/tts/lib/python3.11/site-packages/torch/_ops.py", line 692, in __call__
    return self._op(*args, **kwargs or {})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Failed to create input filter: "time_base=1/16000:sample_rate=16000:sample_fmt=s16:channel_layout=0x0" (Invalid argument)

This wav comes from the RIR datasets. RWCP_type2_rir_cirline_jr1_imp070.zip

Versions

PyTorch version: 2.1.2+cu121 Is debug build: False CUDA used to build PyTorch: 12.1 ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.3 LTS (x86_64) GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 Clang version: Could not collect CMake version: version 3.22.1 Libc version: glibc-2.35

Python version: 3.11.6 | packaged by conda-forge | (main, Oct 3 2023, 10:40:35) [GCC 12.3.0] (64-bit runtime) Python platform: Linux-5.15.0-88-generic-x86_64-with-glibc2.35 Is CUDA available: True CUDA runtime version: 12.1.66 CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090 GPU 1: NVIDIA GeForce RTX 3090 GPU 2: NVIDIA GeForce RTX 3090 GPU 3: NVIDIA GeForce RTX 3090

Nvidia driver version: 535.129.03 cuDNN version: Probably one of the following: /usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.7 /usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.7 /usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.7 /usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.7 /usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.7 /usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.7 /usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.7 HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 46 bits physical, 57 bits virtual Byte Order: Little Endian CPU(s): 64 On-line CPU(s) list: 0-63 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) Gold 6326 CPU @ 2.90GHz CPU family: 6 Model: 106 Thread(s) per core: 2 Core(s) per socket: 16 Socket(s): 2 Stepping: 6 CPU max MHz: 3500.0000 CPU min MHz: 800.0000 BogoMIPS: 5800.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 1.5 MiB (32 instances) L1i cache: 1 MiB (32 instances) L2 cache: 40 MiB (32 instances) L3 cache: 48 MiB (2 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0-15,32-47 NUMA node1 CPU(s): 16-31,48-63 Vulnerability Gather data sampling: Mitigation; Microcode Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

Versions of relevant libraries: [pip3] mypy-extensions==1.0.0 [pip3] numpy==1.26.1 [pip3] torch==2.1.2 [pip3] torchaudio==2.1.2 [pip3] torchvision==0.16.2 [pip3] triton==2.1.0 [conda] numpy 1.26.1 pypi_0 pypi [conda] torch 2.1.2 pypi_0 pypi [conda] torchaudio 2.1.2 pypi_0 pypi [conda] torchvision 0.16.2 pypi_0 pypi [conda] triton 2.1.0 pypi_0 pypi

mthrok commented 6 months ago

AFAIK, this is the limitation of FFmpeg. FFmpeg handles audio channels in term of channel layout, instead of the number of channels, and there is no channel layout that support 30-channels.

gau-nernst commented 1 month ago

Facing the same issue! backend="soundfile" also works.

faroit commented 1 month ago

@mthrok i don't think an unknown channel layout would prevent ffmpeg to decode a 30ch file.

In fact, here is a test:

# creates 30ch wav file
sox -n -r 44100 -c 30 sine30ch.wav synth 12 sine
# decodes file with ffmpeg
ffmpeg -benchmark_all -loglevel debug -i sine30ch.wav out.wav

results in

Input file #0 (sine30ch.wav):
  Input stream #0:0 (audio): 15565 packets read (63504000 bytes); 15565 frames decoded (529200 samples);
  Total: 15565 packets (63504000 bytes) demuxed
Output file #0 (out.wav):
  Output stream #0:0 (audio): 15565 frames encoded (529200 samples); 15565 packets muxed (31752000 bytes);
  Total: 15565 packets (31752000 bytes) muxed
15565 frames successfully decoded, 0 decoding errors

so this should also work in torchaudio