Skip to content

Commit

Permalink
Don't use Identity matrix coefficients with 4:0:0
Browse files Browse the repository at this point in the history
Chrome doesn't render 4:0:0 with Identity matrix coefficients
correctly. Work around this Chrome issue by using matrix coefficients 6
instead with lossless 4:0:0.

Fix AOMediaCodec#1481.
  • Loading branch information
wantehchang committed Jul 27, 2023
1 parent 2f25613 commit 2fe5ab8
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions apps/avifenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1625,12 +1625,10 @@ int main(int argc, char * argv[])
image->alphaPremultiplied = premultiplyAlpha;

if ((image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_IDENTITY) && (input.requestedFormat != AVIF_PIXEL_FORMAT_NONE) &&
(input.requestedFormat != AVIF_PIXEL_FORMAT_YUV444) && (input.requestedFormat != AVIF_PIXEL_FORMAT_YUV400)) {
// User explicitly asked for non YUV444/YUV400 yuvFormat, while
// matrixCoefficients was likely set to
// AVIF_MATRIX_COEFFICIENTS_IDENTITY as a side effect of --lossless, and
// Identity is only valid with YUV444/YUV400. Set matrixCoefficients
// back to the default.
(input.requestedFormat != AVIF_PIXEL_FORMAT_YUV444)) {
// User explicitly asked for non YUV444 yuvFormat, while matrixCoefficients was likely
// set to AVIF_MATRIX_COEFFICIENTS_IDENTITY as a side effect of --lossless,
// and Identity is only valid with YUV444. Set matrixCoefficients back to the default.
image->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_BT601;

if (cicpExplicitlySet) {
Expand Down Expand Up @@ -1663,8 +1661,7 @@ int main(int argc, char * argv[])
}

// Check again for y4m input (y4m input ignores input.requestedFormat and retains the format in file).
if ((image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_IDENTITY) && (image->yuvFormat != AVIF_PIXEL_FORMAT_YUV444) &&
(image->yuvFormat != AVIF_PIXEL_FORMAT_YUV400)) {
if ((image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_IDENTITY) && (image->yuvFormat != AVIF_PIXEL_FORMAT_YUV444)) {
fprintf(stderr, "matrixCoefficients may not be set to identity (0) when subsampling.\n");
returnCode = 1;
goto cleanup;
Expand Down

0 comments on commit 2fe5ab8

Please sign in to comment.