PDA

View Full Version : opinions on CRF vs Bitrate for first pass


morph166955
19th September 2007, 23:05
I've been reading some conflicting posts lately about this and I'm starting to get a bit confused. In the past I was always told that doing bitrate for both first and second pass helped to get to that target bitrate that I wanted since the second pass could see where the first pass "messed up" when it tried to get there. However now I'm seeing people saying that it doesn't really matter or that doing CRF produces the same thing or that the decisions made with CRF produces a second pass with a higher PSNR/SSIM output then it would with a bitrate first pass. My own tests have shown that doing CRF also produces a bitrate thats almost perfect on the second pass to what I wanted it to do (I consider almost perfect to be +/- 1kbps...mine have been with in .5). I'm curious as to what others are using on their passes and what results everyone is seeing.

Just to "eliminate" my settings from causing this difference as opposed to the crf/bitrate, heres what I'm using for my two passes (taken from a bash script that I use to make my life easier, so ignore the ${} stuff those are variables for those who dont know).

Pass 1:
x264 --pass 1 --crf 18 --threads 8 --thread-input --bframes 3 --me dia --ref 1 --subme 1 --no-dct-decimate --partitions none --progress --fps 23.976025 --output ${pass1file} buffout.yuv ${WIDTH}x${HEIGHT}

Pass 2:
x264 --pass 2 --bitrate ${bitrate} --threads 8 --thread-input --bframes 3 --b-pyramid --bime --wei\
ghtb --b-rdo --me umh --ref 5 --mixed-refs --subme 6 --trellis 1 --8x8dct --no-fast-pskip --progress --fps 23.9760\
25 --output ${pass2file} buffout.yuv ${WIDTH}x${HEIGHT}


The source that I'm using is a "low action" (cruel intentions for those wondering) bluray m2ts file piped through mencoder to produce a 1920x1040 YUV/i420 output. Also I'm using threads=8 because the version of x264 that I'm using has the threadpool patch implemented and that works better then threads auto on my octacore.

p.s. if anyone has any suggestions for how I can improve my settings please let me know, im always open to criticism.

Dark Shikari
19th September 2007, 23:08
CRF only works better on first pass if it gets you relatively close to the correct bitrate to begin with. But when it does, it is better than 1pass bitrate IMO.

Sagittaire
19th September 2007, 23:11
The most efficient way is ... 3 pass if you want the best possible prediction.

morph166955
19th September 2007, 23:33
prediction is not my major concern, quality is. Im shooting for DVD9 sizes so as long as im "close" then im happy. Close to me means yea id like to use the whole thing, but at 8.5Gig im not overly upset if im a few meg off here or there...or even as much as like 30 meg lol. Here were my results from the run with the settings from above:


Pass 1:
x264 [info]: using cpu capabilities: MMX MMXEXT SSE SSE2 SSSE3
x264 [info]: slice I:1280 Avg QP:14.12 size:232631 PSNR Mean Y:49.85 U:49.94 V:51.23 Avg:50.02 Global:49.77
x264 [info]: slice P:82016 Avg QP:16.25 size:117084 PSNR Mean Y:47.13 U:48.43 V:50.31 Avg:47.68 Global:47.41
x264 [info]: slice B:56931 Avg QP:18.46 size: 43254 PSNR Mean Y:46.26 U:48.64 V:50.77 Avg:46.99 Global:46.46
x264 [info]: mb I I16..4: 29.9% 0.0% 70.1%
x264 [info]: mb P I16..4: 37.7% 0.0% 0.0% P16..4: 58.8% 0.0% 0.0% 0.0% 0.0% skip: 3.5%
x264 [info]: mb B I16..4: 5.8% 0.0% 0.0% B16..8: 29.5% 0.0% 0.0% direct:42.8% skip:21.9%
x264 [info]: SSIM Mean Y:0.9827406
x264 [info]: PSNR Mean Y:46.803 U:48.528 V:50.509 Avg:47.417 Global:47.015 kb/s:16910.58

encoded 140227 frames, 25.14 fps, 16910.68 kb/s


