View Full Version : Second Pass Simulation
NiTroGen
9th September 2002, 00:06
I'd like to know how does this simulation work. How is it possible to calculate the frame quantizer from the desired video size?
Let's rephrase this to a programming problem:
I have the following variables: TotalFrames, TotalFrameSize, Frame[1 to TotalFrames].FrameSize and TotalVideoSize. What formula should I use to calculate Frame[1 to TotalFrames].Quantizer?
I have read both the xvid and ffvfw source codes, but because I don't know programming in C++, I couldn't find the right formula.
-h
9th September 2002, 02:51
There isn't really a correct way to determine what the quantizer should be when all you have is the frame size when quantized by a different value. There are ways you can refine your guess though.
XviD starts by guessing based on ratios:
secondpass.quant = (firstpass.quant * firstpass.bytes) / secondpass.desiredbytes
That is, if the first pass gave an 8000 byte frame at quant 2, our desired frame size of 3000 bytes would give:
quant = (2 * 8000) / 3000 = 5
It's not perfect, obviously. But then XviD keeps track of how bad its guess is, and over time is able to guess "better".
-h
milan
9th September 2002, 08:03
The problem in ffvfw second pass simulation isn't the quantizer calculation - XviD code does this, but the guessing of frame size. From the first pass old quantizer (usualy 2) and old frame size is known. For each frame ffvfw obtains new quantizer and it has to compute new frame size. For now it is very simple: if old frame was compressed with quantizer 2 and had 50000 bytes and new quantizer is for example 4, new frame will have 25000 bytes. This of course isn't exact and I'm thinking about something better. For example some random value could be added or substracted from calculated value. Any suggestions are wellcome and if they will be useful, they will be immediatelly implemented.
MfA
9th September 2002, 09:37
If you are looking for a better way be sure to look at Zhihai He's p-domain work.
milan
9th September 2002, 09:53
Thank you. I downloaded the paper and quickly read it. As I see, that quote about 'immediate implementation' was quite hurried :)
That work is surely interesting, but it will take me some time to understand it fully and to try to code it.
NiTroGen
9th September 2002, 11:22
Originally posted by MfA
If you are looking for a better way be sure to look at Zhihai He's p-domain work.
Where can I find this paper?
milan
9th September 2002, 11:42
I did google search for "Zhihai He" and found this page: http://vision.ece.ucsb.edu/alumni/zhihai/ and this PDF: http://www-iplab.ece.ucsb.edu/zhihai/papers/icassp011.pdf
MfA
9th September 2002, 11:53
Well a google search for "Zhihai-He p-domain" works ;)
It would need partly to be implemented in core though.
NiTroGen
9th September 2002, 12:55
Thanks guys...
MfA
9th September 2002, 16:10
BTW, he leaves out how exactly you should map pt (percentage of zeros at target rate) to qt (the corresponding quantizer). Thats in his thesis (2.3.2).
-h
9th September 2002, 16:38
BTW, he leaves out how exactly you should map pt (percentage of zeros at target rate) to qt (the corresponding quantizer). Thats in his thesis (2.3.2).
I'm sure that could be extrapolated well enough by experimenting (or just debugging).
This theory will be slightly incorrect due to intra prediction (unless we run that too for appropriate blocks), but overall seems a sound method for getting it "right". As soon as my new keyboard shows up I'll put this into XviD's dev branch.
-h
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.