MCPcopy Create free account
hub / github.com/AOMediaCodec/libavif / aomCodecEncodeImage

Function aomCodecEncodeImage

src/codec_aom.c:656–1348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

654}
655
656static avifResult aomCodecEncodeImage(avifCodec * codec,
657 avifEncoder * encoder,
658 const avifImage * image,
659 avifBool alpha,
660 int tileRowsLog2,
661 int tileColsLog2,
662 int quality,
663 avifEncoderChanges encoderChanges,
664 avifBool disableLaggedOutput,
665 avifAddImageFlags addImageFlags,
666 avifCodecEncodeOutput * output)
667{
668 // Save the quality of the first layer because it's useful for further decision making
669 if (encoder->extraLayerCount > 0 && codec->internal->currentLayer == 0) {
670 codec->internal->qualityFirstLayer = quality;
671 }
672
673 // Determine whether the encoder should be configured to use intra frames only, either by setting aomUsage to
674 // AOM_USAGE_ALL_INTRA, or by manually configuring the encoder so all frames will be key frames (if AOM_USAGE_ALL_INTRA isn't
675 // available).
676
677 // For libaom versions older than 3.14.0, all-intra encoding is beneficial when encoding a two-layer image item and the
678 // quality of the first layer is very low. Switching to all-intra encoding comes with the following benefits:
679 // - The first layer will be smaller than the second layer (which is often not the case with inter encoding)
680 // - Outputs have predictable file sizes: the sum of the first layer (quality <= 10) plus the second layer (quality set by
681 // the caller)
682 // - Because the first layer is very small, layered encoding overhead is also smaller and more stable (about 5-8% for quality
683 // 40 and 2-4% for quality 60)
684 // Note: libaom 3.14.0 introduces a mechanism to completely control each layer's QP, and extends tune IQ to inter-frame
685 // encoding modes (AOM_USAGE_GOOD_QUALITY and AOM_USAGE_REALTIME), so there's no need to use all-intra encoding for layered.
686
687 // aom_codec.h says: aom_codec_version() == (major<<16 | minor<<8 | patch)
688 static const int aomVersion_3_14_0 = (3 << 16) | (14 << 8);
689 const int aomVersion = aom_codec_version();
690 avifBool useAllIntraForLayered = aomVersion < aomVersion_3_14_0 && encoder->extraLayerCount == 1 &&
691 codec->internal->qualityFirstLayer <= TWO_LAYER_ALL_INTRA_QUALITY_THRESHOLD;
692 // Also use all-intra encoding when encoding still images.
693 avifBool useAllIntra = (addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE) || useAllIntraForLayered;
694
695 // Map encoder speed to AOM usage + CpuUsed:
696 // Speed 0: GoodQuality CpuUsed 0
697 // Speed 1: GoodQuality CpuUsed 1
698 // Speed 2: GoodQuality CpuUsed 2
699 // Speed 3: GoodQuality CpuUsed 3
700 // Speed 4: GoodQuality CpuUsed 4
701 // Speed 5: GoodQuality CpuUsed 5
702 // Speed 6: GoodQuality CpuUsed 6
703 // Speed 7: RealTime CpuUsed 7
704 // Speed 8: RealTime CpuUsed 8
705 // Speed 9: RealTime CpuUsed 9
706 // Speed 10: RealTime CpuUsed 9
707 unsigned int aomUsage = AOM_USAGE_GOOD_QUALITY;
708 // Use AOM_USAGE_ALL_INTRA (added in https://crbug.com/aomedia/2959) if available.
709#if defined(AOM_USAGE_ALL_INTRA)
710 if (useAllIntra) {
711 aomUsage = AOM_USAGE_ALL_INTRA;
712 }
713#endif

Callers

nothing calls this directly

Calls 14

avifDiagnosticsPrintfFunction · 0.85
aomQualityToQuantizerFunction · 0.85
avifImageCalcAOMFmtFunction · 0.85
avifGetPixelFormatInfoFunction · 0.85
doesLevelMatchFunction · 0.85
aomDiagPrintfFunction · 0.85
avifFindAOMScalingModeFunction · 0.85
avifImagePlaneWidthFunction · 0.85
avifImagePlaneHeightFunction · 0.85

Tested by

no test coverage detected