-
Notifications
You must be signed in to change notification settings - Fork 269
Use AOM_TUNE_IQ by default for YUV #2830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
WIth this PR, using |
|
@maryla-uc good catch! tune iq sets up many optimized defaults (including |
Done. |
|
Any idea what's holding up this PR? |
There are a few consequences of TUNE=IQ to take into consideration when using it by default:
|
|
@castano another thing worth mentioning: tune IQ is already considered production quality (on libaom 3.13.1 and newer). If a project doesn't have to worry about specific tune ssim behavior, then said project can just switch to use tune IQ right away. For example, The Guardian has been using tune IQ for a few months, and we've received positive feedback from the website admin in the form of overall better image quality and consistency. Tune IQ's improvement in bit allocation by itself can be seen as a "bug fix". I wouldn't wait for this PR to be merged as a sign of feature "readiness". On the contrary, we're just trying to be super thorough in understanding the inherent differences in bitrate allocation and encode time with tune IQ across images, compared to tune SSIM. |
|
I think it makes sense to evaluate the consequences of enabling tune IQ before making it the default choice, but it would be helpful to first add support for tune IQ as a user option, and only later make it the default after more users have had the chance to evaluate it and provide feedback. I have clients interested in using tune IQ, but they won't maintain a custom build of libavif with modifications that they have to merge on every update. Similarly, tools that use libavif won't offer this option until it's officially supported by libavif, so not having this exposed also delays its upstream adoption. |
|
@castano you can enable tune IQ in avifenc with the following parameter: avifenc in turn passes in the parameter to libavif as a key ("tune")/ value ("iq") pair in the following manner: static avifBool avifCodecSpecificOptionsAdd(avifCodecSpecificOptions * options, const char * keyValue)
{
const char * value = strchr(keyValue, '=');
if (value) {
// Keep the parts on the left and on the right of the equal sign,
// but not the equal sign itself.
const size_t keyLength = value - keyValue;
return avifCodecSpecificOptionsAddKeyValue(options, keyValue, keyLength, value + 1);
}
// Pass in a non-NULL, empty string. Codecs can use the mere existence of a key as a boolean value.
return avifCodecSpecificOptionsAddKeyValue(options, keyValue, strlen(keyValue), "");
}
|
|
Hmm... I haven't tried avifenc, but I didn't see the iq option in the aomOptionDefs struct, so I assumed that would not work without additional changes: Ah, I see it gets routed to |
|
Ignacio: The aomOptionDefs struct is only used with older versions of libaom that don't have the For testing this pull request, please use the latest version of libaom, v3.13.1 if you can. Thanks! |
Co-authored-by: Vincent Rabaud <vrabaud@google.com>
| #if defined(AOM_HAVE_TUNE_IQ) && defined(AOM_USAGE_ALL_INTRA) && defined(ALL_INTRA_HAS_SPEEDS_7_TO_9) | ||
| // AOM_TUNE_IQ is favored for its low perceptual distortion on luma and chroma samples. | ||
| // AOM_TUNE_IQ sets --deltaq-mode=6 which can only be used in all intra mode. | ||
| if (image->matrixCoefficients != AVIF_MATRIX_COEFFICIENTS_IDENTITY && (addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMPORTANT: If the addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE test is intended to detect whether all intra mode is used, ideally we should wait until we have set the aomUsage variable and then test aomUsage == AOM_USAGE_ALL_INTRA.
This requires moving some code around and possibly save some variables such as aomUsage and useTuneIq in the codec->internal struct.
Would you like me to take a stab at this and attach a patch to this pull request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like me to take a stab at this and attach a patch to this pull request?
Thank you for the proposal. Could you do that in a separate pull request, so that this PR only switches t=IQ on by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can reorder the code in a separate pull request.
Optional: If the addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE check is intended to detect whether all intra mode is used rather than whether we are encoding a still image, it would be good to use a local variable whose name clarifies the purpose of the check:
avifBool useAllIntra = (addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE) != 0;
if (image->matrixCoefficients != AVIF_MATRIX_COEFFICIENTS_IDENTITY && useAllIntra) {
|
Yannis: Sorry about the late review. I missed your review request. |
wantehchang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
| } else { | ||
| libavifDefaultTuneMetric = AOM_TUNE_SSIM; | ||
| #if defined(AOM_HAVE_TUNE_IQ) | ||
| #if !defined(AOM_USAGE_ALL_INTRA) || !defined(ALL_INTRA_HAS_SPEEDS_7_TO_9) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check looks strange here, especially the check for ALL_INTRA_HAS_SPEEDS_7_TO_9. The reason for this check is not obvious until we get to line 721 below:
if (aomCpuUsed >= 7) {
#if defined(AOM_USAGE_ALL_INTRA) && defined(ALL_INTRA_HAS_SPEEDS_7_TO_9)
if (!(addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE)) {
aomUsage = AOM_USAGE_REALTIME;
}
#else
aomUsage = AOM_USAGE_REALTIME;
#endif
}
If you want to avoid reordering the code now, I suggest we delete this check. This check is always false in libaom releases or on the libaom main branch.
| #if defined(AOM_HAVE_TUNE_IQ) && defined(AOM_USAGE_ALL_INTRA) && defined(ALL_INTRA_HAS_SPEEDS_7_TO_9) | ||
| // AOM_TUNE_IQ is favored for its low perceptual distortion on luma and chroma samples. | ||
| // AOM_TUNE_IQ sets --deltaq-mode=6 which can only be used in all intra mode. | ||
| if (image->matrixCoefficients != AVIF_MATRIX_COEFFICIENTS_IDENTITY && (addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can reorder the code in a separate pull request.
Optional: If the addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE check is intended to detect whether all intra mode is used rather than whether we are encoding a still image, it would be good to use a local variable whose name clarifies the purpose of the check:
avifBool useAllIntra = (addImageFlags & AVIF_ADD_IMAGE_FLAG_SINGLE) != 0;
if (image->matrixCoefficients != AVIF_MATRIX_COEFFICIENTS_IDENTITY && useAllIntra) {
| printf(" sharpness=S : Bias towards block sharpness in rate-distortion optimization of transform coefficients in 0..7. (Default: 0)\n"); | ||
| printf(" tune=METRIC : Tune the encoder for distortion metric, one of 'psnr', 'ssim' or 'iq'.\n"); | ||
| printf(" (Default for color: ssim, default for alpha: psnr)\n"); | ||
| printf(" (Default for color: still images (libaom v3.12.0+): iq, otherwise: ssim; default for alpha: psnr)\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change "still images" to "still non-RGB images"?
Based on #2599.
Note that "(Default: psnr)" was incorrect.