PDA

View Full Version : noise adaptive smart bob/standards converter script (very experimental)


Mug Funky
1st August 2005, 09:04
hi all. for a while i've been trying to emulate a hardware standards-converter in avisynth. kernelbob and convertfps work to a certain extent, but i could never get very accurate static area detection out of kernelbob (or anything else, really). the converter i use has an auto motion threshold that is difficult to figure out.

well, here's an attempt at doing just that. at default settings, it'll output a smart-bobbed stream and change nothing. you can enter an output fps, and an output height, as well as tweaking the noise thresholds.

function ixion (clip c, float "fps",int "height", int "nth", int "dth",bool "interlaced")
{

fps=default(fps,c.framerate())
out_height=default(height,c.height())
nth=default(nth,8)
dth=default(dth,4)
interlaced=default(interlaced,false)

map=c.horizontalreduceby2().coloryuv(cont_y=-32).temporalsoften(1,nth,0,nth+1,2).leakkerneldeint(order=1,map=true,threshold=dth,twoway=true).binarize(234,false).expand().converttoyuy2().bilinearresize(c.width,c.height)

lowrate_even=overlay(c,c.leakkerneldeint(order=1,threshold=dth,twoway=true),mask=map).converttoyuy2().bicubicresize(c.width,out_height,0,.5).convertfps(fps*2).selecteven()
lowrate_odd=overlay(c,c.leakkerneldeint(order=0,threshold=dth,twoway=true),mask=map).converttoyuy2().bicubicresize(c.width,out_height,0,.5).convertfps(fps*2).selectodd()
lowrate=interleave(lowrate_even,lowrate_odd)

highrate=c.leakkernelbob(order=1,threshold=dth,sharp=true,twoway=true).converttoyuy2().bicubicresize(c.width,out_height,0,.5)

overlay(lowrate,highrate.convertfps(fps*2),mask=map.bicubicresize(c.width,out_height,0,.5).convertfps(fps*2))

assumebff()
interlaced==true? last.separatefields().selectevery(4,1,2).weave() : last
}

nth = noise threshold. this thing ignores noise by running a hard temporal smooth on the luma, and this threshold says just how hard it is. the default value is for a (noisy) analog broadcast i used for testing, but for REALLY noisy sources it'll need to be raised to avoid lots of shimmer. for a smooth source (CG anime?) you can drop this value to 0 and get a speed gain, but then it'll just be like using kernelbob without noise detection.

dth = the regular kernelbob thresold. probably should be left as it is to avoid shimmer, but can be lowered on clean sources (again, no point using this at all on really clean stuff).

interlaced = true/false. if true it weaves the 2 bobbed frames together. useful for standards conversion, ie "ixion(fps=30/1.001,height=480,interlaced=true)" will go PAL to NTSC. if false, you'll get bobbed output at twice the "fps" value entered.


this is not at all speed-optimised (i want to masktool the hell out of it eventually, but i wanted to prove the concept first), and it only works with top-field first sources. in my opinion bottom-first should be ditched, and a standard of top-first always should be adopted, as people just get it wrong way too often and it makes things harder for everyone. there's a bunch of ways to reverse field-dominance out there, or some kind soul could modify this script to handle both...

enjoy!

[edit]

btw, you'll need leakkerneldeint to run this...

mg262
2nd August 2005, 22:03
I've just tried it out quickly, and it seems to work great! (I haven't actually tried standards conversion very often, so I'm afraid I don't have anything more intelligent to say... but no glitches that I can see and its surprisingly fast.)

Silly question: why the conversion to YUY2?

Mug Funky
3rd August 2005, 13:46
because convertfps hasn't been touched since avisynth 2.0x... it still only works in yuy2 (though i'd LOVE it to work in yv12, as i use this function all the time).

hehe.. this script is only really useful on sources that are so noisy that a regular field-differencing approach will lead to everything being deinterlaced all the time, or hardly anything being deinterlaced and combed output. agressively killing the noise then detecting combs works pretty well to tune the comb detection on combing only (plus it expands the mask out a bit temporally, which can help avoid "dancing pixels" in the bobbed output).

also, converting the static parts and the moving parts separately seems like a waste of time now, but it could potentially be interesting for denoising - the progressive parts can be denoised more effectively as they're working on twice the time-scale. the trick is to get useful denoising in without artefacting (tricky - it'll give artefacts if you add it to the function as it is now, which is why there's no optional denoising in this version).

basically i wrote this because i'd just got analog capture working properly on my new compy and decided to run a bad station into it to see what happens :)

mg262
3rd August 2005, 14:24
because convertfps hasn't been touched since avisynth 2.0x... it still only works in yuy2 (though i'd LOVE it to work in yv12, as i use this function all the time).There is a YV12 function to increase FPS (with a minimum weight threshold for blending) inside RestoreFPS:

http://forum.doom9.org/showthread.php?p=652115#post652115

Actually, there is also an internal function that will let you increase or decrease FPS; it literally just needs to be given a name to be accessible from scripts ... I will sort it out soon (probably assimilate it into ReverseBlend). Adding new forward blend patterns is very easy in that framework -- adding a new blend typically takes less space than your script above. So if you want anything, just provide a clear description of it.

Backwoods
8th August 2005, 03:44
I tried this for some 60i to 24p files and it works nice, minus scene changes. There are a couple frames blending during the scene change which makes almost a cross dissolve.

Mug Funky
9th August 2005, 07:53
oh, this'll totally blend fields. it's not meant for IVTC...

also i noticed some artefacting on certain kinds of movement (subtle tones and high motion-blur, like somebody's hand gesturing in a softly lit room for example).

that's why i said this was experimental :). it's more to try out a noise-tolerant comb threshold to maybe give developers some ideas as to how to make a deinterlacer/IVTC more robust against noisy sources. i figure now people can burn DVDs instead of CDs, we get the luxury of keeping the noise and interlacing in if we want to.

Backwoods
9th August 2005, 09:34
Yea I wasn't expecting perfect 60i to 24p, just messing around. Motion wise it looked good, just too much noticable blending. I didn't notice any artifacts during my tests though.

If you develop this further, please shoot the thread an update.

Mug Funky
9th August 2005, 10:08
hehe... i think i'll do more with it if:

- i have a "eureka" moment and figure out how to make better comb detection. this is the most likely i reckon.
- i learn C or C++ and ASM and make a plugin that does it faster and better.

i'd prefer the second, but i've only got like 1 spare day per week, and i spend most of that buying gadgets and chilling out (i got an 8x6 wacom tablet yesterday) :)