get display aspect ratio of video? [closed]
In python I process a mp4 video with
stream = cv2.VideoCapture(filename)
The video has a resolution of 1440x1080 and a SAR of 4:3, but a display aspect ratio (DAR) of 16:9. This is how it comes from my sony camera. To preserve the display aspect ratio, I need to know it. How can I get the display aspect ratio with OpenCV? ffmpeg -i tells me this:
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/iec61966-2-4), 1440x1080 [SAR 4:3 DAR 16:9]
why do you think, it has an aspect ratio of 16:9 ? (1440x1080 would be 4:3)
DAR does not matter in computer-vision.
playing the video with VLC it appears as 16:9 and looks good.
If I read a mp4 video with SAR 4:3 and DAR 16:9 and I store or replay video frames without knowing the DAR, the DAR is lost and the video frames are displayed at 4:3 and so are distorted.
unfortunately, the DAR information is discarded while opening the file. (you cannot access it via VideoCapture)