StainlessS
13th November 2016, 22:32
SOLVED :) Problem disappears with mvtools2 v2.7.1.22.
Hi Guys, having a bit of a problem with below code (VS2010), there dont seem to be similar problem in VS98 or VS2003 ToolKit 3.
Produces -1.IND000000000000 condition (but only on very first frame [EDIT: RT_AverageLuma will not access frame -1]).
Code producing error is during conversion of __int64 value of 255 to double.
Script
FN="LowBitrateAnime.AVI"
Avisource(FN)
Function StartOfSceneClip(clip c,Int "thSCD1",Int "thSCD2") {
c
thSCD1=Default(thSCD1,400)
thSCD2=Default(thSCD2,130)
sup=c.MSuper(pel=1,sharp=0,rfilter=2,hpad=16, vpad=16)
I_fv=sup.MAnalyse(isb=false,delta=1,blksize=16,overlap=8)
Return c.MSCDetection(I_fv,thSCD1=thSCD1,thSCD2=thSCD2)
}
SC=StartOfSceneClip
SSS="""
n=current_frame
f=SC.RT_AverageLuma(n=n,W=1,H=1) # Sample single pixel
RT_Subtitle("%d] F=%f",n,f) # Shows '0] F=-1.#IND00' on first frame
return last
"""
Scriptclip(SSS)
Code fragment
// Roughly What happens earlier in source
// __int64 acc = 0;
// unsigned int sum = 0;
// sum = sum + 255
// unsigned int Pixels=1; // EDIT: Added
// floating point error flags (eg 1.0/3.0 gives _EM_INEXACT)
unsigned int e = (_clearfp());
if(e) {
dprintf("RT_AverageLuma2: ***ERROR*** E=%X\n",e);
}
acc += sum; // acc = 255
double dacc = double(acc); // -1.#IND000000000000 ... SHOCK HORROR
double result = dacc / Pixels;
// e = (_clearfp() & ~_EM_INEXACT);
e = (_clearfp());
if(e) {
dprintf("RT_AverageLuma3: ***ERROR*** E=$%X dacc=%f($%I64X) Pixels=%d",e,dacc,acc,Pixels);
}
return result;
}
Debugview Output, prints 2nd Error only (ie RT_AverageLuma3: error [EDIT: Below E=$10 is _EM_INEXACT])
00000006 1.73375964 RT_AverageLuma3: ***ERROR*** E=$10 dacc=-1.#IND00($FF) Pixels=1
Disassembly
// floating point error flags (eg 1.0/3.0 gives _EM_INEXACT)
// unsigned int e = (_clearfp() & ~_EM_INEXACT);
unsigned int e = (_clearfp());
04DEBFBA call @ILT+1620(__clearfp) (4DE3659h)
04DEBFBF mov dword ptr [e],eax
if(e) {
04DEBFC5 cmp dword ptr [e],0
04DEBFCC je $LN7+183h (4DEBFE2h)
dprintf("RT_AverageLuma2: ***ERROR*** E=%X\n",e);
04DEBFCE mov eax,dword ptr [e]
04DEBFD4 push eax
04DEBFD5 push offset string "RT_AverageLuma2: ***ERROR*** E=%"... (4ECF1ACh)
04DEBFDA call dprintf (4DE31DBh)
04DEBFDF add esp,8
}
acc += sum;
04DEBFE2 mov eax,dword ptr [sum]
04DEBFE5 xor ecx,ecx
04DEBFE7 add eax,dword ptr [acc]
04DEBFEA adc ecx,dword ptr [ebp-38h]
04DEBFED mov dword ptr [acc],eax
04DEBFF0 mov dword ptr [ebp-38h],ecx
double dacc = double(acc);
04DEBFF3 fild qword ptr [acc]
04DEBFF6 fstp qword ptr [dacc]
double result = dacc / Pixels;
04DEBFFC mov eax,dword ptr [Pixels]
04DEBFFF mov dword ptr [ebp-1A0h],eax
04DEC005 mov dword ptr [ebp-19Ch],0
04DEC00F fild qword ptr [ebp-1A0h]
04DEC015 fdivr qword ptr [dacc]
04DEC01B fstp qword ptr [result]
// e = (_clearfp() & ~_EM_INEXACT);
e = (_clearfp());
04DEC021 call @ILT+1620(__clearfp) (4DE3659h)
04DEC026 mov dword ptr [e],eax
if(e) {
04DEC02C cmp dword ptr [e],0
04DEC033 je $LN7+202h (4DEC061h)
dprintf("RT_AverageLuma3: ***ERROR*** E=%X dacc=%f($%I64X) Pixels=%d",e,dacc,acc,Pixels);
04DEC035 mov eax,dword ptr [Pixels]
04DEC038 push eax
04DEC039 mov ecx,dword ptr [ebp-38h]
04DEC03C push ecx
04DEC03D mov edx,dword ptr [acc]
04DEC040 push edx
04DEC041 sub esp,8
04DEC044 fld qword ptr [dacc]
04DEC04A fstp qword ptr [esp]
04DEC04D mov eax,dword ptr [e]
04DEC053 push eax
04DEC054 push offset string "RT_AverageLuma3: ***ERROR*** E=%"... (4ECF164h)
04DEC059 call dprintf (4DE31DBh)
04DEC05E add esp,1Ch
}
return result;
04DEC061 fld qword ptr [result]
}
Is it possible that the problem resides earlier in code ? if so how can one detect it ?
Perhaps MvTools2 (v2.5.11.20) problem in trying to access first frame-1 ie frame -1, and somehow propagated into my function ?
Any clues anybody ?
Hi Guys, having a bit of a problem with below code (VS2010), there dont seem to be similar problem in VS98 or VS2003 ToolKit 3.
Produces -1.IND000000000000 condition (but only on very first frame [EDIT: RT_AverageLuma will not access frame -1]).
Code producing error is during conversion of __int64 value of 255 to double.
Script
FN="LowBitrateAnime.AVI"
Avisource(FN)
Function StartOfSceneClip(clip c,Int "thSCD1",Int "thSCD2") {
c
thSCD1=Default(thSCD1,400)
thSCD2=Default(thSCD2,130)
sup=c.MSuper(pel=1,sharp=0,rfilter=2,hpad=16, vpad=16)
I_fv=sup.MAnalyse(isb=false,delta=1,blksize=16,overlap=8)
Return c.MSCDetection(I_fv,thSCD1=thSCD1,thSCD2=thSCD2)
}
SC=StartOfSceneClip
SSS="""
n=current_frame
f=SC.RT_AverageLuma(n=n,W=1,H=1) # Sample single pixel
RT_Subtitle("%d] F=%f",n,f) # Shows '0] F=-1.#IND00' on first frame
return last
"""
Scriptclip(SSS)
Code fragment
// Roughly What happens earlier in source
// __int64 acc = 0;
// unsigned int sum = 0;
// sum = sum + 255
// unsigned int Pixels=1; // EDIT: Added
// floating point error flags (eg 1.0/3.0 gives _EM_INEXACT)
unsigned int e = (_clearfp());
if(e) {
dprintf("RT_AverageLuma2: ***ERROR*** E=%X\n",e);
}
acc += sum; // acc = 255
double dacc = double(acc); // -1.#IND000000000000 ... SHOCK HORROR
double result = dacc / Pixels;
// e = (_clearfp() & ~_EM_INEXACT);
e = (_clearfp());
if(e) {
dprintf("RT_AverageLuma3: ***ERROR*** E=$%X dacc=%f($%I64X) Pixels=%d",e,dacc,acc,Pixels);
}
return result;
}
Debugview Output, prints 2nd Error only (ie RT_AverageLuma3: error [EDIT: Below E=$10 is _EM_INEXACT])
00000006 1.73375964 RT_AverageLuma3: ***ERROR*** E=$10 dacc=-1.#IND00($FF) Pixels=1
Disassembly
// floating point error flags (eg 1.0/3.0 gives _EM_INEXACT)
// unsigned int e = (_clearfp() & ~_EM_INEXACT);
unsigned int e = (_clearfp());
04DEBFBA call @ILT+1620(__clearfp) (4DE3659h)
04DEBFBF mov dword ptr [e],eax
if(e) {
04DEBFC5 cmp dword ptr [e],0
04DEBFCC je $LN7+183h (4DEBFE2h)
dprintf("RT_AverageLuma2: ***ERROR*** E=%X\n",e);
04DEBFCE mov eax,dword ptr [e]
04DEBFD4 push eax
04DEBFD5 push offset string "RT_AverageLuma2: ***ERROR*** E=%"... (4ECF1ACh)
04DEBFDA call dprintf (4DE31DBh)
04DEBFDF add esp,8
}
acc += sum;
04DEBFE2 mov eax,dword ptr [sum]
04DEBFE5 xor ecx,ecx
04DEBFE7 add eax,dword ptr [acc]
04DEBFEA adc ecx,dword ptr [ebp-38h]
04DEBFED mov dword ptr [acc],eax
04DEBFF0 mov dword ptr [ebp-38h],ecx
double dacc = double(acc);
04DEBFF3 fild qword ptr [acc]
04DEBFF6 fstp qword ptr [dacc]
double result = dacc / Pixels;
04DEBFFC mov eax,dword ptr [Pixels]
04DEBFFF mov dword ptr [ebp-1A0h],eax
04DEC005 mov dword ptr [ebp-19Ch],0
04DEC00F fild qword ptr [ebp-1A0h]
04DEC015 fdivr qword ptr [dacc]
04DEC01B fstp qword ptr [result]
// e = (_clearfp() & ~_EM_INEXACT);
e = (_clearfp());
04DEC021 call @ILT+1620(__clearfp) (4DE3659h)
04DEC026 mov dword ptr [e],eax
if(e) {
04DEC02C cmp dword ptr [e],0
04DEC033 je $LN7+202h (4DEC061h)
dprintf("RT_AverageLuma3: ***ERROR*** E=%X dacc=%f($%I64X) Pixels=%d",e,dacc,acc,Pixels);
04DEC035 mov eax,dword ptr [Pixels]
04DEC038 push eax
04DEC039 mov ecx,dword ptr [ebp-38h]
04DEC03C push ecx
04DEC03D mov edx,dword ptr [acc]
04DEC040 push edx
04DEC041 sub esp,8
04DEC044 fld qword ptr [dacc]
04DEC04A fstp qword ptr [esp]
04DEC04D mov eax,dword ptr [e]
04DEC053 push eax
04DEC054 push offset string "RT_AverageLuma3: ***ERROR*** E=%"... (4ECF164h)
04DEC059 call dprintf (4DE31DBh)
04DEC05E add esp,1Ch
}
return result;
04DEC061 fld qword ptr [result]
}
Is it possible that the problem resides earlier in code ? if so how can one detect it ?
Perhaps MvTools2 (v2.5.11.20) problem in trying to access first frame-1 ie frame -1, and somehow propagated into my function ?
Any clues anybody ?