get display aspect ratio of video? [closed]

asked 2017-08-16 03:11:55 -0600

jms gravatar image

updated 2017-08-22 07:57:27 -0600

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]

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by jms
close date 2017-08-22 04:16:40.714918

Comments

why do you think, it has an aspect ratio of 16:9 ? (1440x1080 would be 4:3)

berak gravatar imageberak ( 2017-08-16 03:34:33 -0600 )edit

DAR does not matter in computer-vision.

berak gravatar imageberak ( 2017-08-22 03:35:48 -0600 )edit

playing the video with VLC it appears as 16:9 and looks good.

jms gravatar imagejms ( 2017-08-22 03:36:02 -0600 )edit

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.

jms gravatar imagejms ( 2017-08-22 03:42:37 -0600 )edit

unfortunately, the DAR information is discarded while opening the file. (you cannot access it via VideoCapture)

berak gravatar imageberak ( 2017-08-22 03:59:47 -0600 )edit