From 984b8ae12b367f4de103533856c4751758b1f639 Mon Sep 17 00:00:00 2001 From: Wan-Teh Chang Date: Mon, 2 Dec 2024 15:51:42 -0800 Subject: [PATCH] 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..528292080b 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[] } }