Opened 3 hours ago

Last modified 14 minutes ago

#11279 new defect

Aspect ratio defined by the PNG resolution chunk “pHYs” is misinterpreted as its reciprocal

Reported by: goodbye Owned by:
Priority: normal Component: avcodec
Version: git-master Keywords: png
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by goodbye)

The PNG pHYs chunk describes the resolution/pixel density of an image, which can be in abstract units (in which case it only defines the pixel aspect ratio) or in pixels per metre.

FFmpeg interprets the X:Y resolution ratio directly as a X:Y PAR, but in actuality, it’s the reciprocal. This is because the resolution is specified as a “pixels per unit” value and not “units per pixel”, as is typically the case with PARs. The X:Y PAR is equal to the Y:X ratio of resolutions specified in the chunk.

Both of these images, from the libpng test suite, are supposed to have a DAR of 1:1, but FFmpeg misinterprets them to have DARs of 16:1 and 1:16:

The issue has been present from the very beginning, since parsing the pHYs chunk was introduced in commit 8288c2b6cb072b61f664bc8ab4c1b0a5a8db0ead, and is still present as of commit 1864025458021a2d2c542f56e268ee1106f84460 (libavcodec/pngdec.c lines 648–649)

The PNG encoder has the complementary problem of writing a reciprocal ratio into the pHYs chunk, introduced with commit f58f90238fc63090da34c9fdb1d06d724d929f6d (now libavcodec/pngenc.c lines 394–395)

Change History (4)

comment:1 by goodbye, 72 minutes ago

Component: undeterminedavcodec
Description: modified (diff)
Version: 7.1git-master

comment:2 by goodbye, 56 minutes ago

Description: modified (diff)

comment:3 by goodbye, 55 minutes ago

Description: modified (diff)

comment:4 by Balling, 14 minutes ago

As I understand Chrome shows it correctly, right? First link is horizontal image, and second is vertical.

Note: See TracTickets for help on using tickets.