Opened 3 years ago

Closed 3 years ago

#9497 closed defect (fixed)

ffmpeg reports wrong display aspect ratio (DAR) for matroska files.

Reported by: Rikitiki Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: mkv
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: yes

Description

ffmpeg reports wrong display aspect ratio (DAR) for matroska files.

If DAR is 160:67 then ffprobe displays:

            "sample_aspect_ratio": "90:67",
            "display_aspect_ratio": "160:67",

and mkvinfo displays:

|   + Display width: 160
|   + Display height: 67

If DAR is 161:67 then ffprobe displays:

            "sample_aspect_ratio": "123:91",
            "display_aspect_ratio": "656:273",

and mkvinfo displays:

|   + Display width: 161
|   + Display height: 67

A matroska file is created by mkvmerge from raw h264 stream. The h264 stream is created by ffmpeg from bmp files.

How to reproduce:

  1. unpack attcahed file
  2. replace VAR_FFMPEG_BINS & MKVMERGE_BINS to right location of the tools
  3. execute run.cmd to obtain output

Pay attention to CASE_1 & CASE_2 texts to change input DAR

ffmpeg version: ffmpeg-4.4.1-full_build
mkvmerge version: mkvtoolnix-64-bit-62.0.0

Attachments (3)

badout.txt (46.4 KB ) - added by Rikitiki 3 years ago.
goodout.txt (46.5 KB ) - added by Rikitiki 3 years ago.
ffmpegbug.zip (15.7 KB ) - added by Rikitiki 3 years ago.

Download all attachments as: .zip

Change History (9)

by Rikitiki, 3 years ago

Attachment: badout.txt added

by Rikitiki, 3 years ago

Attachment: goodout.txt added

by Rikitiki, 3 years ago

Attachment: ffmpegbug.zip added

comment:1 by Gyan, 3 years ago

Resolution: wontfix
Status: newclosed

Matroska stores DisplayWidth and DisplayHeight. ffmpeg stores Sample Aspect Ratio in its internal contexts. The former is the effective ratio of the displayed dimensions. The latter is the 'scale factor' to be applied to the decoder output for processing or display purposes. When converting the former to SAR, rounding may occur. Which in turn, may lead to a slightly different DAR computed by ffmpeg.

comment:2 by Rikitiki, 3 years ago

Resolution: wontfix
Status: closedreopened

To prevent the rounding, can ffmpeg store Sample Aspect Ratio in its internal contexts as rational number? Something like https://www.boost.org/doc/libs/1_77_0/libs/rational/rational.html or https://docs.python.org/3/library/fractions.html.

comment:3 by Gyan, 3 years ago

Resolution: wontfix
Status: reopenedclosed

It already does. It still has to be expressed as two integers.

comment:4 by Rikitiki, 3 years ago

Resolution: wontfix
Status: closedreopened

If it is expressed as two integers (as fractional) then rounding errors, mentioned early by you, must not exist. So must be

"display_aspect_ratio": "161:67",

instead

"display_aspect_ratio": "656:273",

...

comment:5 by mkver, 3 years ago

Analyzed by developer: set
Component: undeterminedavformat
Keywords: mkv added
Reproduced by developer: set
Version: unspecifiedgit-master

comment:6 by mkver, 3 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.