PDA

View Full Version : kfthreshold/kfreduction


plugh
11th November 2006, 21:30
Searched the net, this forum, and the sources...

Using xvidvfw 1.1.0 - do these parameters do anything?

Can find them initialized, acquired from gui, and set into params structure, but not actually used anywhere.

plugh
16th November 2006, 16:57
Well, it appears

kfthreshold = "I-frames closer then ... (frames)"
kfreduction = "...are reduced by %"

settings don't actually do anything

foxyshadis
17th November 2006, 10:39
That's because key frames are only extremely rarely 1 or 2 frames apart, especially since min keyinterval normally prevents that. It basically means that if you start getting extremely fast flashing of totally different frames that have to be I-frames, it'll degrade them, since it doesn't do later frames any good.

As a test to synthesize that sort of thing, you could start with a 200 frame video, and then at frame 100 interleave 10 frames each from 10 other movies into it. Most of them will have to be I-frames in that case, and the quant distribution will be different if kfreduction is set.

plugh
17th November 2006, 14:48
No, it is because the parameters aren't used in the code.
Using the 1.1.2 source kit (edited extracts)-

xvidvfw.dll - config.c
static const REG_INT reg_ints[] = {
{"kfreduction", &reg.kfreduction, 20},
{"kfthreshold", &reg.kfthreshold, 1},

...
/* upload config data into dialog */
static void adv_upload(HWND hDlg, int idd, CONFIG * config)
case IDD_RC_2PASS2 :
SetDlgItemInt(hDlg, IDC_KFREDUCTION, config->kfreduction, FALSE);
SetDlgItemInt(hDlg, IDC_MINKEY, config->kfthreshold, FALSE);
...
/* download config data from dialog */
static void adv_download(HWND hDlg, int idd, CONFIG * config)
case IDD_RC_2PASS2 :
config->kfreduction = GetDlgItemInt(hDlg, IDC_KFREDUCTION, NULL, FALSE);
config->kfthreshold = config_get_uint(hDlg, IDC_MINKEY, config->kfthreshold);
xvidvfw.dll - codec.c
LRESULT compress_begin(CODEC * codec, BITMAPINFO * lpbiInput, BITMAPINFO * lpbiOutput)
case RC_MODE_2PASS2 :
pass2.kfreduction = codec->config.kfreduction;
pass2.kfthreshold = codec->config.kfthreshold;
...
plugins[create.num_plugins].func = codec->xvid_plugin_2pass2_func;
plugins[create.num_plugins].param = &pass2;

so far so good - initialized, gui set and gui get, passed to core
let's look at the core
xvidcore.dll - plugin_2pass2.c
/*****************************************************************************
* Some default settings
****************************************************************************/
/* Keyframe settings */
#define DEFAULT_KFREDUCTION 20
#define DEFAULT_KFTHRESHOLD 1
...
rc_2pass2_create(xvid_plg_create_t * create, rc_2pass2_t **handle)
rc->param.kfreduction = param->kfreduction;
rc->param.kfthreshold = param->kfthreshold;
#define _INIT(a, b) if((a) <= 0) (a) = (b)
/* Keyframe settings */
_INIT(rc->param.kfreduction, DEFAULT_KFREDUCTION);
_INIT(rc->param.kfthreshold, DEFAULT_KFTHRESHOLD);
...
rc_2pass2_before(rc_2pass2_t * rc, xvid_plg_data_t * data)
#if 0 /* ToDo: decide how to apply kfthresholding */
#endif

As Porky Pig says, "bada bada bada That's all folks!"
That's it. No further use/reference to those variables anywhere in the code.
They aren't USED - changing them doesn't modify code behaviour.
Set them to anything you want in the gui, you'll always get the same result.

foxyshadis
17th November 2006, 15:42
Oh, that's right, I think I remember some work being done and then removed some time back. Sorry, I forgot your earlier comment. ^^;

plugh
17th November 2006, 16:04
I did find some mailing list stuff from 2003 about it,
and "changelog-1.0" has the following entry:
2003-12-05 14:06:19 GMT patch-120

Summary:
KFthresholding changes.
Revision:
xvidcore--devapi4--1.0--patch-120

As user reports proved, the logic behind the min_key_interval was
1/ misleading because the parameter is kfthreshold indeed and not
a minimum keyframe interval
2/ the formula was a bit too aggressive (removing 20% of bitrate
per frame until distance to next iframe was 1)

I posted a RFC to try to settle a decision on what behavior this
setting should have. We have still have no clear answer so i prefer
just fixing the misleading name right now and wait for a common
position about its behavior later.

Libraries are *binary* compatible, but *source code* compatibility
is broken (rename rc_2pass2_t->min_key_interval to kfthreshold).
This is probably the last API change.

NB: fixes a type problem during scaling parameter computing which
was causing insane pb_iboost_tax_ratio values.

modified files:
src/plugins/plugin_2pass2.c src/xvid.h vfw/src/codec.c
vfw/src/config.c vfw/src/config.h
however, I can find nothing later in the changelogs, on the net, mailing lists, etc, about removing whatever code may have been present at one time

Didée
17th November 2006, 21:45
It's been some time already - 1 year, 2 years, dunno - that I repeated noting that Iframe reduction doesn't do anything.

Good to see someone else noted this - almost got the feeling I was living in an alternate reality or something. ;)