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

Variable Bitrate (Peak Constrained) ignores given constraints. #39

Closed
Xaymar opened this issue Nov 3, 2016 · 19 comments
Closed

Variable Bitrate (Peak Constrained) ignores given constraints. #39

Xaymar opened this issue Nov 3, 2016 · 19 comments

Comments

@Xaymar
Copy link
Contributor

Xaymar commented Nov 3, 2016

Seems to be a regression from an earlier driver (accidentally changed the wrong code?), VBR seems to completely ignore any constraints. Min/Max QP, VBV Buffer Size, Target/Peak Bitrate all have no effect on what it is going to use for the actual bitrate and usually it hovers at around a fixed 20mbit/s.

Edit: Bitrate drops below 20mbit/s when Target Bitrate is set to exactly 0. Still does not follow any other constraints.

Constraints being ignored completely:

  • Min QP (unless 0)
  • Target Bitrate
  • Peak Bitrate
  • VBV Buffer

System Information

  • Windows 10 64-Bit (Anniversary Update, automatic Updates enabled)
  • CPU: Intel 4690
  • Mainboard: GIGABYTE H97-D3H
  • GPU: RASUS Radeon R9 285 Strix OC DirectCU II
  • Driver: 16.10.3

Report Data

2016-11-03 (Wrong Target Bitrate)

2016-11-03 (Corrected Target Bitrate)

2016-11-03 (Applied fixes by Mikhail)

@Xaymar Xaymar changed the title Variable Bitrate (Peak Constrained) does not stay below Peak Bitrate. Variable Bitrate (Peak Constrained) ignores given constraints. Nov 3, 2016
@Xaymar
Copy link
Contributor Author

Xaymar commented Nov 3, 2016

When setting Target Bitrate to 0 and only using Peak Bitrate, the achieved bitrate drops to 3200kbit/s. Still unsure how to control the actual bitrate, it seems to ignore me completely.

Edit: Higher motion scenes get closer to the Peak Bitrate. Did I just find a solution?
Edit 2: Nope. Still shoots straight past the given Peak Bitrate or falls way below it.

@MikhailAMD
Copy link
Collaborator

There was no changes in the driver in this area.
From what I see in the log is that peak bitrate is less then target bitrate (9000000 vs 20000000). It doesn't have a lot of sense. AMF will not correct this and codec team told that HW behaviour would be unpredicted.

@Xaymar
Copy link
Contributor Author

Xaymar commented Nov 3, 2016

So the name of the rate control method AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR is wrong here?

Edit: I'd also like to state that it worked in older drivers and started breaking with AMF SDK being rolled out.

@Xaymar
Copy link
Contributor Author

Xaymar commented Nov 3, 2016

Another thing that I forgot in the last response, I did not set Target Bitrate to 20mbit/s. I set Target Bitrate to 0, since it is called PEAK_CONSTRAINED_VBR and should be using Peak Bitrate instead.

@MikhailAMD
Copy link
Collaborator

Not sure but it was not intended to work.
This method uses two parameters target bitrate (kind of average bitrate) and hard limitation for peaks. Obviously peak limitation should be higher then average.

@Xaymar
Copy link
Contributor Author

Xaymar commented Nov 3, 2016

I will do some additional tests and report back

@Xaymar
Copy link
Contributor Author

Xaymar commented Nov 3, 2016

Further testing with "correct" Bitrates (3500000 for Target, 9000000 for Peak) revealed that it doesn't work at all - which reflects what users have been reporting with Plays.TV for a while too. Average bitrate is again close to 20mbit/s instead of the given 9mbit/s.

2016-11-03

@MikhailAMD
Copy link
Collaborator

MikhailAMD commented Nov 3, 2016

I looked briefly into the plug-in code. Please confirm if I am right or not: the plug-in sets bitrate parameters before calling encoder->Init(), correct?
If so it is wrong. There parameters are overwritten by applying "usage" parameter inside Init() method. All dynamic parameters including bitrate should be set after Init() call.

@Xaymar
Copy link
Contributor Author

Xaymar commented Nov 3, 2016

