Log in

View Full Version : x264: qp2bitrate, bit2qp ?


ncahammer
22nd October 2008, 13:38
If I encode a two pass encode, using a given bitrate A and the x264 log reports an achieved mean QP B, is some kind of function that will give me the estimated QP B' if I reencode (using the same video and parameters of course) using a bitrate A'

is the opposite also predictable ?
I mean if I want to achieve a QP B' what is the bitrate A' that I should give to x264 ?

I searched the x264 source code and I did find in the ratecontrol.c some functions (qscale2bits,qp2qscale) but I am not sure that I am in the correct path, I suspect that I need to read and reevaluate each frame from the .stats file

Sagekilla
22nd October 2008, 15:37
The simple fact is you can't determine how many bits will be given for a certain QP and the number of bits to achieve a certain QP.

What happens when you have a completely flat frame, i.e. one color? It could have a QP of 0 and take up almost no bits. On the other hand, you can have a scene from parkrun that has a QP of 20 but takes up tons of bits.

akupenguin
22nd October 2008, 15:59
Bitrate is approximately proportional to 2^(-qp/6)
Yes you'll get a slightly more accurate estimate if you run qscale2bits on each frame, which scales mvs and residuals by different amounts.
But if you want a target quality, use CRF and not 2pass.

ncahammer
22nd October 2008, 16:40
What happens when you have a completely flat frame, i.e. one color? It could have a QP of 0 and take up almost no bits. On the other hand, you can have a scene from parkrun that has a QP of 20 but takes up tons of bits.The x264 has given somehow the 0 and 24 QP based only on the .stats and the target bitrate I specified in the command line. How are those computations will be altered if I specify a diffent bitrate and run again just the second pass using the same .stat ? Obviously the x264 will give different QP to those frames and my question is: can I predict it ?

Bitrate is approximately proportional to 2^(-qp/6)
Yes you'll get a slightly more accurate estimate if you run qscale2bits on each frame, which scales mvs and residuals by different amounts.
But if you want a target quality, use CRF and not 2pass.
Thanks I will try both !
about CRF specially if you use AQ or psy is not very accurate. The final QP varies several units on different videos I encoded with the same CRF value.

akupenguin
22nd October 2008, 16:47
So you don't want constant quality, but really constant QP (which is just some number used internally by the encoder and not very related to quality). Why?!

ncahammer
22nd October 2008, 17:21
I do want constant quality but also I do not trust so much the CRF mode with AQ and psy.
Also QP is the only number that x264 reports (in the log), so I was wondering if I could predict it.
If it had an average RF value (quality factor) I could use that, but it is not available
Unless you implying I should use SSIM instead of QP, but again SSIM also varies on different videos encoded with the same CRF.

Dark Shikari
22nd October 2008, 17:36
I do want constant quality but also I do not trust so much the CRF mode with AQ and psy.Then why do you trust the quantizer, which is even more arbitrary with regard to quality?

ncahammer
22nd October 2008, 18:03
Then why do you trust the quantizer, which is even more arbitrary with regard to quality?I do not trust it more. I want to predict it.
if the result of an encode doesn't match on what I observe as transparent, I want a factor than I can increase or decrease and Bitrate and QP are the only numbers I have. I was wondering if there was a formula where altering one I could predict the other

Dark Shikari
22nd October 2008, 18:06
I do not trust it more. I want to predict it.
if the result of an encode doesn't match on what I observe as transparent, I want a factor than I can increase or decrease and Bitrate and QP are the only numbers I have. I was wondering if there was a formula where altering one I could predict the otherDecreasing QP by 6 doubles bitrate. Approximately. This is not always guaranteed to be true.

Sagekilla
22nd October 2008, 21:17
ncahammer, if you do several encodes to find the highest CRF that'll produce "transparent" quality for you, you can rest assured you can reuse that CRF over many encodes and the quality will be very similar.

Generally speaking, CRF 18 should produce transparency in almost every condition (I've yet to encounter a situation where it hasn't..)