Open
@jamesTSCoop

Description

Hi, I'm encountering a decoding error on a vorbis audio file that can be played:

Error decoding file orig.ogg: Could not push packet to decoder: Invalid data found when processing input

I'm mentioning this because issues #505 and #165 are lacking example data, which I can provide below.

My code is pretty simple, just scanning through the file with decoder.get_samples_played_in_range(). I wasn't able to find any clear examples of through huge (24 hour in this case) audio files, so if this isn't the recommended way of doing it, please let me know! For instance, at first I set my loop to break when 0 == samples.duration_seconds but that actually never happens, the call to get_samples_played_in_range() that would return zero actually fails with an error because the time index isn't "within" the file. I'm curious about this, because it implies that for a file that happens to end exactly at stop_seconds of a get_samples_played_in_range() call there is no way to know that without receiving an error.

# --- Configuration ---
SEG_SIZ = 64 # Megabytes we expect a chunk from streamaudio to be.
CPU_SIZ = os.cpu_count() # Use all available CPU cores for decoding.
CPU_HEADROOM = 3 # Ensure there's always CPU work to do while using the GPU.

# global so they will be inherited via fork.
global cpu_sem
global gpu_lock

cpu_sem = Semaphore(CPU_SIZ)
gpu_lock = Lock()

# --- Decoding Function for Pool Workers ---
def decode_audio_segment(infile):

    print(f"Worker {os.getpid()} decoding {infile}")
    try:
        cpu_sem.acquire()
        decoder = AudioDecoder(infile)
        print(f"medadata: {decoder.metadata}")
        sr = decoder.metadata.sample_rate
        ch = decoder.metadata.num_channels
        frames = sr* decoder.metadata.duration_seconds_from_header

        #l
        # number of seconds that will fit in a SEG_SIZ tensor.
        #
        incr_sec = (SEG_SIZ*1024*1024)/(sr*ch)
        stop_sec = incr_sec
        start_sec = 0
        dtime = 0

        while True:

            print(f"start_sec: {start_sec} stop_sec: {stop_sec}")
            samples = decoder.get_samples_played_in_range(start_sec, stop_sec)
            print(f"sample info: {samples}")
            dtime += [samples.duration_seconds](url)
            cpu_sem.release()

            with gpu_lock:
                gtime *= -1
                gtime += time.time()

                # Do GPU stuff

            cpu_sem.acquire()

            start_sec += samples.duration_seconds
            stop_sec = start_sec + incr_sec

            # If samples[duration] was not what we asked for we're at the
            # end of the file
            if incr_sec != samples.duration_seconds:
                break

        cpu_sem.release()

For the linked file orig.ogg I get the below output:

Server listening on 0.0.0.0:2345...
Worker 1419 decoding /mnt/media/jam/audio/livingroom/20241113.074825-jaM-livingroom.ogg
medadata: AudioStreamMetadata:
  duration_seconds_from_header: 11131.08898
  begin_stream_seconds_from_header: 0.0
  bit_rate: 64000.0
  codec: vorbis
  stream_index: 0
  sample_rate: 44100
  num_channels: 1
  sample_format: fltp

start_sec: 0 stop_sec: 1521.742947845805
sample info: AudioSamples:
  data (shape): torch.Size([1, 67108864])
  pts_seconds: 0.0
  duration_seconds: 1521.742947845805
  sample_rate: 44100

start_sec: 1521.742947845805 stop_sec: 3043.48589569161
Error decoding file /mnt/media/jam/audio/livingroom/20241113.074825-jaM-livingroom.ogg: Could not push packet to decoder: Invalid data found when processing input

A quick scan of the torchcodec source implies that the Invalid data found when processing input part is actually coming from ffmpeg and that's all that I can determine. If I "transcode" the file with ffmpeg -i orig.ogg fixed.ogg the transcoded file, also linked below, is properly decoded by torchcodec.

https:///file/d/1fZTb3xWhNgpu6Eh8S-EbFs74HqPorPXb/view?usp=sharing
https:///file/d/1mEWXsjfQIFrVlSvOg2zxYVSnfPEkaCLl/view?usp=drive_link

