How Smart Is Handbrake with 2 Passes?

General questions or discussion about HandBrake, Video and/or audio transcoding, trends etc.
Post Reply
ozmosis82
Novice
Posts: 61
Joined: Mon Jul 23, 2007 7:17 pm

How Smart Is Handbrake with 2 Passes?

Post by ozmosis82 »

If I were to encode a film at, say, ABR 2500kbps, and then again at 2800kbps, both with 2 passes each, would it keep the less intense scenes at the same bitrate for both, but increase the bitrate even more during the more complex scenes? Or would it just tend to boost everything up a little bit more at the expense of saving the extra bits for complex scenes?
PuzZLeR
Bright Spark User
Posts: 287
Joined: Tue Apr 24, 2007 4:01 am

Post by PuzZLeR »

The title would be more appropriate as "How Smart Is x264 with 2 Passes?" (Not that HandBrake is dumb... :lol:)

Not sure if this will answer your question but here goes.

Increasing the bitrate by 300kbps in 2-pass ABR does not actually automatically "shift" everything up by an exact 300kbps more. In fact, it *is* "smart".

Even though it will have that extra little bitrate more to play with, it will still keep about the same amount of bitrate to some static scenes (like it did for 2500kbps) if x264 doesn't feel it needs more, but will instead add EVEN MORE to the complex scenes (since you gave it more in your settings).

One thing it won't do for sure (at least in theory) is that if you increase the average bitrate, there will be no scene with less bitrate than when encoding from the lower bitrate. In other words, with the extra bitrate, it will not get overly excited about the complex scenes whereas it will add even less to the static scenes.

Funny. Everybody talks about the fact that CRF is unpredictable. In fact, in this case, CRF would be much more likely to have a "straight shift" uniformly throughout the encode with a higher % value - even almost proportionally.
saintdev
Enlightened
Posts: 146
Joined: Wed Dec 20, 2006 4:17 am

Post by saintdev »

I've never tried this before, but the way that 2-pass works, is the first pass' stats file is used to make decisions on what frame types to use at any given point. So if you were to increase the bitrate for the second pass, it would just use the frame types that were generated for the lower bitrate, which might not be as optimal as if you had used the same bitrate for the first pass.
PuzZLeR
Bright Spark User
Posts: 287
Joined: Tue Apr 24, 2007 4:01 am

Post by PuzZLeR »

Hey saintdev,

First of all, I don't think you can do that in HandBrake: enter your settings for a first pass in ABR, then have different settings for a second pass in the ABR, in that EXACT encoding. Not saying you can't - you certainly can with hardcore encoding raw with x264 - but how do you do that with HandBrake?

Second of all, I wouldn't recommend it anyway unless you absolutely know what you're doing. When you enter your settings for the first pass, information is entered into the stats file according to the bitrate and other parameters you gave x264. Then if you suddenly change your settings for your second pass, then the info gathered in the first pass could be absolutely useless for the settings in the second pass and will not optimally give you the best quality. The encoder is encoding your final file to settings with, now "wrong", information regarding the first pass.

There are reasons to do this though. Some are encoding the first pass with speed, but still gathering info and applying it to the second pass. Sure people do it all the time, and there's other reasons to do this too, but you really have to know what you're doing.
jbrjake
Veteran User
Posts: 4805
Joined: Wed Dec 13, 2006 1:38 am

Post by jbrjake »

PuzZLeR wrote:First of all, I don't think you can do that in HandBrake: enter your settings for a first pass in ABR, then have different settings for a second pass in the ABR, in that EXACT encoding. Not saying you can't - you certainly can with hardcore encoding raw with x264 - but how do you do that with HandBrake?
Don't set two-pass in HandBrake.

On the first pass, include pass=1:stats=/path/to/stats-file.stats in the x264 options

On the second pass, include pass=2:stats=/path/to/stats-file.stats

Eddyg wanted to make a way to customize all the 1st pass options while still using HandBrake's two-pass function, but I veoted it because, like you said, it's easy to screw up and choose 1st pass options that will lead to "bit curves to not converge" or however the x264 error reads.

Instead, he added --turbo, which applies the options mencoder and megui use for 1st pass.
saintdev
Enlightened
Posts: 146
Joined: Wed Dec 20, 2006 4:17 am

Post by saintdev »

PuzZLeR wrote:Hey saintdev,

First of all, I don't think you can do that in HandBrake: enter your settings for a first pass in ABR, then have different settings for a second pass in the ABR, in that EXACT encoding. Not saying you can't - you certainly can with hardcore encoding raw with x264 - but how do you do that with HandBrake?
You can always tell x264 to output and/or use a stats file with the advanced x264 options.
PuzZLeR wrote:Second of all, I wouldn't recommend it anyway unless you absolutely know what you're doing. When you enter your settings for the first pass, information is entered into the stats file according to the bitrate and other parameters you gave x264. Then if you suddenly change your settings for your second pass, then the info gathered in the first pass could be absolutely useless for the settings in the second pass and will not optimally give you the best quality. The encoder is encoding your final file to settings with, now "wrong", information regarding the first pass.
Agreed. All I was stating was that the stats file is really bitrate-independent, it just suggests what type of frame the encoder should use so it can make better decisions as far as the actual frame type it writes to the file. I would always recommend using the same bitrate for both the first and second pass and never ever recommend using different bitrates. This way your the frame type suggestions are actually accurate. However, you probably could do it. Doubt the final video would look too good, but you could do it.
eddyg
Veteran User
Posts: 798
Joined: Mon Apr 23, 2007 3:34 am

Post by eddyg »

jbrjake wrote: Eddyg wanted to make a way to customize all the 1st pass options while still using HandBrake's two-pass function, but I veoted it because, like you said, it's easy to screw up and choose 1st pass options that will lead to "bit curves to not converge" or however the x264 error reads.

Instead, he added --turbo, which applies the options mencoder and megui use for 1st pass.
That was whilst developing the turbo options, during which I got loads of crashes from x264. It *really* doesn't like mismatched options :)

Cheers, Ed.
PuzZLeR
Bright Spark User
Posts: 287
Joined: Tue Apr 24, 2007 4:01 am

Post by PuzZLeR »

@jbrjake:
Thanks. Will give it a try. I am particularly interested in a fast first pass when using ABR...
eddyg wrote: That was whilst developing the turbo options, during which I got loads of crashes from x264. It *really* doesn't like mismatched options :)
Hey Ed,

I do believe it was crashing for a good reason... :D

However, I don't know how long ago that was happening with you, but I hear that there's been modifications to x264 regarding the stats file and flexible multi-pass options in recent builds. Not sure if it's worth it for the average HB user, but if you're the curious type you may want to revisit it.
Post Reply