Pass 2:
x264 [info]: using cpu capabilities: MMX MMXEXT SSE SSE2 SSSE3
x264 [info]: slice I:1280 Avg QP:15.69 size:170822 PSNR Mean Y:49.10 U:48.92 V:50.55 Avg:49.21 Global:48.97
x264 [info]: slice P:82016 Avg QP:17.55 size: 77018 PSNR Mean Y:47.00 U:47.94 V:50.38 Avg:47.50 Global:47.24
x264 [info]: slice B:56931 Avg QP:19.18 size: 29127 PSNR Mean Y:46.35 U:48.44 V:50.73 Avg:47.01 Global:46.50
x264 [info]: mb I I16..4: 27.3% 58.1% 14.6%
x264 [info]: mb P I16..4: 11.5% 15.9% 2.2% P16..4: 42.4% 16.9% 5.7% 0.0% 0.0% skip: 5.4%
x264 [info]: mb B I16..4: 1.3% 1.6% 0.2% B16..8: 33.3% 1.4% 3.5% direct:12.3% skip:46.4%
x264 [info]: 8x8 transform intra:53.9% inter:54.1%
x264 [info]: ref P 62.3% 18.0% 9.7% 5.6% 4.4%
x264 [info]: ref B 79.2% 11.7% 4.4% 2.8% 2.0%
x264 [info]: SSIM Mean Y:0.9821669
x264 [info]: PSNR Mean Y:46.755 U:48.156 V:50.522 Avg:47.317 Global:46.935 kb/s:11207.50

encoded 140227 frames, 6.85 fps, 11207.60 kb/s

chros
29th October 2007, 11:10
Interesting topic, thanks morph166955.

I'm using 3 "pass" for trailer reencodes from 1080p to 720p.
My current setup is:
1. --crf 18 encode with Sharktooth (ST, further) HQ-Slower profile (all the settings are from the ST HQ-Slower 2nd pass profile except for the --bitrate option)
2. 1st pass of Sharktooth HQ-Slower profile
3. 2st pass of Sharktooth HQ-Slower profile

So, I can eliminate my 2. point, it's good news.
But, what settings should I use for my 1. point?
Can I use the command line of ST HQ-Slower 1st pass (of course, except for the --bitrate option) ? (Because it's way too faster then the 2nd pass.)

my current (1.) CRF encode:
%x264file% --crf 18 --keyint %ki% --min-keyint %mki% --ref 5 --mixed-refs --bframes 16 --b-pyramid --b-rdo --bime --weightb --direct auto --filter -2,-1 --subme 6 --trellis 1 --analyse p8x8,b8x8,i4x4,i8x8 --8x8dct --vbv-maxrate 25000 --me umh --threads auto --thread-input --progress --no-psnr --no-ssim --quiet --output %tempfile% %infile% 2>&1 | tee.exe log.txt


So, can I use this? :
%x264file% --pass 1 --crf 18 --stats .stats --keyint %ki% --min-keyint %mki% --bframes 16 --b-pyramid --direct auto --filter -2,-1 --subme 1 --analyse none --vbv-maxrate 25000 --me dia --threads auto --thread-input --progress --no-psnr --no-ssim --quiet --output NUL %infile% 2>&1 | tee.exe log.txt


Thanks

chros
29th October 2007, 13:36
Answering to my question: NO. (I understand why, now.)
So I eliminated "only" the 2. pont in my cue :) (the 1st pass of the Automated 2 pass.)

I have made a test with the 10000_bc-tlr1_h108p.mov (1801 frames, 23.976 fps) and the results:

I.
1. with --crf 18 and 1st pass settings: 4066.41 kb/s
2. the second pass: 4099.2 kb/s , and the QP values:
I:48 Avg QP:14.88
P:653 Avg QP:15.74
B:1100 Avg QP:15.26

II.
1. with --crf 18 and 2st pass settings: 2543.75 kb/s
2. the second pass: 2569.4 kb/s , and the QP values:
I:52 Avg QP:18.38
P:667 Avg QP:18.37
B:1082 Avg QP:17.43


So a new question:
how are the QP values calculated?
Are they option-independent ? (which means that x264 comapres the encoded frames to the original frames)

Thanks

akupenguin
29th October 2007, 13:44
QPs chosen by CRF are option independent except for --subme=1 which uses different metrics. Yes, that is a design flaw, and maybe I'll fix it some day.

chros
29th October 2007, 17:50
QPs chosen by CRF are option independent except for --subme=1 which uses different metrics. Yes, that is a design flaw, and maybe I'll fix it some day.
Thanks for the answer.
Is this true for non-crf encodes too? (So QP is a "global quality meter" (except for the mentioned --subme=1).)

CRF only works better on first pass if it gets you relatively close to the correct bitrate to begin with.
And what happens when it's far from it ? (eg. crf bitrate is 2000, and the 2nd pass bitrate is 5000)
This time is it worse than the normal 1st pass or equal to it?

Thanks

akupenguin
29th October 2007, 18:39
Thanks for the answer.
Is this true for non-crf encodes too? (So QP is a "global quality meter" (except for the mentioned --subme=1).)
CRF is the one that changes at subme=1.
But quality-per-QP does depend slightly on other options. Any option that improves objective quality does so by both increasing quality-per-QP and reducing bitrate-per-QP.

chros
25th November 2007, 20:48
@akupenguin: have you seen this thread? http://forum.doom9.org/showthread.php?t=130376
What is your opinion about it?

Thanks