Skip to content
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

Add support for all profiles of SVT-AV1 #2422

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

FrankGalligan
Copy link
Contributor

SVT-AV1 profiles (speed) can be set from 0 to 13, while libaom and Rav1e speed settings range is 0-10. This CL adds support to set the speed paramter up to 13.

Copy link
Collaborator

@y-guyon y-guyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not check thoroughly but this change looks good overall.

This does not look like a widespread use case so I wonder if silently allowing up to 13 in the libavif API when SVT-AV1 is selected without changing the value of AVIF_SPEED_FASTEST is safer.

An alternative approach would be to allow up to 13 for all codecs but to make 11,12,13 the same as 10 for libaom and rav1e. This avoids the need for a separate AVIF_SPEED_LIBAOM_RAV1E_FASTEST constant. It should just be written in a comment somewhere.

Another alternative approach could be a custom key passed to avifEncoderSetCodecSpecificOption() to avoid changing the current API or constant values. I do not expect speeds 11,12,13 to be widely used anyway.

@FrankGalligan
Copy link
Contributor Author

So you can actually encode in 11-13 with SVT-AV1 in the current code. You can pass -a preset=13 to avifenc, but I think the output would confuse people:
Encoding with codec 'svt' speed [6], color quality [60 (Medium)], alpha quality [100 (Lossless)], tileRowsLog2 [0], tileColsLog2 [0], 128 worker thread(s), please wait...

I think I like your first alternative approach.

Copy link
Collaborator

@y-guyon y-guyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you can actually encode in 11-13 with SVT-AV1 in the current code. You can pass -a preset=13 to avifenc, but I think the output would confuse people

What about (also or instead) fixing stdout for this use case then? Because this PR does not prevent people from using -a preset=13 and have a confusing console output.

apps/avifenc.c Outdated Show resolved Hide resolved
src/codec_svt.c Outdated Show resolved Hide resolved
include/avif/avif.h Outdated Show resolved Hide resolved
@FrankGalligan
Copy link
Contributor Author

So you can actually encode in 11-13 with SVT-AV1 in the current code. You can pass -a preset=13 to avifenc, but I think the output would confuse people

What about (also or instead) fixing stdout for this use case then? Because this PR does not prevent people from using -a preset=13 and have a confusing console output.

I'm not sure I want to do this as then we may need to establish precedence rules. E.g. if you specify preset and speed. For simplicity I think it is better this way.

@y-guyon
Copy link
Collaborator

y-guyon commented Sep 6, 2024

I am a bit uneasy about changing the value of a define in a public header.
@wantehchang Is this common practice?

Vincent suggested just changing avifenc behavior, because the API currently allows for SVT speed 11+.

@FrankGalligan
Copy link
Contributor Author

So what about keeping #define AVIF_SPEED_FASTEST 10 as is. Adding #define AVIF_SPEED_FASTEST_SVT-AV1 13 and changing avifenc to clamp the speed to AVIF_SPEED_FASTEST_SVT-AV1?

@wantehchang
Copy link
Collaborator

@FrankGalligan @y-guyon I am sorry I forgot to answer Yannis's question. I will take a look tomorrow.

But very quickly, this is very likely a gray area. That is, changing the value of AVIF_SPEED_FASTEST (a macro defined in a public header) is an incompatible change strictky speaking, but under a practical definition of backward compatibility, I suspect it won't break any application. But I need to think about this more.

@wantehchang
Copy link
Collaborator

wantehchang commented Sep 7, 2024

I have two proposals that avoid changing AVIF_SPEED_FASTEST. I recommend the first proposal.

Proposal 1: Use avifEncoder::codecChoice to select which speed scale to use.

  • AVIF_CODEC_CHOICE_AUTO (the default) selects the current libavif speed scale of 0..10. AVIF_SPEED_SLOWEST and AVIF_SPEED_FASTEST only apply in this mode.
  • Any other AVIF_CODEC_CHOICE_* value selects the original speed scale of the explicitly chosen codec. This is a change of behavior.
  • In the avifenc command line interface, the -c / --codec option selects which speed scale to use.

I think this proposal is easy to understand even though the link between codecChoice and speed may not be obvious at first. It does not require adding a new avifEncoder option, so I prefer this proposal.

Proposal 2: Add an avifBool useCodecSpeed option to avifEncoder.

  • If useCodecSpeed is false (the default), use the current libavif speed scale of 0..10. AVIF_SPEED_SLOWEST and AVIF_SPEED_FASTEST only apply in this mode. This is the current behavior.
  • If useCodecSpeed is true, use the original speed scale of the codec in use. This is new behavior.
  • In the avifenc command line interface, useCodecSpeed is indicated by adding the codec: prefix to the value of the -s / --speed option. For example, -s 6 means speed 6 in the libavif 0..10 speed scale, and -s codec:6 means speed 6 in the original speed scale of the codec in use.

This proposal is fully backward compatible, but requires adding a new avifEncoder option.

@FrankGalligan
Copy link
Contributor Author

Proposal 2 seems too complicated and do not think that is good to implement.

So for proposal 1 to get SVT-AV1 to encode with speed 13 you would need to set this command:
avifenc -c svt -s 13 temp.png temp.avif

And if you used this command, even with svt the only encoder:
avifenc -s 13 temp.png temp.avif

You would get speed 10 instead of 13.

How about proposal 3

  • Keep AVIF_SPEED_FASTEST as is. I.e. 10
  • Change codec_svt.c to clamp from 0 to 13.
  • Change avifenc.c to remove the check for if (settings.speed > AVIF_SPEED_FASTEST) { settings.speed = AVIF_SPEED_FASTEST; }
    • The library specific clamps will still happen in their wrapper code.
  • No other changes.

With proposal 3 you will get speed 13 with both of these commands:
avifenc -c svt -s 13 temp.png temp.avif

And if you used this command, even with svt the only encoder:
avifenc -s 13 temp.png temp.avif

SVT-AV1 profiles (speed) can be set from 0 to 13, while libaom and Rav1e
speed settings range is 0-10. This CL adds support to set the speed
paramter up to 13.
Added comment and avifenc help text that libaom and rav1e range is
0-10.
@FrankGalligan
Copy link
Contributor Author

I also changed the avifenc help text to output the encoder speed range as 0-13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants