Log in

View Full Version : X264 Pass Differences


jdobbs
29th August 2009, 17:56
I've been doing a lot of testing of Blu-ray reencodes using the X264 "--preset veryfast" setting and I noticed that in all my encodes the second pass is considerably faster than the first pass (~25fps compared to ~15fps). That seems to be the opposite of what I see in other presets. I'm sure there is a good reason, but I'm just not seeing it and its driving me nuts... I was just wondering if someone could explain it?

Here are my command lines -- almost identical except the first pass outputs to NUL.


"E:\BD_Rebuilder\tools\x264.exe" "E:\WORKING4\WORKFILES\VID_00102.AVS" --preset veryfast --bitrate 7114
--level 4.1 --sar 1:1 --fps 24000/1001 --aud --vbv-bufsize 25000 --keyint 24 --min-keyint 1
--ipratio 1.1 --pbratio 1.1 --vbv-maxrate 35000 --threads auto --thread-input
--stats "E:\WORKING4\WORKFILES\VID_00102.AVS.MKV.stats" --pass 1
--output NUL
"E:\BD_Rebuilder\tools\x264.exe" "E:\WORKING4\WORKFILES\VID_00102.AVS" --preset veryfast --bitrate 7114
--level 4.1 --sar 1:1 --fps 24000/1001 --aud --vbv-bufsize 25000 --keyint 24 --min-keyint 1
--ipratio 1.1 --pbratio 1.1 --vbv-maxrate 35000 --threads auto --thread-input
--stats "E:\WORKING4\WORKFILES\VID_00102.AVS.MKV.stats" --pass 2
--output "E:\WORKING4\WORKFILES\VID_00102.AVS.MKV" I thought about the fact that fast first pass doesn't really have any effect with that preset, and that might contribute to the difference in behaviour with other higher quality presets -- but is seems like 10fps (60% speed difference) is a lot of delta between passes.

shon3i
29th August 2009, 18:14
@jdobbs, sorry for ot but why use settings that are incompatible with Blu-ray standard like Level 4.1 require 4 or more slices. I know that maybe no one has ever had a problem with SAP, but why not follow the standard, btw you use vbv buffer 25000 which limits peak bitrate over 25mbps so vbv maxrate of Level 4.0 will not limit the quality anyway.

:)

jdobbs
29th August 2009, 18:19
@jdobbs, sorry for ot but why use settings that are incompatible with Blu-ray standard like Level 4.1 require 4 or more slices. I know that maybe no one has ever had a problem with SAP, but why not follow the standard, btw you use vbv buffer 25000 which limits peak bitrate over 25mbps so vbv maxrate of Level 4.0 will not limit the quality anyway.

:) No reason really, the slice requirement is something that I've never seen enforced anywhere -- so I ignore it. I guess it might come back to bite me at some point, like when they start putting more powerful processors on SAPs... if I remember correctly the vbv buffer size can change depending upon what I set for destination size, it just happened to be 25000 here.

LoRd_MuldeR
29th August 2009, 18:25
Well, the frame-type decision is made in the first pass and as far as I know the "lookahead" part is still not multi-threaded. So it may be that serial part that makes your first pass slow.

So with "slower" presets this just doesn't show up, simply because all the rest is much slower. But when everything is speeded-up (as with "veryfast" preset), the lookahead can become the bottleneck easily...

jdobbs
29th August 2009, 18:29
Makes sense. Thanks.

Snowknight26
29th August 2009, 18:30
The default is --b-adapt 1 still so I don't think that's the issue.

kemuri-_9
29th August 2009, 18:55
the speed cost seen there is likely vbv-lookahead in combination with b-adapt 1.

according to

h->param.rc.i_lookahead = x264_clip3( h->param.rc.i_lookahead, 0, X264_LOOKAHEAD_MAX );
{
int maxrate = X264_MAX( h->param.rc.i_vbv_max_bitrate, h->param.rc.i_bitrate );
float bufsize = maxrate ? (float)h->param.rc.i_vbv_buffer_size / maxrate : 0;
float fps = h->param.i_fps_num > 0 && h->param.i_fps_den > 0 ? (float) h->param.i_fps_num / h->param.i_fps_den : 25.0;
h->param.rc.i_lookahead = X264_MIN( h->param.rc.i_lookahead, X264_MAX( h->param.i_keyint_max, bufsize*fps ) );
}


the lookahead size in the above case would be set to
MIN( 40, MAX( 24, 35000/25000 * ~24 ) ) , so 33.

b-adapt 1 takes some time to perform and this should be noticeable compared to the rest of veryfast's settings when compounded with vbv-lookahead on a multicore processor.

ajp_anton
29th August 2009, 19:21
--preset veryfast includes --b-adapt 1 and --no-mbtree.

Dark Shikari
29th August 2009, 19:23
--preset veryfast includes --b-adapt 1 and --no-mbtree.But it still does VBV lookahead.

Remember, presets like "veryfast" are so fast that they're about the same speed as x264's "fast first pass" system, so the first pass will surely be slower--it simply does more work! (since the first pass does frametype does frametype decision)

At this point, it would be better to use ABR mode if trying to maximize performance.

jdobbs
29th August 2009, 20:04
Thanks to all. The explanation is appreciated.