Skip to content

Commit 33d9d90

Browse files
committed
Remove define check
Add non-RGB to avifenc help. Base tune default on aomUsage.
1 parent e2719c3 commit 33d9d90

2 files changed

Lines changed: 38 additions & 41 deletions

File tree

apps/avifenc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static void syntaxLong(void)
321321
printf(" end-usage=MODE : Rate control mode, one of 'vbr', 'cbr', 'cq', or 'q'\n");
322322
printf(" sharpness=S : Bias towards block sharpness in rate-distortion optimization of transform coefficients in 0..7. (Default: 0)\n");
323323
printf(" tune=METRIC : Tune the encoder for distortion metric, one of 'psnr', 'ssim' or 'iq'.\n");
324-
printf(" (Default for color: still images (libaom v3.12.0+): iq, otherwise: ssim; default for alpha: psnr)\n");
324+
printf(" (Default for color: still non-RGB images (libaom v3.12.0+): iq, otherwise: ssim; default for alpha: psnr)\n");
325325
printf(" film-grain-test=TEST : Film grain test vectors in 0..16. 0=none (default), 1=test1, 2=test2, ... 16=test16\n");
326326
printf(" film-grain-table=FILENAME : Path to file containing film grain parameters\n");
327327
printf("\n");

src/codec_aom.c

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,40 @@ static avifResult aomCodecEncodeImage(avifCodec * codec,
657657
avifAddImageFlags addImageFlags,
658658
avifCodecEncodeOutput * output)
659659
{
660+
// Map encoder speed to AOM usage + CpuUsed:
661+
// Speed 0: GoodQuality CpuUsed 0
662+
// Speed 1: GoodQuality CpuUsed 1
663+
// Speed 2: GoodQuality CpuUsed 2
664+
// Speed 3: GoodQuality CpuUsed 3
665+
// Speed 4: GoodQuality CpuUsed 4
666+
// Speed 5: GoodQuality CpuUsed 5
667+
// Speed 6: GoodQuality CpuUsed 6
668+
// Speed 7: RealTime CpuUsed 7
669+
// Speed 8: RealTime CpuUsed 8
670+
// Speed 9: RealTime CpuUsed 9
671+
// Speed 10: RealTime CpuUsed 9
672+
unsigned int libavifDefaultAomUsage = AOM_USAGE_GOOD_QUALITY;
673+
// Use the new AOM_USAGE_ALL_INTRA (added in https://crbug.com/aomedia/2959) for still
674+
// image encoding if it is available.
675+
#if defined(AOM_USAGE_ALL_INTRA)
676+
if (addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE) {
677+
libavifDefaultAomUsage = AOM_USAGE_ALL_INTRA;
678+
}
679+
#endif
680+
int aomCpuUsed = -1;
681+
if (encoder->speed != AVIF_SPEED_DEFAULT) {
682+
aomCpuUsed = AVIF_CLAMP(encoder->speed, 0, 9);
683+
if (aomCpuUsed >= 7) {
684+
#if defined(AOM_USAGE_ALL_INTRA) && defined(ALL_INTRA_HAS_SPEEDS_7_TO_9)
685+
if (!(addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE)) {
686+
libavifDefaultAomUsage = AOM_USAGE_REALTIME;
687+
}
688+
#else
689+
libavifDefaultAomUsage = AOM_USAGE_REALTIME;
690+
#endif
691+
}
692+
}
693+
660694
avifBool useLibavifDefaultTuneMetric = AVIF_FALSE; // If true, override libaom's default tune option.
661695
aom_tune_metric libavifDefaultTuneMetric = AOM_TUNE_PSNR; // Meaningless unless useLibavifDefaultTuneMetric.
662696
if (quality != AVIF_QUALITY_LOSSLESS && !avifAOMOptionsContainExplicitTuning(codec, alpha)) {
@@ -667,13 +701,10 @@ static avifResult aomCodecEncodeImage(avifCodec * codec,
667701
} else {
668702
libavifDefaultTuneMetric = AOM_TUNE_SSIM;
669703
#if defined(AOM_HAVE_TUNE_IQ)
670-
#if !defined(AOM_USAGE_ALL_INTRA) || !defined(ALL_INTRA_HAS_SPEEDS_7_TO_9)
671-
#error "AOM_HAVE_TUNE_IQ was introduced after AOM_USAGE_ALL_INTRA and ALL_INTRA_HAS_SPEEDS_7_TO_9"
672-
#endif
673704
// AOM_TUNE_IQ has been tuned for the YCbCr family of color spaces, and is favored for its low perceptual distortion.
674705
// AOM_TUNE_IQ partially generalizes to, and benefits from other "YUV-like" spaces (e.g. YCgCo and ICtCp) including monochrome (luma only).
675706
// AOM_TUNE_IQ sets --deltaq-mode=6 which can only be used in all intra mode.
676-
if (image->matrixCoefficients != AVIF_MATRIX_COEFFICIENTS_IDENTITY && (addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE)) {
707+
if (image->matrixCoefficients != AVIF_MATRIX_COEFFICIENTS_IDENTITY && libavifDefaultAomUsage == AOM_USAGE_ALL_INTRA) {
677708
libavifDefaultTuneMetric = AOM_TUNE_IQ;
678709
}
679710
#endif
@@ -695,40 +726,6 @@ static avifResult aomCodecEncodeImage(avifCodec * codec,
695726
encoderChanges &= ~AVIF_ENCODER_CHANGE_SCALING_MODE;
696727

697728
if (!codec->internal->encoderInitialized) {
698-
// Map encoder speed to AOM usage + CpuUsed:
699-
// Speed 0: GoodQuality CpuUsed 0
700-
// Speed 1: GoodQuality CpuUsed 1
701-
// Speed 2: GoodQuality CpuUsed 2
702-
// Speed 3: GoodQuality CpuUsed 3
703-
// Speed 4: GoodQuality CpuUsed 4
704-
// Speed 5: GoodQuality CpuUsed 5
705-
// Speed 6: GoodQuality CpuUsed 6
706-
// Speed 7: RealTime CpuUsed 7
707-
// Speed 8: RealTime CpuUsed 8
708-
// Speed 9: RealTime CpuUsed 9
709-
// Speed 10: RealTime CpuUsed 9
710-
unsigned int aomUsage = AOM_USAGE_GOOD_QUALITY;
711-
// Use the new AOM_USAGE_ALL_INTRA (added in https://crbug.com/aomedia/2959) for still
712-
// image encoding if it is available.
713-
#if defined(AOM_USAGE_ALL_INTRA)
714-
if (addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE) {
715-
aomUsage = AOM_USAGE_ALL_INTRA;
716-
}
717-
#endif
718-
int aomCpuUsed = -1;
719-
if (encoder->speed != AVIF_SPEED_DEFAULT) {
720-
aomCpuUsed = AVIF_CLAMP(encoder->speed, 0, 9);
721-
if (aomCpuUsed >= 7) {
722-
#if defined(AOM_USAGE_ALL_INTRA) && defined(ALL_INTRA_HAS_SPEEDS_7_TO_9)
723-
if (!(addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE)) {
724-
aomUsage = AOM_USAGE_REALTIME;
725-
}
726-
#else
727-
aomUsage = AOM_USAGE_REALTIME;
728-
#endif
729-
}
730-
}
731-
732729
// aom_codec.h says: aom_codec_version() == (major<<16 | minor<<8 | patch)
733730
static const int aomVersion_2_0_0 = (2 << 16);
734731
const int aomVersion = aom_codec_version();
@@ -760,14 +757,14 @@ static avifResult aomCodecEncodeImage(avifCodec * codec,
760757
avifGetPixelFormatInfo(image->yuvFormat, &codec->internal->formatInfo);
761758

762759
aom_codec_iface_t * encoderInterface = aom_codec_av1_cx();
763-
aom_codec_err_t err = aom_codec_enc_config_default(encoderInterface, cfg, aomUsage);
760+
aom_codec_err_t err = aom_codec_enc_config_default(encoderInterface, cfg, libavifDefaultAomUsage);
764761
if (err != AOM_CODEC_OK) {
765762
avifDiagnosticsPrintf(codec->diag, "aom_codec_enc_config_default() failed: %s", aom_codec_err_to_string(err));
766763
return AVIF_RESULT_UNKNOWN_ERROR;
767764
}
768765

769766
// Set our own default cfg->rc_end_usage value, which may differ from libaom's default.
770-
switch (aomUsage) {
767+
switch (libavifDefaultAomUsage) {
771768
case AOM_USAGE_GOOD_QUALITY:
772769
// libaom's default is AOM_VBR. Change the default to AOM_Q since we don't need to
773770
// hit a certain target bit rate. It's easier to control the worst quality in Q

0 commit comments

Comments
 (0)