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

fix: h264 level selection algorithm #1048

Conversation

RebootVanChild
Copy link

There seems to be a slight issue in the h264 level selection algorithm. Widths and heights of frames and h264 macroblocks should be taken into account when doing the calculation, not only the pixel counts.
This issue can cause encoder invalid param error on certain resolution ranges.

For example, a 1922x1080 30fps video stream:

The correct algorithm should be

macroblocksPerFrame = Ceil( pixelsFrameWidth / pixelsMacroblockSide ) * Ceil( pixelsFrameHeight / pixelsMacroblockSide )
= Ceil( 1922 / 16 ) * Ceil( 1080 / 16 )
= 8228

Which resides in level 4.2.

However, according to current algorithm

macroblocksPerFrame = Ceil( pixelsPerFrame / pixelsPerMacroblock )
= Ceil( 1922 * 1080 / (16 * 16) )
= 8109

Thus, the algorithm would select level 4, and cause encoder invalid param error.

@unity-cla-assistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


tiancheng.liu seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@RebootVanChild
Copy link
Author

Moved to PR #1049
Closing this because the author is not able to sign the CLA.

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.

2 participants