Versions

PyTorch version: 2.7.1+cu126
Is debug build: False
CUDA used to build PyTorch: 12.6
ROCM used to build PyTorch: N/A

OS: Gentoo Linux (x86_64)
GCC version: (Gentoo 12.4.0 p1) 12.4.0
Clang version: 20.1.7
CMake version: version 4.0.3
Libc version: glibc-2.41

Python version: 3.13.5 (main, Jun 12 2025, 10:58:59) [GCC 15.1.0] (64-bit runtime)
Python platform: Linux-6.1.27-gentoo-r1-x86_64-Intel-R-_Core-TM-_i9-7940X_CPU_@_3.10GHz-with-glibc2.41
Is CUDA available: True
CUDA runtime version: 12.8.93
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3070
Nvidia driver version: 570.153.02
cuDNN version: Probably one of the following:
/opt/cuda/targets/x86_64-linux/lib/libcudnn.so.9.8.0
/opt/cuda/targets/x86_64-linux/lib/libcudnn_adv.so.9.8.0
/opt/cuda/targets/x86_64-linux/lib/libcudnn_cnn.so.9.8.0
/opt/cuda/targets/x86_64-linux/lib/libcudnn_engines_precompiled.so.9.8.0
/opt/cuda/targets/x86_64-linux/lib/libcudnn_engines_runtime_compiled.so.9.8.0
/opt/cuda/targets/x86_64-linux/lib/libcudnn_graph.so.9.8.0
/opt/cuda/targets/x86_64-linux/lib/libcudnn_heuristic.so.9.8.0
/opt/cuda/targets/x86_64-linux/lib/libcudnn_ops.so.9.8.0
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, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          28
On-line CPU(s) list:             0-27
Vendor ID:                       GenuineIntel
Model name:                      Intel(R) Core(TM) i9-7940X CPU @ 3.10GHz
CPU family:                      6
Model:                           85
Thread(s) per core:              2
Core(s) per socket:              14
Socket(s):                       1
Stepping:                        4
CPU(s) scaling MHz:              60%
CPU max MHz:                     4400.0000
CPU min MHz:                     1200.0000
BogoMIPS:                        6199.99
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 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 cdp_l3 invpcid_single pti ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req md_clear flush_l1d
Virtualization:                  VT-x
L1d cache:                       448 KiB (14 instances)
L1i cache:                       448 KiB (14 instances)
L2 cache:                        14 MiB (14 instances)
L3 cache:                        19.3 MiB (1 instance)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-27
Vulnerability Itlb multihit:     KVM: Mitigation: VMX disabled
Vulnerability L1tf:              Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Mmio stale data:   Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:          Mitigation; IBRS
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; IBRS, IBPB conditional, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT vulnerable

Versions of relevant libraries:
[pip3] numpy==2.3.0
[pip3] nvidia-cublas-cu12==12.6.4.1
[pip3] nvidia-cuda-cupti-cu12==12.6.80
[pip3] nvidia-cuda-nvrtc-cu12==12.6.77
[pip3] nvidia-cuda-runtime-cu12==12.6.77
[pip3] nvidia-cudnn-cu12==9.5.1.17
[pip3] nvidia-cufft-cu12==11.3.0.4
[pip3] nvidia-curand-cu12==10.3.7.77
[pip3] nvidia-cusolver-cu12==11.7.1.2
[pip3] nvidia-cusparse-cu12==12.5.4.2
[pip3] nvidia-cusparselt-cu12==0.6.3
[pip3] nvidia-nccl-cu12==2.26.2
[pip3] nvidia-nvjitlink-cu12==12.6.85
[pip3] nvidia-nvtx-cu12==12.6.77
[pip3] onnx==1.17.0
[pip3] onnxruntime==1.22.0
[pip3] torch==2.7.1+cu126
[pip3] torchaudio==2.7.1+cu126
[pip3] torchcodec==0.4.0+cu128
[pip3] triton==3.3.1
[conda] Could not collect```