Log in

View Full Version : Scriptclip problems (plus AverageLuma & TemporalSoften)


marcellus
29th April 2004, 23:58
Hi everybody!

Trying to do some adaptive filtering, at some point I ran into some strange problems. I cracked my head a lot over this and I don't know if it's my fault (I admit I am a newbie). I'm using latest Avisynth alpha binary (20 March) and latest available filters (masktools 1.4.16). But I tested also with no success on the latest Avisynth's stable release.

Problem 1:
I managed to isolate the problem as being related to ScriptClip filter and (but I'm not sure it's limited to) AverageLuma function. Although the following script is not part of my filtering (it is useless as it is) I'm using it to demonstrate the problem:


#Source: TV capture Mpeg2, 352x288 PAL, captured with
#the TV card's Intervideo WinDVR, then processed with dvd2avi
LoadPlugin ("C:\Program Files\AviSynth 2.5\pluginz\MPEG2Dec3dg.dll")
original = Mpeg2Source ("E:\Captura\Naz 01\encoding\naz01.d2v")
spatial = ScriptClip (original , "blur (1.58 * float (255 - AverageLuma (original))/255)")
left_good = original . Crop (0 , 0 , 176 , 288)
right_bad = spatial . Crop (176, 0, 176 , 288)
glued = StackHorizontal (left_good , right_bad)
Return glued

Now, the problem: I get randomly, now and then, brighter and "pinky-er" frames (actually one in 1-2 minutes, or so, it depends on source). As you can see the problematic branch of the script is "spatial" clip. I cropped it and stacked it side by side with the original for demonstration purposes. Beside the blurring (as expected) this is what I get (see 3 consecutive frames, the one in the middle shows the problem):

http://www.marcellusvcd.netfirms.com/scriptclipissue.html

My actual adaptive script looks like this:


SetMemoryMax(64)
#___Load plugins
loadplugin ("C:\Program Files\AviSynth 2.5\pluginz\MPEG2Dec3dg.dll")
loadplugin ("C:\Program Files\AviSynth 2.5\pluginz\mpasource.dll")
LoadPlugin ("C:\Program Files\AviSynth 2.5\pluginz\masktools.dll")
LoadPlugin ("C:\Program Files\AviSynth 2.5\pluginz\unfilter.dll")
#___Sources
v1 = mpeg2source ("E:\Captura\Naz 01\encoding\naz01.d2v")
a1 = mpasource ("E:\Captura\Naz 01\encoding\naz01 MPA T01 DELAY 68ms.mpa" , normalize = true) \
. Bufferaudio () . ssrc (44100 , fast = false) . delayaudio (0.068)
#
d1 = audiodub (v1 , a1)
#
v2 = mpeg2source ("E:\Captura\Naz 01\encoding\naz02.d2v")
a2 = mpasource ("E:\Captura\Naz 01\encoding\naz02 MPA T01 DELAY 68ms.mpa" , normalize = true) \
. Bufferaudio () . ssrc (44100 , fast = false) . delayaudio(0.068)
#
d2 = audiodub (v2 , a2)
#___Splice1
spliced_1 = alignedsplice (d1 , d2)
#___Trim
t1 = spliced_1 . trim (186 , 136596)
t2 = spliced_1 . trim (157217 , 289789)
#___Splice2
spliced_2 = alignedsplice (t1 , t2) . crop (16 , 16 , 320 , 256)
#___Process
movementmask = MotionMask (spliced_2 , thY1 = 1 , thY2 = 4 , thSD = 255 , y = 3 , u = -128 , v = -128) \
. inflate (y = 3 , u = -128 , v = -128) . temporalsoften (2 , 255 , 255 , 255 , 2) \
. blur (1.58) . fity2uv ("bicubic")
#
spatial = spliced_2 . scriptclip ("blur (1 * averageluma (movementmask) / 255)")
#
temporal = spliced_2 . TemporalSoften (2 , 8 , 16 , 10 , 2)
#
merged = temporal . MaskedMerge (spatial , movementmask , y = 3 , u = 3 , v = 3) \
. scriptclip ("blur (0.2 * averageluma (movementmask) / 255)")
#
#____Final
final = merged . addborders (16 , 16 , 16 , 16) . limiter()
return final

With the script above i get the same problem.
Interesting thing, if I change the spatial filtering from blur to unfilter instead pink-ish frames I get flickering (quick luma variation) now and then (and not in the same places):

#spatial = spliced_2 . scriptclip ("blur (averageluma (movementmask) / 255)")
spatial = spliced_2 . scriptclip ("unfilter (int(-100 * averageluma (movementmask) / 255) \
, int (-100 * averageluma (movementmask) / 255))")

Problem 2:

In the script above only spatial filtering is adaptive. If I put scriptclip also on temporal filtering line rendering speed drops almost to 0 fps. Even if a don't put any variable parameters to TemporalSoften the effect is the same (almost 0 fps):

#temporal = spliced_2 . TemporalSoften (2 , 8 , 16 , 10 , 2)
temporal = spliced_2 \
. scriptclip ("TemporalSoften (2 , int (8 * averageluma (movementmask) / 255) , 16 , 10 , 2)")
#or:
temporal = spliced_2 . scriptclip ("TemporalSoften (2 , 8 , 16 , 10 , 2)")


What is wrong?

best regards
marcellus

marcellus
11th May 2004, 23:21
Hi!
It seems to me more and more that the problem above is an avisynth bug (unless I misunderstand the usage of scriptclip and averageluma).

It would be apropriate to post something about it in the Development section? Because this issue is very annoying and I'm pretty sure isn't source related. I need an advise, I don't want to crosspost. :confused:

bye
marcellus