From 3bddabc6be5e5def9cee23a9cbc72ebfc9740649 Mon Sep 17 00:00:00 2001 From: Wan-Teh Chang Date: Mon, 2 Dec 2024 15:51:42 -0800 Subject: [PATCH 1/2] Write the MA1B brand correctly A partial fix for https://github.com/AOMediaCodec/libavif/issues/2514. --- src/write.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/write.c b/src/write.c index cf4e1c7932..f001d0179c 100644 --- a/src/write.c +++ b/src/write.c @@ -3134,6 +3134,7 @@ avifResult avifEncoderFinish(avifEncoder * encoder, avifRWData * output) // ----------------------------------------------------------------------- // Harvest configuration properties from sequence headers + avifBool isMA1B = AVIF_TRUE; for (uint32_t itemIndex = 0; itemIndex < encoder->data->items.count; ++itemIndex) { avifEncoderItem * item = &encoder->data->items.item[itemIndex]; if (item->encodeOutput->samples.count > 0) { @@ -3142,6 +3143,11 @@ avifResult avifEncoderFinish(avifEncoder * encoder, avifRWData * output) AVIF_CHECKERR(avifSequenceHeaderParse(&sequenceHeader, (const avifROData *)&firstSample->data, codecType), avifGetErrorForItemCategory(item->itemCategory)); item->av1C = sequenceHeader.av1C; + // The MA1B brand: The AV1 profile shall be the Main Profile and the level shall be 5.1 + // or lower. + if (item->av1C.seqProfile != 0 || item->av1C.seqLevelIdx0 > 13) { + isMA1B = AVIF_FALSE; + } } } @@ -3239,10 +3245,11 @@ avifResult avifEncoderFinish(avifEncoder * encoder, avifRWData * output) } // AVIF_CHECKRES(avifRWStreamWriteChars(&s, "mif1", 4)); // ... compatible_brands[] AVIF_CHECKRES(avifRWStreamWriteChars(&s, "miaf", 4)); // ... compatible_brands[] + if (isMA1B) { // + AVIF_CHECKRES(avifRWStreamWriteChars(&s, "MA1B", 4)); // ... compatible_brands[] + } // if ((imageMetadata->depth == 8) || (imageMetadata->depth == 10)) { // - if (imageMetadata->yuvFormat == AVIF_PIXEL_FORMAT_YUV420) { // - AVIF_CHECKRES(avifRWStreamWriteChars(&s, "MA1B", 4)); // ... compatible_brands[] - } else if (imageMetadata->yuvFormat == AVIF_PIXEL_FORMAT_YUV444) { // + if (imageMetadata->yuvFormat == AVIF_PIXEL_FORMAT_YUV444) { // AVIF_CHECKRES(avifRWStreamWriteChars(&s, "MA1A", 4)); // ... compatible_brands[] } } From 5fd0303b477a76b5f90713ab8d44b4f068e57396 Mon Sep 17 00:00:00 2001 From: Wan-Teh Chang Date: Mon, 2 Dec 2024 15:56:23 -0800 Subject: [PATCH 2/2] Run clang-format --- src/write.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/write.c b/src/write.c index f001d0179c..7896163017 100644 --- a/src/write.c +++ b/src/write.c @@ -3232,25 +3232,25 @@ avifResult avifEncoderFinish(avifEncoder * encoder, avifRWData * output) avifBoxMarker ftyp; AVIF_CHECKRES(avifRWStreamWriteBox(&s, "ftyp", AVIF_BOX_SIZE_TBD, &ftyp)); - AVIF_CHECKRES(avifRWStreamWriteChars(&s, majorBrand, 4)); // unsigned int(32) major_brand; - AVIF_CHECKRES(avifRWStreamWriteU32(&s, minorVersion)); // unsigned int(32) minor_version; - AVIF_CHECKRES(avifRWStreamWriteChars(&s, "avif", 4)); // unsigned int(32) compatible_brands[]; - if (useAvioBrand) { // - AVIF_CHECKRES(avifRWStreamWriteChars(&s, "avio", 4)); // ... compatible_brands[] - } // - if (isSequence) { // - AVIF_CHECKRES(avifRWStreamWriteChars(&s, "avis", 4)); // ... compatible_brands[] - AVIF_CHECKRES(avifRWStreamWriteChars(&s, "msf1", 4)); // ... compatible_brands[] - AVIF_CHECKRES(avifRWStreamWriteChars(&s, "iso8", 4)); // ... compatible_brands[] - } // - AVIF_CHECKRES(avifRWStreamWriteChars(&s, "mif1", 4)); // ... compatible_brands[] - AVIF_CHECKRES(avifRWStreamWriteChars(&s, "miaf", 4)); // ... compatible_brands[] - if (isMA1B) { // - AVIF_CHECKRES(avifRWStreamWriteChars(&s, "MA1B", 4)); // ... compatible_brands[] - } // - if ((imageMetadata->depth == 8) || (imageMetadata->depth == 10)) { // - if (imageMetadata->yuvFormat == AVIF_PIXEL_FORMAT_YUV444) { // - AVIF_CHECKRES(avifRWStreamWriteChars(&s, "MA1A", 4)); // ... compatible_brands[] + AVIF_CHECKRES(avifRWStreamWriteChars(&s, majorBrand, 4)); // unsigned int(32) major_brand; + AVIF_CHECKRES(avifRWStreamWriteU32(&s, minorVersion)); // unsigned int(32) minor_version; + AVIF_CHECKRES(avifRWStreamWriteChars(&s, "avif", 4)); // unsigned int(32) compatible_brands[]; + if (useAvioBrand) { // + AVIF_CHECKRES(avifRWStreamWriteChars(&s, "avio", 4)); // ... compatible_brands[] + } // + if (isSequence) { // + AVIF_CHECKRES(avifRWStreamWriteChars(&s, "avis", 4)); // ... compatible_brands[] + AVIF_CHECKRES(avifRWStreamWriteChars(&s, "msf1", 4)); // ... compatible_brands[] + AVIF_CHECKRES(avifRWStreamWriteChars(&s, "iso8", 4)); // ... compatible_brands[] + } // + AVIF_CHECKRES(avifRWStreamWriteChars(&s, "mif1", 4)); // ... compatible_brands[] + AVIF_CHECKRES(avifRWStreamWriteChars(&s, "miaf", 4)); // ... compatible_brands[] + if (isMA1B) { // + AVIF_CHECKRES(avifRWStreamWriteChars(&s, "MA1B", 4)); // ... compatible_brands[] + } // + if ((imageMetadata->depth == 8) || (imageMetadata->depth == 10)) { // + if (imageMetadata->yuvFormat == AVIF_PIXEL_FORMAT_YUV444) { // + AVIF_CHECKRES(avifRWStreamWriteChars(&s, "MA1A", 4)); // ... compatible_brands[] } } #if defined(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP)