Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 22nd October 2008, 13:38   #1  |  Link
ncahammer
Registered User
 
Join Date: Feb 2007
Location: Athens, Greece
Posts: 43
x264: qp2bitrate, bit2qp ?

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
ncahammer is offline   Reply With Quote
Old 22nd October 2008, 15:37   #2  |  Link
Sagekilla
x264aholic
 
Join Date: Jul 2007
Location: New York
Posts: 1,752
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.
__________________
You can't call your encoding speed slow until you start measuring in seconds per frame.
Sagekilla is offline   Reply With Quote
Old 22nd October 2008, 15:59   #3  |  Link
akupenguin
x264 developer
 
akupenguin's Avatar
 
Join Date: Sep 2004
Posts: 2,392
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.
akupenguin is offline   Reply With Quote
Old 22nd October 2008, 16:40   #4  |  Link
ncahammer
Registered User
 
Join Date: Feb 2007
Location: Athens, Greece
Posts: 43
Quote:
Originally Posted by Sagekilla View Post
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 ?

Quote:
Originally Posted by akupenguin View Post
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.
ncahammer is offline   Reply With Quote
Old 22nd October 2008, 16:47   #5  |  Link
akupenguin
x264 developer
 
akupenguin's Avatar
 
Join Date: Sep 2004
Posts: 2,392
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?!
akupenguin is offline   Reply With Quote
Old 22nd October 2008, 17:21   #6  |  Link
ncahammer
Registered User
 
Join Date: Feb 2007
Location: Athens, Greece
Posts: 43
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.
ncahammer is offline   Reply With Quote
Old 22nd October 2008, 17:36   #7  |  Link
Dark Shikari
x264 developer
 
Dark Shikari's Avatar
 
Join Date: Sep 2005
Posts: 8,666
Quote:
Originally Posted by ncahammer View Post
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?
Dark Shikari is offline   Reply With Quote
Old 22nd October 2008, 18:03   #8  |  Link
ncahammer
Registered User
 
Join Date: Feb 2007
Location: Athens, Greece
Posts: 43
Quote:
Originally Posted by Dark Shikari View Post
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
ncahammer is offline   Reply With Quote
Old 22nd October 2008, 18:06   #9  |  Link
Dark Shikari
x264 developer
 
Dark Shikari's Avatar
 
Join Date: Sep 2005
Posts: 8,666
Quote:
Originally Posted by ncahammer View Post
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
Decreasing QP by 6 doubles bitrate. Approximately. This is not always guaranteed to be true.
Dark Shikari is offline   Reply With Quote
Old 22nd October 2008, 21:17   #10  |  Link
Sagekilla
x264aholic
 
Join Date: Jul 2007
Location: New York
Posts: 1,752
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..)
__________________
You can't call your encoding speed slow until you start measuring in seconds per frame.
Sagekilla is offline   Reply With Quote
Reply

Tags
bitrate, x264


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 19:00.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.