@@ -518,6 +518,7 @@ static avifBool avifProcessAOMOptionsPostInit(avifCodec * codec, avifBool alpha)
518518 }
519519#endif // defined(HAVE_AOM_CODEC_SET_OPTION)
520520 }
521+ codec -> csOptions -> count = 0 ;
521522 return AVIF_TRUE ;
522523}
523524
@@ -606,26 +607,30 @@ static avifResult aomCodecEncodeImage(avifCodec * codec,
606607 avifDiagnosticsPrintf (codec -> diag , "aom_codec_enc_config_default() failed: %s" , aom_codec_err_to_string (err ));
607608 return AVIF_RESULT_UNKNOWN_ERROR ;
608609 }
610+ } else {
611+ cfg -> g_usage = aomUsage ;
609612 }
610613
611- // Set our own default cfg->rc_end_usage value, which may differ from libaom's default.
612- switch (aomUsage ) {
613- case AOM_USAGE_GOOD_QUALITY :
614- // libaom's default is AOM_VBR. Change the default to AOM_Q since we don't need to
615- // hit a certain target bit rate. It's easier to control the worst quality in Q
616- // mode.
617- cfg -> rc_end_usage = AOM_Q ;
618- break ;
619- case AOM_USAGE_REALTIME :
620- // For real-time mode we need to use CBR rate control mode. AOM_Q doesn't fit the
621- // rate control requirements for real-time mode. CBR does.
622- cfg -> rc_end_usage = AOM_CBR ;
623- break ;
614+ if (!codec -> internal -> endUsageSet ) {
615+ // Set our own default cfg->rc_end_usage value, which may differ from libaom's default.
616+ switch (aomUsage ) {
617+ case AOM_USAGE_GOOD_QUALITY :
618+ // libaom's default is AOM_VBR. Change the default to AOM_Q since we don't need to
619+ // hit a certain target bit rate. It's easier to control the worst quality in Q
620+ // mode.
621+ cfg -> rc_end_usage = AOM_Q ;
622+ break ;
623+ case AOM_USAGE_REALTIME :
624+ // For real-time mode we need to use CBR rate control mode. AOM_Q doesn't fit the
625+ // rate control requirements for real-time mode. CBR does.
626+ cfg -> rc_end_usage = AOM_CBR ;
627+ break ;
624628#if defined(AOM_USAGE_ALL_INTRA )
625- case AOM_USAGE_ALL_INTRA :
626- cfg -> rc_end_usage = AOM_Q ;
627- break ;
629+ case AOM_USAGE_ALL_INTRA :
630+ cfg -> rc_end_usage = AOM_Q ;
631+ break ;
628632#endif
633+ }
629634 }
630635
631636 // Profile 0. 8-bit and 10-bit 4:2:0 and 4:0:0 only.
@@ -744,20 +749,12 @@ static avifResult aomCodecEncodeImage(avifCodec * codec,
744749 }
745750 }
746751
747- if (lossless ) {
748- aom_codec_control (& codec -> internal -> encoder , AV1E_SET_LOSSLESS , 1 );
749- }
750- if (encoder -> maxThreads > 1 ) {
751- aom_codec_control (& codec -> internal -> encoder , AV1E_SET_ROW_MT , 1 );
752- }
753- if (encoder -> tileRowsLog2 != 0 ) {
754- int tileRowsLog2 = AVIF_CLAMP (encoder -> tileRowsLog2 , 0 , 6 );
755- aom_codec_control (& codec -> internal -> encoder , AV1E_SET_TILE_ROWS , tileRowsLog2 );
756- }
757- if (encoder -> tileColsLog2 != 0 ) {
758- int tileColsLog2 = AVIF_CLAMP (encoder -> tileColsLog2 , 0 , 6 );
759- aom_codec_control (& codec -> internal -> encoder , AV1E_SET_TILE_COLUMNS , tileColsLog2 );
760- }
752+ aom_codec_control (& codec -> internal -> encoder , AV1E_SET_LOSSLESS , lossless );
753+ aom_codec_control (& codec -> internal -> encoder , AV1E_SET_ROW_MT , encoder -> maxThreads > 1 );
754+ int tileRowsLog2 = AVIF_CLAMP (encoder -> tileRowsLog2 , 0 , 6 );
755+ aom_codec_control (& codec -> internal -> encoder , AV1E_SET_TILE_ROWS , tileRowsLog2 );
756+ int tileColsLog2 = AVIF_CLAMP (encoder -> tileColsLog2 , 0 , 6 );
757+ aom_codec_control (& codec -> internal -> encoder , AV1E_SET_TILE_COLUMNS , tileColsLog2 );
761758 if (aomCpuUsed != -1 ) {
762759 if (aom_codec_control (& codec -> internal -> encoder , AOME_SET_CPUUSED , aomCpuUsed ) != AOM_CODEC_OK ) {
763760 return AVIF_RESULT_UNKNOWN_ERROR ;
0 commit comments