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

[Request]: Support automatic level calculation for encoders #533

Open
lexano-ivs opened this issue Feb 12, 2025 · 5 comments
Open

[Request]: Support automatic level calculation for encoders #533

lexano-ivs opened this issue Feb 12, 2025 · 5 comments

Comments

@lexano-ivs
Copy link

When using the AVC, HEVC, or AV1 encoders, the codec level needs to be set by the application. It would be an improvement to offer an Auto option where AMF calculates the best-fit level for the encode operation.

Using HEVC as an example, AMF_VIDEO_ENCODER_HEVC_PROFILE_LEVEL should have AMF_LEVEL_AUTO. This option should apply to all encoders.

Refer to the OBS upstream PR at obsproject/obs-studio#11548 for an example of what would be needed.

@rhutsAMD
Copy link
Collaborator

The encoder profile level is automatically increased based on the frame size if the given profile level is found to not be sufficient. For HEVC, the default profile level set is the highest one, which is why you are not seeing it get corrected upwards.

For example, if you set a low profile level for the H264 encoder such as AMF_H264_LEVEL__1, you should see it get automatically increased to AMF_H264_LEVEL__4 for 1920x1080 input. Similarly if you leave the default profile level for H264, you should see it increase if you use, for example, a 4k input.

If you find this correction doesn't work, could you please provide an example?

@cs9kc
Copy link

cs9kc commented Feb 17, 2025

Is there a reason why AMF's HEVC uses the highest "level" by default? People have noticed this before when using OBS Studio in the past, but I don't think anyone has directly asked "why"?

@lexano-ivs
Copy link
Author

lexano-ivs commented Feb 18, 2025

@rhutsAMD For HEVC, the AMF default is the highest level (6.2). It didn't occur to me to try using the lowest level and testing it that way, as it's a bit counterintuitive.

The documentation for AMF_VIDEO_ENCODER_HEVC_PROFILE_LEVEL indicates "Description: Selects the HEVC Profile Level." This implies the level has to be selected, and because the enumeration doesn't list an "Auto" option, it could easily be interpreted as "the level is set here and we won't change it".

Is there any documentation that describes the automatic level adjustment?

Also, as @cs9kc points out, defaulting to the highest level is questionable. Given the description you provided, wouldn't it make sense to default it to the lowest level and let AMF adjust it?

@rhutsAMD
Copy link
Collaborator

I have lowered the default profile level for the HEVC encoder to AMF_LEVEL_5_2 to closer match the default of the other encoders considering the corresponding frame sizes. This new default profile level will take effect in a future driver release.

@cgutman
Copy link

cgutman commented Feb 20, 2025

Is there a reason not to have all AMF encoders default to the lowest level that can meet the requested resolution, frame rate, bitrate, and reference frame count? If you don't want to do it in AMF itself, we can always do it in FFmpeg (which right now defaults to leaving the level unset and using AMF's default) if it makes sense.

Most encoders and tools that have an Auto option for level selection use this "pick lowest possible level" behavior. I suspect it's what users are expecting for the broadest possible decoder compatibility.

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

No branches or pull requests

4 participants