Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: 2-pass encoding vs. constant quality (Read 25561 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

2-pass encoding vs. constant quality

Are there any advantages of using 2-pass encoding compared to constant quality/quantizer, except using a target filesize? If this is not an issue for me, am I better off using 1-pass, quality- and speedwise?

I read somewhere that the target of 2-pass encoding is to use a quantizer as constant as possible, is that true? 
If yes, why do so many people claim that 2-pass is inherently better?

2-pass encoding vs. constant quality

Reply #1
Quote
I read somewhere that the target of 2-pass encoding is to use a quantizer as constant as possible, is that true?

Not exactly.  My understanding is that 2-pass will try to use higher quantizers where it thinks you won't notice it, and lower quantizers where it thinks they are needed.  There is some "artificial intelligence" involved, while 1-pass quantizer blindly applies the same quantizer to every frame.  According to this theory, a 2-pass encode which targets the same filesize as your previous 1-pass encode should look slightly better.
May the FOURCC be with you...

2-pass encoding vs. constant quality

Reply #2
Wouldn't it be possible to use this "intelligence" for a one pass encoding as well? If, for example, it is analyzing the movement of the scene, it could do so as well in a 1-pass scenario. Or is there really so much more behind it?

2-pass encoding vs. constant quality

Reply #3
I don't know, but there'd better be more behind it (given that it takes twice as long to do!)

Honestly, I tend to use 1-pass quantizer for most things anyway because I'm too impatient.  I only go with 2-pass when I absolutely need a file to be a specific size.
May the FOURCC be with you...

2-pass encoding vs. constant quality

Reply #4
A 2-pass encode at the same filesize as 1-pass fixed quantizer encode will (should in theory) always look better.  I would only recomend 1-pass quntizer based encodings at the lowest quantizer availble and only then for transcoding to another format.  Otherwise 2-pass is the way to go.

1-pass enocdes can be made to conform to a certain filesize or bitrate using guesstimation.  This is because when analizing a scene for motion in a 1-pass encode you don't know the complexity of the motion to come.  Therefore if you use to much bitrate in the first half of the film, but the second half was more complex, the second half will look terrible.  Let me relate it to  audio codecs.

All VBR audio codecs (IIRC) try to encode to a specific SNR.  This is like 1-pass quantizer based video encodes that compress the film by a set ratio.  2-pass or nth-pass encodes of video don't aim for a set quality but for a set bitrate of filesize.  Because they're 2-pass they can better estimate where the bitrate is needed because they no which parts of the movie are complex and which are not.

Hope this all makes sense.

2-pass encoding vs. constant quality

Reply #5
Great explanation.  And it brings to mind a question (slightly OT) which I've been wondering about for some time.  Why doesn't LAME have a 2-pass mode?  Similar to the theory with 2-pass video, one would expect 2-pass audio to give the best quality for a given file size...
May the FOURCC be with you...

2-pass encoding vs. constant quality

Reply #6
Indeed a two pass mode for audio codecs would be able to accurately dictate a filesize or bitrate but who wants to with an audio codec.  I certainly don't.  I guess it would be interesting though.

2-pass encoding vs. constant quality

Reply #7
Quote
The process can be applied to 1-pass using guesstimation.  This is because when analizing a scene for motion in a 1-pass encode you don't know the complexity of the motion to come.  Therefore if you use to much bitrate in the first half of the film, but the second half was more complex, the second half will look terrible.

I don't understand that. If the second half is more complex, then constant quantizer will use more bits on it!

The only reason, I can see, why 2-pass could be theoretically better (qualitywise), is that the quantizer value is not related to the perceived quality under certain conditions. But then, how would a 2-pass mode know that?

2-pass encoding vs. constant quality

Reply #8
Quote
Quote

The process can be applied to 1-pass using guesstimation.  This is because when analizing a scene for motion in a 1-pass encode you don't know the complexity of the motion to come.  Therefore if you use to much bitrate in the first half of the film, but the second half was more complex, the second half will look terrible.

I don't understand that. If the second half is more complex, then constant quantizer will use more bits on it!

The only reason, I can see, why 2-pass could be theoretically better (qualitywise), is that the quantizer value is not related to the perceived quality under certain conditions. But then, how would a 2-pass mode know that? 

Sorry, that was probably written poorly.  What I was referring to was applying the same sort of 'intelligence' you mentioned earlier to 1-pass encoding (i.e. 1-pass bitrate or filesize based encoding).

[span style='font-size:8pt;line-height:100%']Note: Original post now edited.[/span]

2-pass encoding vs. constant quality

Reply #9
this is a funny issue in many respects;
recently i stacked 1pass(limited quantizers) to 2pass encoding(unlimited quants);
the only thing 2pass did different was that it almost never used quant2,but rather started from quant3....and subsequently it had least higher quants than 1pass encoding....
and then,i want my still scenes on quant2;no doubt about it;i kept my 1pass encoding....erased 2pass quant3 galore...

but indeed,2pass might save you SOME bitrate(or you may try 1pass in 3-x mode..heh) but i'm wondering will you notice a difference between my 1pass and other folks 2pass'....
and if small percentage of quality increase(if existant at all..) is justified with 2x encoding time.....

fcc said it well;
Quote
According to this theory, a 2-pass encode which targets the same filesize as your previous 1-pass encode should look slightly better.

but again,"slightly better" is a flexible term...
once upon a time i though considerable savings in bitrate are possible by 2pass way....now i don't think they are....
now i save my time....
here in croatia we have a saying "speed is a virtue"....

to quote undercut;
Quote
But why use one pass encoding at all and not two pass? I think it depends on trade-offs and your taste. Some will claim that two pass encoding will always result in better quality, but that's completely subjective and often false. If you have two MS-MPEG4 video both of same size, one done in one pass and other in two pass, it's not possible to say one is conclusively better than the other. Technically, there are no wasted bits in both of these files. All the bits are used up somewhere. Question is how well and effectively the bits are used up to suit our eye.

http://www.undercut.org/Nandub_OnePass/

some will call this a "sacrilige";i call it "truth"....
my eyes prefer top-notch still scenes while motion may block(but up to particular quant;say 6 till 9....)
also,i'm not using his stuff,but normal nandubRC2....

i think i have the stats(1pass my settings,2pass muf's settings..see filename);
Quote
DivX DRF Analyzer v0.9.5 Report!
File Name: D:\Video\Finished\3rd_rock_[].avi
FourCC: DIV3
Codec: MSMPEG4
Resolution: [ Width: 512 Height: 384 ]
Frame Rate: 25.000 frames per second
The Video has 31796 frames [ 00:21:11 ]

Average Frame quality is  MEDIUM   [Average DRF/quantizer is 3.80]
Standard Deviation: Quality is MEDIUM   [Std. Deviation is 1.17]
Image Resolution is MEDIUM

There are NO frame drops ( NO drops is better )

Recomended Resolution: [432x320]  (Target DRF/quantizer=2.8)
The filesize should be larger!

Performance Caracteristics:
Macroblocks per frame: 768
The Width is multiple of 32

Kilobits per Second: 1200.60
Kilobits per Frame: 47.99
Kilobits per Macroblock: 0.062
Bits per Pixel: 0.25

Frame Quality Statistics :

DRF=1&2:   3354   10.7%
DRF=3:  10975   34.9%
DRF=4:  9441   30.0%
DRF=5:  5230   16.6%
DRF=6:  1684   5.4%
DRF=7:  499   1.6%
DRF=8:  260   0.8%
DRF=9:  0   0.0%
DRF>9:  0   0.0%
KeyF/DeltaF:  1.12%
KeyDRF<4:   0
KeyDRF=4:   326
KeyDRF>4:   27

AverageKeyDRF:   4.11
MAXDRF:   8
AverageDRF:   3.80
Deviation:   1.17

http://www.geocities.com/analyzerDRF/



Quote
DivX DRF Analyzer v0.9.5 Report!
File Name: D:\Video\Finished\3rd_rock_[muf].avi
FourCC: DIV3
Codec: MSMPEG4
Resolution: [ Width: 512 Height: 384 ]
Frame Rate: 25.000 frames per second
The Video has 31796 frames [ 00:21:11 ]

Average Frame quality is  MEDIUM   [Average DRF/quantizer is 3.77]
Standard Deviation: Quality is HIGH   [Std. Deviation is 0.70]
Image Resolution is MEDIUM

There are NO frame drops ( NO drops is better )

Recomended Resolution: [432x320]  (Target DRF/quantizer=2.8)
The filesize should be larger!

Performance Caracteristics:
This video seems to have too FEW Keyframes. May degrade image quality and seeking.
Macroblocks per frame: 768
The Width is multiple of 32

Kilobits per Second: 1212.68
Kilobits per Frame: 48.47
Kilobits per Macroblock: 0.063
Bits per Pixel: 0.25

Frame Quality Statistics :

DRF=1&2:   68   0.2%
DRF=3:  11739   37.2%
DRF=4:  15486   49.0%
DRF=5:  4062   12.9%
DRF=6:  212   0.7%
DRF=7:  30   0.1%
DRF=8:  1   0.0%
DRF=9:  0   0.0%
DRF>9:  0   0.0%
KeyF/DeltaF:  0.63%
KeyDRF<4:   7
KeyDRF=4:   191
KeyDRF>4:   0

AverageKeyDRF:   3.95
MAXDRF:   8
AverageDRF:   3.77
Deviation:   0.70

http://www.geocities.com/analyzerDRF/

2-pass encoding vs. constant quality

Reply #10
Quote
the only thing 2pass did different was that it almost never used quant2,but rather started from quant3....and subsequently it had least higher quants than 1pass encoding....

uhmm, but isnt that something to be expected? i mean, what 2-pass mode is trying to achive is filesize and constant subjective quality, so it has to reduce some of the parts and increase some other (bitrate wise). 

(but i agree, i dont care that much for that 10 second shooting part when all other 'love scenes' look like piccasso. (and again that ratio is dictated by the average bitrate, so i would expect that the formula should fail easily in smaller average bitrate conditions.))
PANIC: CPU 1: Cache Error (unrecoverable - dcache data) Eframe = 0x90000000208cf3b8
NOTICE - cpu 0 didn't dump TLB, may be hung

2-pass encoding vs. constant quality

Reply #11
Quote
what 2-pass mode is trying to achive is filesize and constant subjective quality

regarding filesize;check this out
http://i4004i4004.bizhosting.com/cgi-bin/i...atrix/pdesk.png
notice the
Wild at heart_.avi
and
Gable&Lombard.avi

was this 1pass limited quants,or 2pass encoding? 
both movies 2h long,both have awfull lot of them 2quants..  ..(but that's also payed for with some niners,obviously...  )

all in all...perfectly acceptable....

2-pass encoding vs. constant quality

Reply #12
Quote
was this 1pass limited quants,or 2pass encoding? 

yes ic what you mean, actually i did encode a few video guides with 1pass xvid the other  day and the filesize was perfect (but the video was like a lot of static screens, so that isnt surprising)

'brzina je vrlina'  ?
PANIC: CPU 1: Cache Error (unrecoverable - dcache data) Eframe = 0x90000000208cf3b8
NOTICE - cpu 0 didn't dump TLB, may be hung

2-pass encoding vs. constant quality

Reply #13
Quote
'brzina je vrlina' ?

sweet!
 

Quote
and again that ratio is dictated by the average bitrate, so i would expect that the formula should fail easily in smaller average bitrate conditions

well said....at some point 1pass may just start to drop frames or to increase the quant's in insane manner....
anyway,i didn't experienced either..it seems i know what i can do and what i can't do with mpeg4(  )

2-pass encoding vs. constant quality

Reply #14
Just adding some info that hasn't been mentioned, yet.

Basically, an almost constant-quantizer-encode more or less is what XviD tries to reach in 2nd pass of a two-pass. (Slight fluctuation isn't necessarily a bad thing.)

Given that you can live with a file not reaching quite the size you aim at, you could give 2-pass a miss and use a constant quantizer instead. (Needless to say, CBR is a no-no.) Except for two slight advantages of two-pass:
- Two-pass in XviD attains quant=2 to those few frames where no gain is expected from compressing them higher (i.e. they're small enough at quant=2). Possibly a minimal gain in quality.
- Two-pass allows to give I-frames a slight boost. Whether this actually makes a positive difference remains somewhat unclear, but I'd say it probably does.

2-pass encoding vs. constant quality

Reply #15
Quote
Basically, an almost constant-quantizer-encode more or less is what XviD tries to reach in 2nd pass of a two-pass.

how can you claim this,as we all know that constant-quantizer encodings result in unpredictable filesizes???

filesizes are achieved by varying the quantizer!!!

you are wrong!

i thought i linked this
http://www.geocities.com/analyzerDRF/
?
inspect your xvid files,as it seems you never did;if you do  2pass with target bitrate in mind(quants with wide span) they are fluctutating,FOR SURE!
otherwise you would get constant quant and unpredictable bitrate....
more hi-motion mean more high quants....
it's simple really.....

codec's only mechanism to regulate bitrate are quants....

2-pass encoding vs. constant quality

Reply #16
Code: [Select]
DivX DRF Analyzer v0.9.5 Report!
File Name: D:\lightwave_matroska_ac3_dvd_rips_guides\explosive_eff_w_hyperwoxels\hyper.avi
FourCC: XVID
Codec: XviD0028
Resolution: [ Width: 512 Height: 384 ]
Frame Rate: 29.970 frames per second
The Video has 178610 frames [ 01:39:19 ]

Average Frame quality is  HIGH    [Average DRF/quantizer is 2.96]
Standard Deviation: Quality is MEDIUM    [Std. Deviation is 1.38]
Image Resolution is MEDIUM

The file has Packeted Frames!

There are NO frame drops ( NO drops is better )
This video may have some frames with VERY POOR Quality!

Recomended Resolution: [496x368]  (Target DRF/quantizer=2.8)
The filesize should be larger!

Performance Caracteristics:
This video seems to have too FEW Keyframes. May degrade image quality and seeking.
Macroblocks per frame: 768
The Width is multiple of 32

Kilobits per Second: 710.78
Kilobits per Frame: 23.71
Kilobits per Macroblock: 0.031
Bits per Pixel: 0.12

Frame Type Statistics :
I Frames: 0.41%
P Frames: 64.66%
B Frames: 34.93%
S Frames: 0.00%
N Frames: 0.00%
(More Advanced Codecs use B and S frames)
Frame Quality Statistics :

DRF=1&2:    90695    51.0%
DRF=3:  25410    14.3%
DRF=4:  48332    27.2%
DRF=5:  5559    3.1%
DRF=6:  2980    1.7%
DRF=7:  2588    1.5%
DRF=8:  834    0.5%
DRF=9:  625    0.4%
DRF>9:  859    0.5%
KeyF/DeltaF:  0.41%
KeyDRF<4:    630
KeyDRF=4:    23
KeyDRF>4:    75

AverageKeyDRF:    2.34
MAXDRF:    14
AverageDRF:    2.96
Deviation:    1.38

now, this is the report of that 1pass thingy, interesting data, but nothing that would really learn me anything... (or maybe i'am missing something..?)
PANIC: CPU 1: Cache Error (unrecoverable - dcache data) Eframe = 0x90000000208cf3b8
NOTICE - cpu 0 didn't dump TLB, may be hung

2-pass encoding vs. constant quality

Reply #17
Quote
Quote
Basically, an almost constant-quantizer-encode more or less is what XviD tries to reach in 2nd pass of a two-pass.

how can you claim this,as we all know that constant-quantizer encodings result in unpredictable filesizes???

filesizes are achieved by varying the quantizer!!!

I don't see a contradiction. He even said "more or less". Of course the codec needs to vary the quantizer, otherwise the output filesize would be restricted to 31 different values. If for example a "constant" quantizer setting of 3.4 yields the required bitrate, then a good 2-pass algorithm should find it and use mostly quantizer 3 or 4.

If this really is the target of the algorithm, or in how far this objective is accomplished is another question...

2-pass encoding vs. constant quality

Reply #18
Exactly.

2-pass encoding vs. constant quality

Reply #19
continuum;
Quote
I don't see a contradiction. He even said "more or less".

he said;
Quote
Basically, an almost constant-quantizer-encode more or less is what XviD tries to reach in 2nd pass of a two-pass.


now you do a drfanalyze on your 2pass xvid stuff,and tell me if it was "almost" or it was " more or less" OR IT WAS NOT.....
i say it is NOT....there will be bunch of different quants there,so there's no talk about "almost" or "more or less".....
you may as well post a drfanalyize file so we all see it....

what's "more or less"?
quants 2-3?
qunats 2-9 used?
quants 2-11?

there is constant quant(no filesize prediction),and there is varied quant(filesize can be predicted,wether it be 1 or 2 passes),and that's it;there's no in between,there's no "almost constant-quantizer-encode more or less is what XviD tries to reach in 2nd pass of a two-pass"
there's no such thing...
no "almost constant-quantizer"!

inspect your files and tell me if i was right...
no,it's not just semantics,but putting the things on their places!
cquant and varied quant are 2 very different things!

2-pass encoding vs. constant quality

Reply #20
I would call this 'trying really hard to misunderstand an easy idea'.

But to help you out: The stronger the compression, the more the quantizer varies. If you have a, let's say, 70% quality, it'll stay, in the range of 2 quantizers.

2-pass encoding vs. constant quality

Reply #21
I repeat what I have said above:
Quote
If this really is the target of the algorithm, or in how far this objective is accomplished is another question...

I don't know the answer (your measurements seem to indicate that the answer is "no").

Nevertheless it would be theoretically possible that a codec uses only two adjacent quantizer values for the whole movie.

2-pass encoding vs. constant quality

Reply #22
Quote
I would call this 'trying really hard to misunderstand an easy idea'.

But to help you out: The stronger the compression, the more the quantizer varies. If you have a, let's say, 70% quality, it'll stay, in the range of 2 quantizers.

so who was wrong,you or me?
to reiterate,i said quants dance(to respect target filesize,off course),and you were real easy to misunderstand when you said that xvid is "almost" constant in 2pass....i say "like hell it is!"
again;there's no "almost";there's varied or constant quant;if encoding uses more than 1 quant,then it means it's not fixed!
also,narrow quant span means less filesize predictability...

2 quantizers?
ok,let's see analyze of your typical xvid encoding,and let's see if you're doing stuff on 2 quantizers(as that means very low predictability too...go on,man,show me encoding with quants2-3 that hit the filesize,or 3-4,or 4-5 or...or...)

[personal attacks removed by moderation]

i'm off untill you prove yourself right with drfanalyzed file....(but you would have to produce real magic to save yourself...)

again;2pass producing "almost" fixed quant?
go on,admit it that this is silly thing to say!
2pass is MENT to be used for getting the filesize OK,and c.quantizer is MENT to be used in 1pass mode(to achieve constant quality;off course)...

ahhh.....

continuum;
Quote
Nevertheless it would be theoretically possible that a codec uses only two adjacent quantizer values for the whole movie.

why "theoretically"?
just limit them quants to desired span!
like p-frames 2-3 or 3-4 or...the i-frames will follow anyway.....
that's exactly what i'm doing in 1pass limited quants mode(only i use wider span so target filesize is respected)
2-3,3-4 etc is unpredictable....ABR mechanism can't kick in with such narrow span....

it's stupidity to call ANY mpeg4 1pass codec CBR as it's NOT(i never saw mpeg4 codec that produced CBR bitrate!can't happen!every frame is different!);on the other hand,mpeg1/2 produce  CBR,but there it is also artificial(padding the stream with zeroes if there's less bitrate than targeted....and increasing(higher numbers) the quants to respect the upper limit...)
we may go so far to say that this is also applied in audio compression (as perfect CBR would mean for example constant 3khz sinusiod...but..it happens that 3khz sinus is not really a music...is it....i wan't to say that CBR128kbit mp3 is ABR underneath all that zero padding and cutting the peaks.(same as mpeg1/2 CBR)...but i'm not audio encoding freak,so i may be wrong...if i am,please correct me....i say that CBR modus is something that nature doesn't know...in audio or video...)

someone that says how "CBR" in mpeg4 is a "no-no" never actually did a single 1pass encoding and analyzed it's quants!
why is he talking then?
beats me!

2-pass encoding vs. constant quality

Reply #23
Quote
why "theoretically"?
just limit them quants to desired span!
like p-frames 2-3 or 3-4 or...the i-frames will follow anyway.....
that's exactly what i'm doing in 1pass limited quants mode(only i use wider span so target filesize is respected)

No, I mean the purpose of the 2-pass algorithm is (or is suggested to be) finding these two quantizers and the needed relation between their number (e.g. 2/3 q3 and 1/3 q4). You could model this behaviour in a 1-pass scenario only if you exactly knew these values a priori. (It's possible that you make an educated guess, but this will never be totally accurate.)

Now maybe the exact computation is extremely difficult, some special "tricks" change the quantizer distribution (e.g. use not too much bits on complex scenes) or the assumption is flat out wrong -- I don't know...

2-pass encoding vs. constant quality

Reply #24
Quote
No, I mean the purpose of the 2-pass algorithm is (or is suggested to be) finding these two quantizers and the needed relation between their number (e.g. 2/3 q3 and 1/3 q4).


hmm...i thought i was clear;
but even clearer;
try 1pass quants 3-4 and try 2pass quants 3-4.....(now look for differences)

main purpose of 2pass is to hit target size while achieving OK quality.....
the first premise(hit the target bitrate) says that "two quantizers used" is a silly concept to say the least......just too narrow span!

does that brin git to it's place now?
filesize AND quality,and not quality alone;quality alone is c.quant's domain(also called constantquality encoding..as you see narler do...)

i suggest;
doing encodings with different modes and different quants span,and after that doing analysis....
that way no confusion is possible......
i'm only saying this after many encodings(with different modes) and many drfanalyized files(and many clips visually inspected,sure...drfanalyze is worth nothing if you can't find a relation between quants used and achieved frame quality..)...and i mean MANY....i never saw anything that would say otherwise...


/ivo