diff --git a/src/write.c b/src/write.c index cd5c4719c5..015d83e120 100644 --- a/src/write.c +++ b/src/write.c @@ -1816,10 +1816,11 @@ static avifResult avifEncoderWriteMediaDataBox(avifEncoder * encoder, size_t chunkOffset = 0; // Deduplication - See if an identical chunk to this has already been written - if (item->encodeOutput->samples.count > 0) { + // Doing it when item->encodeOutput->samples.count > 0 would require contiguous memory. + if (item->encodeOutput->samples.count == 1) { avifEncodeSample * sample = &item->encodeOutput->samples.sample[0]; chunkOffset = avifEncoderFindExistingChunk(s, mdatStartOffset, sample->data.data, sample->data.size); - } else { + } else if (item->encodeOutput->samples.count == 0) { chunkOffset = avifEncoderFindExistingChunk(s, mdatStartOffset, item->metadataPayload.data, item->metadataPayload.size); }