PyAV icon indicating copy to clipboard operation
PyAV copied to clipboard

Allow way to get real aspect ratio

Open animetosho opened this issue 1 year ago • 0 comments

Overview

video.display_aspect_ratio and video.sample_aspect_ratio don't always return the correct values.

Reproduction

Using the following script:

import av
import sys

container = av.open(sys.argv[1])
video = next(s for s in container.streams if s.type == 'video')
print(video.display_aspect_ratio)
print(video.sample_aspect_ratio)

Sample file 1 output:

# python3 test.py 000fd474_9930.mkv
4/3
3/4
# ffprobe -hide_banner 000fd474_9930.mkv
Input #0, matroska,webm, from '000fd474_9930.mkv':
  Metadata:
    ENCODER         : Lavf58.76.100
  Duration: 00:00:00.04, bitrate: 47051 kb/s
  Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 3:4 DAR 4:3], SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Metadata:
      DURATION        : 00:00:00.041000000

Sample file 2 output:

# python3 test.py 00115c29_11730.mkv
None
None
# ffprobe -hide_banner 00115c29_11730.mkv
[libdav1d @ 0x561c7adb3280] libdav1d 0.9.1
Input #0, matroska,webm, from '00115c29_11730.mkv':
  Metadata:
    ENCODER         : Lavf58.76.100
  Duration: 00:00:00.04, start: 0.000000, bitrate: 45895 kb/s
  Stream #0:0: Video: av1 (Main), yuv420p10le(tv, bt709), 1440x1080 [SAR 1:1 DAR 4:3], SAR 4:3 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn, 1k tbc (default)
    Metadata:
      DURATION        : 00:00:00.041000000
[libdav1d @ 0x561c7adb62c0] libdav1d 0.9.1

It looks like these files have two aspect ratios (stream and container ratios perhaps?), with the second being the 'correct' one, but PyAV reports the first.
It would be useful if PyAV could report the second (i.e. ideal) aspect ratio, either by changing video.*_aspect_ratio or through some other mechanism.

Versions

  • OS: Debian 12
  • PyAV runtime:
PyAV v10.0.0
library configuration: --prefix=/usr --extra-version=0+deb12u1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libglslang --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librist --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --disable-sndio --enable-libjxl --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-libplacebo --enable-librav1e --enable-shared
library license: GPL version 2 or later
libavcodec     59. 37.100
libavdevice    59.  7.100
libavfilter     8. 44.100
libavformat    59. 27.100
libavutil      57. 28.100
libswresample   4.  7.100
libswscale      6.  7.100
  • FFprobe:
ffprobe version 4.4.4 Copyright (c) 2007-2023 the FFmpeg developers
built with gcc 10 (Debian 10.2.1-6)

animetosho avatar Jan 30 '24 01:01 animetosho