Is 2 pass better than CRF?

General questions or discussion about HandBrake, Video and/or audio transcoding, trends etc.
Post Reply
Leo
Bright Spark User
Posts: 174
Joined: Thu Feb 22, 2007 4:39 pm

Is 2 pass better than CRF?

Post by Leo »

I keep seeing things about people running a single CRF pass to get a filesize then running 2 pass for the given filesize. Does this actually improve quality? How can it? I thought the data would be optimally allocated the first time...

And is the benefit of this significant? Can it be equated to an approximate average reduction in filesize for a given output quality, e.g. 10%?
cbud
Bright Spark User
Posts: 181
Joined: Thu Feb 22, 2007 2:24 am

Re: Is 2 pass better than CRF?

Post by cbud »

Leo wrote:I keep seeing things about people running a single CRF pass to get a filesize then running 2 pass for the given filesize. Does this actually improve quality? How can it? I thought the data would be optimally allocated the first time...

And is the benefit of this significant? Can it be equated to an approximate average reduction in filesize for a given output quality, e.g. 10%?
They run the 1-pass CRF so they can figure out what bitrate is required to achieve a quality of 72% (or whatever %). The bitrate needed to achieve a certain constant quality will vary from disc to disc. Once they know the bitrate, they do a 2-pass encode with this data.

So the benefit is not increasing quality, the benefit is to know that bitrate. The first pass is just for information, the encode is trashed.
Leo
Bright Spark User
Posts: 174
Joined: Thu Feb 22, 2007 4:39 pm

Post by Leo »

OK, but I don't see the advantage of this. Surely a single CRF pass encode would be much quicker and simpler? And if it's not improving the quality, and not reducing the file size, what is the point?

If they are just going to encode at that size anyway, why do they so badly want to know the size beforehand?

So am I right in thinking there is no disadvantage of doing single pass CRF encoding, other than not knowing the final filesize until the end?
hawkman
Veteran User
Posts: 609
Joined: Sat Feb 17, 2007 9:46 pm

Post by hawkman »

Leo wrote:OK, but I don't see the advantage of this. Surely a single CRF pass encode would be much quicker and simpler? And if it's not improving the quality, and not reducing the file size, what is the point?
The theory is, the constant quality pass gives some idea of how good the source material is - and what kind of bitrate you'll need to get a good-looking file (as this varies depending on how grubby the source is).

Then, using 2-pass encoding at this bitrate, you can squeeze a bit more quality out as it does a lot more analysis of the video file, and allocates the bits much better.

You might not see much of a difference though, only if you look really, really closely :)
Leo
Bright Spark User
Posts: 174
Joined: Thu Feb 22, 2007 4:39 pm

Post by Leo »

Thanks hawkman.

Can this be expressed as a rough percentage of how much more efficient it typically ends up, or how much more filespace I'd have to use on single pass CRF? Are we talking 5%? 10%? Surely not more than 10%?

"allocates the bits much better"

why is this? I thought 2 pass allocated the bits to try to get a consant Q value throughout, and would have thought that simply using that CRF value in the first place would actually allocate the bits better? Would the Q value not be more constant throughout using CRF than 2 pass for the same size?
cbud
Bright Spark User
Posts: 181
Joined: Thu Feb 22, 2007 2:24 am

Post by cbud »

Leo wrote:Thanks hawkman.

Can this be expressed as a rough percentage of how much more efficient it typically ends up, or how much more filespace I'd have to use on single pass CRF? Are we talking 5%? 10%? Surely not more than 10%?
I don't think anyone here knows how to or even wants to try and quantify the quality differences down to the percentile. "Yes, my 2-Pass, 3500 kbs, encode with a resolution of 656 x 277 was exactly 10% lower in quality than my 1-Pass CRF at 4000 kbs with 608 x 256." Give me a break.

Leo wrote: "allocates the bits much better"

why is this? I thought 2 pass allocated the bits to try to get a consant Q value throughout, and would have thought that simply using that CRF value in the first place would actually allocate the bits better? Would the Q value not be more constant throughout using CRF than 2 pass for the same size?
No
Leo
Bright Spark User
Posts: 174
Joined: Thu Feb 22, 2007 4:39 pm

Post by Leo »

