PDA

View Full Version : GK and XviD bitrate/filesize issue tip


Kheffer
24th February 2005, 20:48
While playing with XviD and Gordian Knot encoding, I've discovered an interesting behavior, which may be a reason for various oversized/undersized problem reported here. I'm not sure whether it is a bug or a "feature" though.

Here it goes. The transfer of bitrate/filesize info from GK to XviD depends on the position of the Target_bitrate/Target_filesize toggle button on the XviD configuration panel. If, when you set your second pass, the button shows "target filesize", GK will overwrite the values that appear next to the button (although GK may not necessarily change it on the panel itself). You may change the values manually at this point to anything you want and it will have no effect. The encoding process will use the bitrate and filesize values set in GK.

However, if, when you set your second pass, the button shows "target bitrate", the value that appears next to the button will overwrite anything that comes from GK. It may be some arbitrary value or something that remained from the previous job. GK will not change it. The encoding process will use this target bitrate value, ignoring anything you set in GK. Interestingly, the GK log will still tell you that the video is encoded at the bitrate specified in GK, although in reality a completely different bitrate may be used. The log will actually lie to you.

jggimi
24th February 2005, 21:28
Moved to development.

xistan
25th February 2005, 06:13
This might actually be the reason why many of my XviD encodes have gone haywire. I had a problem once when all my encodes ended up with 700 kps bitrate no matter what settings I used. I don't remember if I did set the second pass settings explicitly in GK or not, but this is very likely to be the case.

/C

len0x
25th February 2005, 15:10
All this makes no sense to me (coz I can assure you that target size/bitrate selection has no influence on the codec settings). You should read my post here: http://forum.doom9.org/showthread.php?s=&threadid=88756&perpage=20&pagenumber=3
(about how codec settings are set and picked up).

Kheffer
26th February 2005, 17:28
Originally posted by len0x
All this makes no sense to me (coz I can assure you that target size/bitrate selection has no influence on the codec settings). You should read my post here: http://forum.doom9.org/showthread.php?s=&threadid=88756&perpage=20&pagenumber=3
(about how codec settings are set and picked up).

At first, it did not make any sense to me either. However, these are the facts and you cannot argue with the facts. So, the "sense" must be wrong. :) Actually, after reading your messages the whole thing started making more sense.
I think the problem is that GK always passes the "target filesize" settings to XviD and does not pass the "target bitrate" ones. XviD, however, can use either. In fact, these 2 settings are independent in XviD. If you change one, XviD will not automatically adjust the other to match it. It's quite reasonable, since normally XviD does not know at the time of set-up what exactly you are encoding. Since, "target bitrate" and "target filesize" values in the codec settings generally don't match, XviD can use only one of them at a time, and will ignore the other. The position of the "Target_bitrate/target_filesize" button determines which of the two is being used and which is being ignored.
So if the button is in the "target filesize" position, GK will send the target filesize value to the codec and XviD will use it for encoding. Changing this value manually when setting the second pass will have no effect, since this value is overwritten by GK after the first pass anyway.
If the button is in the "target bitrate" position, GK will still pass the target filesize setting to the codec. However, in this mode XviD never uses this value. It relies on the "target bitrate" setting, which is never passed from GK. So, it will use the value set in XviD at the moment, which may be some codec default, or something left from the previous job, or something set manually, etc. In any case, the resulted bitrate and, consequently, the filesize will be completely unrelated to the values prescribed by GK. Moreover, GK does not know that in this situation its settings are being ignored and will still write in the log that the video is encoded at the bitrate it calculated. So, the log will be wrong.

I think the safest thing at the moment is to make sure that the button is ALWAYS in the "target filesize" position, when using GK for encoding. This way the GK settings will always take precedence. To make it fool-proof, though, it might be a good idea for GK to send both the filesize and the bitrate values to XviD after the first pass.

