vision icon indicating copy to clipboard operation
vision copied to clipboard

Video Reader's get_metadata function fails on videos with sound

Open NSalberg opened this issue 1 year ago • 4 comments

🐛 Describe the bug

from torchvision.io import VideoReader
reader = VideoReader("never.mp4", "video")

metadata = reader.get_metadata()

With the previous code this error occurs:

File "/home/name/dev/reader_test/main.py", line 6, in <module>
    metadata = reader.get_metadata()
  File "/home/name/dev/reader_test/.venv/lib/python3.10/site-packages/torchvision/io/video_reader.py", line 254, in get_metadata
    rate = stream.average_rate if stream.average_rate is not None else stream.sample_rate
  File "av/stream.pyx", line 120, in av.stream.Stream.__getattr__
AttributeError: 'av.audio.codeccontext.AudioCodecContext' object has no attribute 'average_rate'

This occurs because av.audio.codeccontext.AudioCodecContext does not have the attribute average_rate

A solution could be to check if the stream is a video before adding assigning average_rate to rate

Here's the output of running ffprobe on the video file:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'never.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2024-01-26T06:10:35.000000Z
  Duration: 00:03:32.04, start: 0.000000, bitrate: 762 kb/s
  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 630 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2024-01-26T06:10:35.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 01/25/2024.
      vendor_id       : [0][0][0][0]
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2024-01-26T06:10:35.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 01/25/2024.
      vendor_id       : [0][0][0][0]```


### Versions

Collecting environment information...
PyTorch version: 2.3.0+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: Could not collect
Libc version: glibc-2.35

Python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-5.15.146.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1060 6GB
Nvidia driver version: 536.99
cuDNN version: Could not collect
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:                      39 bits physical, 48 bits virtual
Byte Order:                         Little Endian
CPU(s):                             6
On-line CPU(s) list:                0-5
Vendor ID:                          GenuineIntel
Model name:                         Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
CPU family:                         6
Model:                              158
Thread(s) per core:                 1
Core(s) per socket:                 6
Socket(s):                          1
Stepping:                           10
BogoMIPS:                           5808.01
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi ept vpid ept_ad fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves md_clear flush_l1d arch_capabilities
Virtualization:                     VT-x
Hypervisor vendor:                  Microsoft
Virtualization type:                full
L1d cache:                          192 KiB (6 instances)
L1i cache:                          192 KiB (6 instances)
L2 cache:                           1.5 MiB (6 instances)
L3 cache:                           9 MiB (1 instance)
Vulnerability Gather data sampling: Unknown: Dependent on hypervisor status
Vulnerability Itlb multihit:        KVM: Mitigation: VMX disabled
Vulnerability L1tf:                 Mitigation; PTE Inversion; VMX conditional cache flushes, SMT disabled
Vulnerability Mds:                  Mitigation; Clear CPU buffers; SMT Host state unknown
Vulnerability Meltdown:             Mitigation; PTI
Vulnerability Mmio stale data:      Mitigation; Clear CPU buffers; SMT Host state unknown
Vulnerability Retbleed:             Mitigation; IBRS
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; IBRS, IBPB conditional, STIBP disabled, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:                Unknown: Dependent on hypervisor status
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] torch==2.3.0
[pip3] torchvision==0.18.0
[pip3] triton==2.3.0
[conda] No relevant packages

NSalberg avatar May 09 '24 23:05 NSalberg

image same

drimeF0 avatar Jun 05 '24 08:06 drimeF0

same

FelipeMarra avatar Jun 05 '24 15:06 FelipeMarra

anyone got this resolved?

plnguyen2908 avatar Jun 21 '24 05:06 plnguyen2908

Try using a Conda environment. Besides torch still not being able to find my GPU, at least this error ain't showing up for me anymore.

FelipeMarra avatar Jun 24 '24 14:06 FelipeMarra

I've been encountering this bug, too, using pytorch==2.4 with both av==10.0.0 and av==12.3.0 (the latest version as of writing this comment). Luckily, it's quite trivial to fix, so I've submitted a quick PR.

stefan-baumann avatar Jul 28 '24 19:07 stefan-baumann

Thanks all for the reports. This should hopefully be fixed by @stefan-baumann 's https://github.com/pytorch/vision/pull/8548. This will be available in the next version within a few months.

NicolasHug avatar Jul 29 '24 15:07 NicolasHug