wouldst thou care to elaborate on thy plain and simple "No". Are all the clauses wrong?

A) I thought 2 pass allocated the bits to try to get a consant Q value throughout
B) would have thought that simply using that CRF value in the first place would actually allocate the bits better
C) Would the Q value not be more constant throughout using CRF than 2 pass for the same size?

If 2 pass doesn't try to get a constant CRF Q value, what does it try to do?
And why can 2 pass encoding to a specific filesize produce a better result than a single CRF pass which is trying to maintain a constant quality regardless of file size?
cbud
Bright Spark User
Posts: 181
Joined: Thu Feb 22, 2007 2:24 am

Post by cbud »

Leo wrote:I thought 2 pass allocated the bits to try to get a consant Q value throughout, and would have thought that simply using that CRF value in the first place would actually allocate the bits better?
No. I don't see how a CRF 1-Pass can allocate bits better than a 2-Pass encode. The whole point of the 1st pass in a 2-pass encode is to figure out where the bits are needed the most! A CRF 1-Pass does not know where they are needed before hand and must decide then and there.
Leo wrote:And why can 2 pass encoding to a specific filesize produce a better result than a single CRF pass which is trying to maintain a constant quality regardless of file size?
Simple, a 2-pass encode allocates the bits better. If you do a 1-pass encode w/ a constant quality of 70% for some movie, you might get an average bitrate of 3000 kbs. This 1-pass encode had to decide on the fly where to put all those bits. Now, if you then encode the same movie with 2-pass at the same bitrate, it will have an entire pass to look over the data and decide where to put the bits. In the end the bitrate is the same for both encodes, but in theory the quality will be better with the 2-pass encode. If you are doing a 100% quality 1-Pass encode then you don't need to worry about allocating bits and a 2-pass would probably be useless.

Leo, 2-pass versus 1-pass encoding has been discussed for many years now and for a variety of codecs. This information is easily provided through a Google search.
Leo
Bright Spark User
Posts: 174
Joined: Thu Feb 22, 2007 4:39 pm

Post by Leo »

cbud, I've tried searching on google for about 50 minutes and I haven't found anything explaining why 2 pass would be better than CRF (constant rate factor). The only sites I could find saying 2 pass was better were comparing it to CQP (contant quantiser), not constant rate factor. In fact, I found more sites disagreeing saying that CRF was better quality or that a second pass would be pointless.

if it is easy for you to find sites explaining why 2 pass may be better that constant rate factor, could you list one/two/some? Thanks.

I just don't get how if CRF is encoding at constant perceived quality regardless of bitrate, two passes restricted to bitrate could produce better quality?
jbrjake
Veteran User
Posts: 4805
Joined: Wed Dec 13, 2006 1:38 am

Post by jbrjake »

You didn't google very hard.

crf vs 2-pass

hit 5, gpoirier, an important developer on projects like x264 and ffmpeg:
http://lists.mplayerhq.hu/pipermail/mpl ... 65203.html
Here's what _I_ think:
- crf provides very good quality and allows to make do without 2 pass,
which is cool.
However, you can't control how big the encode will end up.
- two pass both allow you to control the target bitrate, and allows to
make a smarter use of the bits you throw at it. Each now pass somewhat
improves quality over the previous one.
- qp is really meant to be used if you know what you do, if you need
to us lossless mode, or if you really want to _force_ low quants.

My ranking (in decreasing order of quality):
2-pass>crf>qp

In terms of speed:
crf,qp>2-pass.
From hit 4, here's akupenguin, the x264 author: http://forum.doom9.org/showthread.php?t=123525
Ratecontrol targets can be order on a scale of constant bitrate to constant PSNR, as follows. The visually optimal mode is somewhere in the middle, and is definitely not below CQP. Of course, these are not the only possible modes, there's a whole continuum of others in between, as well as different algorithms to implement these targets.

CBR
ABR
CRF/2pass
CQP
CPSNR