len0x
26th February 2005, 22:12
Actually, you are still wrong when saying that GK passes bitrate to the XviD settings (it never does that - only target size is used, no matter what logs are saying).

I'm only partially wrong about "target size/bitrate selection has no influence on the codec settings". I mean that settings to the codec are passed irrespectively of which mode is selected. But one thing is different: try to switch between modes quickly back and forth and you'll see that bitrate stays the same but target size does not! I had this reported once but couldn't get to the bottom of that because calculator inside GK is very messy and non-trivial to understand. So I would say that calculations might be off slightly when target bitrate mode is used (but all this happens before codec settings are involved).

Kheffer
27th February 2005, 18:57
Originally posted by len0x
Actually, you are still wrong when saying that GK passes bitrate to the XviD settings (it never does that - only target size is used, no matter what logs are saying).

I'm only partially wrong about "target size/bitrate selection has no influence on the codec settings". I mean that settings to the codec are passed irrespectively of which mode is selected. But one thing is different: try to switch between modes quickly back and forth and you'll see that bitrate stays the same but target size does not!

That's exactly what I'm saying -- GK passes only the size, but never the bitrate -- and this is the source of the problem!
And indeed the bitrate stays the same but the size does not - this is how I've found the problem. GK passes the settings to the codec irrespectively of which mode is selected - it always passes the target size. However, the codec DOES use the settings depending on the mode selected. If the bitrate mode is selected it uses the bitrate setting, which is never passed from GK, and ignores the size setting, which is passed from GK, thus the result is all wrong.

len0x
27th February 2005, 19:49
Originally posted by Kheffer
That's exactly what I'm saying -- GK passes only the size, but never the bitrate -- and this is the source of the problem!

Not its not. When I coded XviD support for GK - I never was planning to use bitrate. So you can't say its a problem if it wasn't intended to be used :) (btw as far as I can see current XviD 1.1 doesn't have bitrate settings at all, only target size). Anyway, the problem as I said is that bitrate calculator behaves strangely. Its not supposed to change target size when switching between options. Its a pure GUI/calculator problem that I was unable to trace in the past, nothing more.

Kheffer
2nd March 2005, 18:32
Originally posted by len0x
Not its not. When I coded XviD support for GK - I never was planning to use bitrate. So you can't say its a problem if it wasn't intended to be used :) (btw as far as I can see current XviD 1.1 doesn't have bitrate settings at all, only target size). Anyway, the problem as I said is that bitrate calculator behaves strangely. Its not supposed to change target size when switching between options. Its a pure GUI/calculator problem that I was unable to trace in the past, nothing more.

I did not notice a calculator problem, when switching options in GK. I was talking only about switching options in the codec. You don't have to do it intentionally though. If you are not aware of the problem and just don't pay attention to the position of the filesize/bitrate button in the codec, it is quite enough to get completely wrong results. If the button is left in the bitrate position, GK will not correct it for you, the codec will ignore the GK calculator altogether and you won't know why.
I have not seen XviD 1.1 yet. If you say that it does not have this button at all, then the problem does not exist there anymore. The whole story is relevant only for XviD 1.0.

Kheffer
2nd March 2005, 18:43
Originally posted by Kheffer

I have not seen XviD 1.1 yet. If you say that it does not have this button at all, then the problem does not exist there anymore. The whole story is relevant only for XviD 1.0.

I've just checked the Doom9 guide on XviD1.1 and it shows that the target bitrate button is still there (http://www.doom9.org/images/xvid/xvid11-encodingoptions.png) . Moreover, it's in the wrong position. It must NEVER be in this position when using GK for encoding!

len0x
2nd March 2005, 18:48
GK never adjusts that setting (bitrate), it only writes target size (that is calculated slightly wrong in target bitrate mode) assuming XviD's using it, so if you manually change that in codec settings, then you're in trouble indeed...

*Edit* I actually _never_ used XviD with target bitrate, so that's why I had hard time understanding what you're talking about :)