That is a very strange way of handling that. Would I have to instantly ReInit the encoder to apply them? Some of the properties can only be applied before calling Init() too, otherwise they return AMF_ALREADY_INITIALIZED.

I will update the code to match your change now and see if that helps.

@MikhailAMD
Copy link
Collaborator

You should not use Reinit() for dynamic properties. You can set them at any time and they will be applied before next frame is submitted. The header file clearly separated dynamic and static properties. Statics should be set before Init() or after with Reinit() call, dynamic should be set after Init(). Check AMF samples they all written this way.

@Xaymar
Copy link
Contributor Author

Xaymar commented Nov 3, 2016

You should not use Reinit() for dynamic properties. You can set them at any time and they will be applied before next frame is submitted.

If this actually works, that would be great. Early tests (on driver 16.9.2 and 16.10.1) however did not automatically apply dynamic properties and instead applied them only when ReInit was called. If 16.10.2/.3 fixed this, that would be a neat fix. (That was the reason for even implementing the ReInit behaviour.)

The header file clearly separated dynamic and static properties. Statics should be set before Init() or after with Reinit() call, dynamic should be set after Init().

Then I have a question: What actually are the dynamic parameters? The documentation only lists "Profile", "ProfileLevel" and "MaxOfLTRFrames" as Static Parameters, but "BPicturesDeltaQP" and "ReferenceBPicturesDeltaQP" are also static parameters that need to be set before Init() and can't ever be changed afterwards (not even with ReInit(), it will just not change them).

I have also applied the suggested changes now, but have had no different results to before. Total average bitrate is still a lot higher than the given target bitrate.

Is there a better way to tell where things fail? The debug output from AMF is rather sparse and doesn't really tell me why things aren't working the way they should.

@MikhailAMD
Copy link
Collaborator

check the VideoEncoderVCE.h: all properties below this comment are dynamic.
// Dynamic properties - can be set at any time
In documentation the "static" word is in the parameter table making group of them but it should be more visible, agree.
There only few static parameters, when in question follow header file.

@MikhailAMD
Copy link
Collaborator

From the log: you should not call Reinit() after updating rate control and other dynamic parameters.

@MikhailAMD
Copy link
Collaborator

Regardless of reinit: log seem right. Where is the file?

@Xaymar
Copy link
Contributor Author

Xaymar commented Nov 3, 2016

My bad, i uploaded the log twice. I have removed any trace of ReInit from my code, however there is still a ReInit call in the log file that is not mine. Here are the up to date files:

@Xaymar
Copy link
Contributor Author

Xaymar commented Nov 3, 2016

I have noticed another thing, CABACEnable is now always 1. I can assume that 16.10.3 fixed any issues with it?

@MikhailAMD
Copy link
Collaborator

MikhailAMD commented Nov 3, 2016

Internal reInit() will be triggered if you set a static property after Init() call. See in the log that QualityPreset property is set after Init().
For rate control Please:

  • enable HDR
  • disable filler data

Not rate control related:

  • enable CABAC
  • Disable B-frames
  • Profile Level should be higher then 4

Please share the results.
Thanks,

@Xaymar
Copy link
Contributor Author

Xaymar commented Nov 3, 2016

Okay, I modified some of the code to not override static settings in update(), hopefully should have removed the ReInit() call now.

Average bitrate is now at about 12mb/s, about what Peak Bitrate + Target Bitrate would be.

Changes applied:

  • Static Properties shouldn't be set after Init() anymore.
  • HRD is enabled (HDR not, I don't have a HDR surface to submit yet or in the near future)
  • Filler Data is Disabled
  • CABAC is Enabled, even though I have no control over it since 16.10.3
  • B-Pictures and Reference are both 0
  • Profile Level set to 52 (no idea why that was on 40)

Edit: The same issue affects #18 and is currently being debugged there.

@Xaymar
Copy link
Contributor Author

Xaymar commented Nov 8, 2016

Same solution as in #18: #18 (comment)

@Xaymar Xaymar closed this as completed Nov 8, 2016
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

No branches or pull requests

2 participants