(CRF and 2pass are at the same point on the CBR-to-CPSNR continuum, because they have the same target bitrate distribution. 2pass just ends up slightly closer to that target.)
finally, hit 3 from that google search, also from akupenguin:
benchmarking the existing implementations of crf vs 2pass on several movies. Result: 2pass was better by anywhere from .01 to .12 dB (equivalently, up to 2.5% bitrate at the same psnr). This includes both the effects of ratecontrol (smarter I-frame qp decision) and the fact that direct=auto only really works in 2pass.
And no, Leo, I haven't forgotten I owe you a reply on another thread. I've got a bunch of school stuff to do this week, so it'll still be a few more days at least.
Leo
Bright Spark User
Posts: 174
Joined: Thu Feb 22, 2007 4:39 pm

Post by Leo »

Thanks. They still don't really explain why it's better, but hey, another day. [Edit: Ok, so hit 3 mentions 2 things that don't make much sense to me.] Food for thought. Sounds like the CRF thing could be improved very slightly, and sounds like the second pass has a tiny effect, which is reassuring. I had actually already been to hits 1 and 5 of your search :)

hehe, are there not two threads for you to reply on:

· Interlacing: A PC program that can play them back *properly*
· What resolutions to use at different bitrate,size,crf q valu
jbrjake
Veteran User
Posts: 4805
Joined: Wed Dec 13, 2006 1:38 am

Post by jbrjake »

Leo wrote:They still don't really explain why it's better, but hey, another day.
I ordered them from general to specific:

* PSNR goes up slightly for every additional pass (I expect a bunch of 3-pass diehards to come out of the woodwork now, so let me add that the quality increase suffers from quickly diminishing returns)
* 2-pass more closely adheres to the bitrate distribution used in CRF. (No this can not be "improved" for CRF, it is due to the nature of rate control. It cannot more closely adhere to the distribution without reading a .stats file with input from a previous pass.)
* 2-pass makes better choices about quantizers for key frames and uses a better b-frame prediction method.
hawkman
Veteran User
Posts: 609
Joined: Sat Feb 17, 2007 9:46 pm

Post by hawkman »

jbrjake wrote:I expect a bunch of 3-pass diehards to come out of the woodwork now...
I'm anal about quality, but frankly there are better things for anyone to do with their life :)
Seifer
Posts: 5
Joined: Thu Mar 29, 2007 6:54 am

Post by Seifer »

Perhaps an example would help.

Action Film versus Non-action.

Plain 2-Pass: You encode the Non-Action film at 1500 and you like how it turns out quality wise. Unfourtunatly when you go to encode your action film, you have to guess at a higher bit-rate. If you do 1500 it will look worse while 2000 might be excessive.

CRF: You encode Non-Action at 66 percent and like it. You encode Action at 66 percent and you get a bigger but similar quality file.

CRF, then 2 Pass: You find out from the CRF that to get a certain quality you need 1700. Then when you 2-pass you set 1700 and it will distribute those bits in a better way. In scenes where you won't notice it, they will drop the quality, where as scenes where it is important the quality will raise.

My guess on this, someone correct me if I'm wrong, is that CRF 2-pass is more important the lower the CRF is. If you are doing a 66 percent encode, the movie will look pretty good no matter what. If you do a lower percent, it is better to distribute the bits in a way that your eye will see.

Either way, I wonder if that encoding time would be better spent on using advanced but slower x264 options, rather than encoding it three times through. Any thoughts?
Leo
Bright Spark User
Posts: 174
Joined: Thu Feb 22, 2007 4:39 pm

Post by Leo »

If you are doing a 66 percent encode, the movie will look pretty good no matter what. If you do a lower percent, it is better to distribute the bits in a way that your eye will see.
You realise that both ways will try to distriute the bitrate to acheive a perceived quality? The result should be very similar even at low or very high qualities... no?
jbrjake
Veteran User
Posts: 4805
Joined: Wed Dec 13, 2006 1:38 am

Post by jbrjake »

Leo wrote:You realise that both ways will try to distriute the bitrate to acheive a perceived quality? The result should be very similar even at low or very high qualities... no?
I think Seifer is suggesting that because crf is already a lot like 2-pass in how it works--just less efficient--the benefits of 2-pass over it will be more significant at higher compression rates where that efficiency will be more noticeable.

Oh, and Seifer: I'd compromise. I would both spend the time on advanced options and encode it 2 times through: once in crf but with a stats file, once in abr reading that crf stats file.
Post Reply