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

Scaling bug fix (issue 353) #354

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

MikeIndiaAlpha
Copy link
Contributor

So to be honest I failed to understand completely original author's intentions. It is a complex code, and getting resolutions/aspects right is notoriously tricky. BTDT. Also, this is my last week, and I don't be there to take care of debugging in case of problems.

Here is what I did, then:

  1. Resolution is always rounded up to the nearest even number. This is no-brainer, because h.264 doesn't allow for odd resolutions and I think most codecs (at least using "420" style chroma subsampling) won't, either.
  2. I noticed that resolution altering logic is applied always, regardless of need. So to avoid screwing up original code I simply added bail out condition - no need to change resolution if it is "valid", that is, if it lies within the encoder limits. This guarantees that all the resolutions (very wide spectrum) that encoder is OK with won't be changed at all.

I hope this is acceptable.

It turned out special logic that makes sure Nvidia encoder limits
are respected can sometimes cause problems. More specifically:
- Resolution cropping logic may generate odd resolutions for the
video stream, which is not supported by h.264 and usually shows up
as a "green bar" at the bottom of the video (because encoder adds
a line of zero YUV values, which translated to certain shade of
green)
- Portrait resolutions get needlessly enlarged, ie value that was
requested as a height of the picture gets used as a width, and as
aspect ratio is preserved, height is rescaled and much larger

Two changes were made: 1) all scaled values are now rounded to the
nearest even number and 2) the whole mechanism is not applied if
the resolution stays within the encoder limits
Previous commit changed the resolution clamping approach: instead
of changing every resolution given, change only resolutions that
are not acceptable to the encoder. To make tests pass properly,
one thing needed to change. Previously, when 600x300 resolution was
given to the encoder with 700x500 limits, it got changed to the
250x500. While that was an expected behaviour, I don't think it is
a proper one - why change something that encoder is fully willing
to accept? So the test was modified to be OK, with original
600x300
Previous changes caused limits from the array in ffmpeg.go to be
strictly applied, i.e. if the resolution was fitting the limits,
no change was done. This uncovered the fact that the limits
themselves were bad - on my machine NVenc refused to work with the
message that the frame dimensions is too low.

Changing the minimum resolution to 146x145 fixed the problem. Note
that is is quite likely that the limits should be different for
h265 as well, but on my machine all works.

Proper approach for this problem would be something along the line
of dynamic discovery of these limits (via Nvidia APIs) and then
applying true local HW limits, not hardcoded ones.
@MikeIndiaAlpha
Copy link
Contributor Author

Unfortunately I am running out of time here. In my opinion the problem is that existing code changes the resolutions even if they are in the "legal" range - but that allows some tests to succeed. I fixed a few of those but not all. So I guess somebody else has to do it.

Alternative option is just adopt "rounding up to the nearest even number" from my first commit, this will eradicate green bars and everything else should work - only then the problem with changing the resolutions in the legal range will remain.

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.

1 participant