Log in

View Full Version : MoComped deinterlace... don't know why i didn't think of this approach before.


Pages : 1 2 3 [4]

scharfis_brain
28th August 2005, 19:51
pre-denoise is only used for a initial bob-deinterlace to make the motion mask more stable. It will NOT reach the output. It is only used for motion-vector search.
Undot ist used to remove some orphan pixels that occur during the EDI (Edge directed interpolation).

WorBry
28th August 2005, 20:08
Thanks alot for your speedy and helpful reply

ariga
24th November 2005, 12:09
To get half the frame rate out of mvbob in one of the posts it is suggested to use selecteven and another post later suggests selectodd. Does it make a difference ? Also for PAL DV, is anything else needed before/after mvbob() ?
Thanks.

akoten
31st January 2006, 23:57
I'm using the following script on a 20min PAL-DV movie:

Import("C:\Programme\AviSynth 2.5\plugins\mvbob.avs")
AVISource("dv.avi")
(Trim(373,25697)++Trim(26237,33349)).FadeIO(50)
MVbob(quick=false)
Lanczos4Resize(768,576,0,2,720,574)
overlay(SelectEven(),SelectOdd(),opacity=0.5,output="yuy2")

The vfw-decoder for DV comes from ffdshow. I load the script in VdubMod1.5.10.2 and select "fast recompress" and "encode to VP70" (or MJPEG via ffdshow, that doesn't matter). After some while Vdub crashes without any message.

Somewhere I read that mvtools had a memory leak problem. So I updated it to version 1.0.3. But no difference.

Somewhere I read that I should have at least 1GB of RAM. Well I only have 128MB (on WinXP-SP2). Please, could somebody confirm that this is definitively too less?

Another topic at the end: I know that with the last line (overlay) the resulting overall process is quite similar to a simple blended deinterlace but IMO the movie looks much better (although the conversion speed is very close to "untolerable" :sly: ). What deinterlacing method is best if my hardware can't play 50fps in realtime?

regards
AKo

foxyshadis
1st February 2006, 00:19
Something that might help, try installing Tritical's 2.5.7-pre Avisynth (http://bengal.missouri.edu/~kes25c/Avisynth_311205.exe), which should at least pop up an error when it crashes.

Also ensure that you have the latest mvbob (http://forum.doom9.org/showthread.php?p=757259&highlight=mvbob#post757259), which uses the latest mvtools.

128 megs on XP, doing video processing? Ouch... Hope you have nothing else open, and setmemorymax(48) or so. With a heavy script I can use up to 400-500 megs during processing, just for avisynth, and mvbob counts as heavy. It may well be the source of the problem, though it seems more likely the system would just swap like mad. Maybe you need more swap file.

At the end, if you're asking about deinterlace during playback, leakkerneldeint is very fast and should work even on older systems. If you mean deinterlace during script, well, mvbob is where it's at.

akoten
1st February 2006, 10:11
@foxishadis:

Latest mvbob does NOT include latest mvtools. Although there is no version description somewhere in the mvtools.dll I suppose it is something around 0.9.8.x. Latest stable version is 1.0.3, or even newer is version 1.1 alpha.

Did I really write 128Megs? I meant 256MB. With swap file 768MB altogether. Anyway, I can see that there is really quite a bit of action on my swap file. But should this really lead to a crash without even an "out of virtual memory" message? What is "setmemorymax(48)"? Where to configure?

However, I'll try the Avisynth-version you suggested and let you know. Currently I just have 2.5.6 running.

Something interesting maybe is that with latest official Vdub (1.6.11) I get MUCH more frames processed than with VdubMod. And another thing is that with 1.6.11 the processing speed is around 0.5fps and with VdubMod it is around 1.5fps.

Why I was asking for the best deinterlacing method (during script only, of course!) is that my "overlay()" method produces "transparent" objects (opacity=0.5!) where they are moving. What I would like is that moving objects have the same brightness as if they were static. I have no idea how to achieve that, but maybe somebody made up his mind about this kind of question.

foxyshadis
1st February 2006, 12:25
What you're doing is just a cheap hack, what you really want is motion blur (http://forum.doom9.org/showthread.php?p=615027#post615027). Here's a version that uses the newer mvflowfps. Slooooow though.


function mvfpssimple(clip i, float fps, float "shutter")
{
shutter=default(shutter,50.0)
fwd=MVAnalyse(isb = false, blksize=blk, truemotion=tm, pel=2, idx=4)
bwd=MVAnalyse(isb = true, blksize=blk, truemotion=tm, pel=2, idx=4)
MVFlowBlur(bwd,fwd,blur=shutter)
}

MVFlowBlur encapsulates the idea of mvfps in one function. Increase shutter to decrease the amount of blurring. Prepare for amazingly slow render times.

In other news, setmemorymax(x) is a directive you place at the top of scripts to limit mem use. I'm not sure what the default is (should be low), but you might need to either lower or raise it.

You're right, by the date on the mvbob mvtools.dll, it's v1.0. I just wanted to make sure you had the latest script, though.

Xesdeeni
1st February 2006, 15:55
I load the script in VdubMod1.5.10.2 and select "fast recompress" and "encode to VP70" (or MJPEG via ffdshow, that doesn't matter). After some while Vdub crashes without any message.Maybe it's just me, but I've found VirtualDubMod to be very unstable. Heck, just choosing File|File Information... causes it to crash. The only reason I use VDM is if I want to add an AC3 stream and edit it. I have to save often to avoid having to start over. They say VDM will handle YV12, but I can't get it to do so. And it's MPEG-2 decoder doesn't pay attention to the flags, so it's useless for that. I usually stick with the original VirtualDub.

Xesdeeni

scharfis_brain
1st February 2006, 23:06
256 MB is FAR to less for mvbob!
even with my 768 MB I am getting into trouble very often!

also avoid the blending used.

mvfpssimple() can simulate slower shutters for you but at another cost of speed and RAM.

Get at least 1 GB of RAM to get mvbob() and mvfpssimple() running stable!

akoten
5th February 2006, 23:01
function mvfpssimple(clip i, float fps, float "shutter")
{
shutter=default(shutter,50.0)
fwd=MVAnalyse(isb = false, blksize=blk, truemotion=tm, pel=2, idx=4)
bwd=MVAnalyse(isb = true, blksize=blk, truemotion=tm, pel=2, idx=4)
MVFlowBlur(bwd,fwd,blur=shutter)
}



This function does not work, until some adjustments are made. Obviously you just wanted to give me a hint how to do the final programming myself, right? Anyway, I was not able to manage a down-conversion from 50fps (mvbob) to 25fps with MVFlowBlur.

To repeat my wish: I want the result to be 25fps, the moving objects should be as clearly visible as possible, and they should be as close to the original objects regarding transparency as possible. What exactly do you think is bad about my idea with "overlap()" except that here transparency is always 50%?

In my opinion blurring is not a good idea, because it would remove second level motion in moving objects (like e.g. the rotation in a flying ball).



256 MB is FAR to less for mvbob!
even with my 768 MB I am getting into trouble very often!


I just bought 1GB of RAM and :thanks: it crashed quite a bit later. After also rising virtual RAM to have 2.5GB overall, it worked for my 21min clip. The result should have been a DV (via ffdshow encoder) but it looked kind of destroyed. So I reran with encoder=MJPEG and again it crashed. Unloading the script, loading it again and then converting finally WORKED! So I'm quite sure that there still is some kind of memory leakage somewhere in mvbob or it's subfunctions.



Maybe it's just me, but I've found VirtualDubMod to be very unstable.


You're quite right! I only use VDM for simple MPEG2's (coming out of PVAstrumento) and for AVISynth scripts. At least AVIsynth-script support is a thing VD really should support, don't you think? However I found that the crashes I mentioned in my post do not have anything to do with VDM.


AKo

Xesdeeni
6th February 2006, 22:21
At least AVIsynth-script support is a thing VD really should support, don't you think?You can't get VirtualDub to work with AVISynth scripts? It works fine for me. I've had no problem on 5 computers across 8 different o/s installations (Windows ME, Windows 2000, Windows XP SP1 & SP2). I've been using VirtualDub to test my scripts before feeding them to anything else since before version 1.4. The only time I used VirtualDubMod was when I wanted to edit an AC3 audio stream without decoding and re-encoding it.

Xesdeeni

akoten
7th February 2006, 08:49
You can't get VirtualDub to work with AVISynth scripts? It works fine for me. I've had no problem on 5 computers across 8 different o/s installations (Windows ME, Windows 2000, Windows XP SP1 & SP2). I've been using VirtualDub to test my scripts before feeding them to anything else since before version 1.4. The only time I used VirtualDubMod was when I wanted to edit an AC3 audio stream without decoding and re-encoding it.

Xesdeeni

I mean support for EDITING AVIsynth scripts

AKo

foxyshadis
7th February 2006, 16:05
VDubMod had it, Avery never felt like keeping it and fleshing it out. Ask him or fcchandler (vdub-mpeg2) what their plans in the area are.

zlab
26th February 2006, 19:44
Hi,
I hvave difficulty to run mvbob() inside the mvbob.rar package,
it always return error: "Scipt error: there is no function named: corrector"
anyone kind enough to give me a hand?
I also found a script mvbob1 seen work as good as mvbob as follows:

function MVbob1(clip c,int "blksize", int "pel", int "lambda")
{
order=(c.getparity==true)? 1:0

blksize=default(blksize,8)
scd=(blksize==8)? 300 : round(300/4)
pel=default(pel,1)
lambda=(blksize==8)? default(lambda,2000) : default(lambda,1000)

bobd=c.Leakkernelbob(order=order).verticalreduceby2()
fields=c.separatefields()
mvf=bobd.mvanalyse(blksize=blksize,pel=pel,isb=false)
mvb=bobd.mvanalyse(blksize=blksize,pel=pel,isb=true)

even1=c.separatefields().selecteven()
odd1a=fields.mvcompensate(mvf,mode=1,thscd1=scd).selecteven()
odd1b=fields.mvcompensate(mvb,mode=1,thscd1=scd).selecteven()
odd1=mergeluma(odd1a,odd1b,0.5).mergechroma(odd1b,0.5)

even2=c.separatefields().selectodd()
odd2a=fields.mvcompensate(mvf,mode=1,thscd1=scd).selectodd()
odd2b=fields.mvcompensate(mvb,mode=1,thscd1=scd).selectodd()
odd2=mergeluma(odd2a,odd2b,0.5).mergechroma(odd1b,0.5)

even=interleave(even1,odd1).weave()
odd=interleave(even2,odd2).weave()

interleave(even,odd)
}

what's the different?
also, someone send me a script, use whenever the edge not proper deinterlace, usage: mvbob().AAAFaster()

function AAAFaster(clip clp, bool "Scale2X")
{
Scale2X = default( Scale2X, false )
clp.Lanczos4Resize(clp.Width * 2, clp.Height * 2)
TurnLeft().SangNom().TurnRight().SangNom()
return Scale2X ? last : ReduceBy2()
}

AVIL
26th February 2006, 21:52
Hi,

The filter "corrector" is not included in the last version of mvtools. Its now a standalone plugin, available at Fizick site.

See:
http://forum.doom9.org/showthread.php?p=786515#post786515

zlab
27th February 2006, 00:34
Thanks for your kindly info.

Xesdeeni
27th February 2006, 17:06
The most impressive thing about the Olympics was the outstanding standards conversion. The video was all 50i HD converted to 60i HD for American broadcast. I saw a few artifacts, but in general, the conversion was fabulous. I suspect on SD broadcasts, the artificacts would have been invisible.

Maybe someday this mocomp technique will approach that quality on PC-powered machines.

Xesdeeni

kle500
10th April 2006, 22:59
Hello everyone.
I am trying to do a standards conversion on NTSC(i) -> PAL(i), and i wanted to give a try to MVBOB.
I downloaded the Mvbob.rar file, and used this script.

#Import ("C:\Program Files\AviSynth 2.5\plugins\mvfpsscd.avs")
import("C:\Program Files\AviSynth 2.5\plugins\mvbob\mvbob.avs")
LoadPlugin("C:\DVD UTILS\dgmpgdec146\DGDecode.dll")
Mpeg2Source("G:\test\VIDEO_TS\test.d2v",idct=0)
mvbob()
lanczos4resize(width,576)
converttoyv12()
MVfps(50)
converttoyuy2()
assumebff().separatefields().selectevery(4,0,3).weave()

but i get "THERE IS NO FUNCTION NAMED MVFPS".
I tryied Avisynth 2.54 - 2.55 - 2.56, none of them worked.
I am sorry for the noobie question, but i am completly lost here.
Can someone suggest a script on testing the Standards Conversion with Motion Compensation?

Right now i am using other deinterlacers with good results, but not good results in panning camera.
That's why i want to test this aproach.
Any help will be welcome.

Kind Regards

Mug Funky
11th April 2006, 08:01
try uncomment the first line that loads the mvfps function :)

[edit]

btw, if you want to try out a mocomp script, here's a simple one that gives good results on talking heads and such. deinterlacing isn't so important if your output is interlaced too - the artefacts aren't bad if your threshold is too low.

try leakkernelbob + clouded's "motionprotectedfps", then resize to pal and re-interlace. it's very fast, especially if you're used to mvbob + mvfps...

Backwoods
11th April 2006, 19:10
The most impressive thing about the Olympics was the outstanding standards conversion. The video was all 50i HD converted to 60i HD for American broadcast. I saw a few artifacts, but in general, the conversion was fabulous. I suspect on SD broadcasts, the artificacts would have been invisible.

Maybe someday this mocomp technique will approach that quality on PC-powered machines.

Xesdeeni

Thought so? I thought the complete opposite. It looked like a blocky mess to me.

kle500
11th April 2006, 19:45
try uncomment the first line that loads the mvfps function :)

[edit]

btw, if you want to try out a mocomp script, here's a simple one that gives good results on talking heads and such. deinterlacing isn't so important if your output is interlaced too - the artefacts aren't bad if your threshold is too low.

try leakkernelbob + clouded's "motionprotectedfps", then resize to pal and re-interlace. it's very fast, especially if you're used to mvbob + mvfps...
Realy appreciate you help.
I did uncomment the first line of the above script, but it didn't make any difference.
I am trying now this script:

Import ("C:\Program Files\AviSynth 2.5\plugins\mvfpsscd.avs")
import("C:\Program Files\AviSynth2.5\plugins\mvbob\mvbob.avs")
LoadPlugin("C:\DVD UTILS\dgmpgdec146\DGDecode.dll")
Mpeg2Source("G:\test\VIDEO_TS\test.d2v",idct=0)

leakkernelbob(order=1,threshold=2)
motionprotectedfps(50)
lanczosresize(720,576)
assumetff()
separatefields().selectevery(4,0,3).weave()

I am encoding right now.
It is a clip from XXX movie NTSC Interlaced that has a lot of outdoors movement.
I hope i will see better results than with simple kernelbob + convertfps.
Do you think that MvBob gives better results?
I wish i could make it work, so i could try it to the same clip.

scharfis_brain
11th April 2006, 20:55
at least use securedeint() instead of leakkernelbob() since securedeint() avoids severe interlacing artifacts especially with handycam footage. Also it gives you better definition due to EEDI2 interpolation.

mvbob() would be even better, but it needs a lot of time to process.

Boulder
11th April 2006, 21:02
scharfi,

could you update MVBob to use MaskTools v2 alpha?

Would it also be possible to add the option to input YUY2 data in MVBob and then output YV12? I understand that it must convert the colorspace to YV12 at some point so it would be nice if the colorspace was left to YV12 in the end to avoid having to do another YUY2->YV12 conversion.

scharfis_brain
11th April 2006, 21:30
I have plans to update it.

But not in the near future due to lacking time.

kle500
11th April 2006, 22:00
I've try the clip i mentioned before, and the panning is almost excelent using motionprotectFps, but i have some observations.

Using Leakkernelbob (order=X, threshold=1), gives me very good speed.
Using, Tdeint, i get much lower speed, but i get many many artifacts and lines (allthough i try to alter the threshold).
Using Securedeint(), i get wrong field, but sloooow speed (how can i change the order?).

These are the observations for the deinterlacers, but my main problem is that i have some tearing effects in the background.
For example, i have a small clip with some metalic curtains in the backround (i am sorry but i don't know how to call these).
You know, the metalic horizontal curtains everybody has in offices.
So, there are 3 White Ropes going vertical the curtains.
When the camera moves, these ropes get very very distorted.
What function can i call in MotionprottectFPS, to alter this?

Kind regards
George

scharfis_brain
11th April 2006, 22:06
you may try the raising the iterate parameter of motionprotectedfps().

also place an assumetff() or assumebff() before securedeint to ensure correct handling.

foxyshadis
11th April 2006, 22:52
I can update it, since MT2 conversion is simple and adding an option for boulder is quick, but I'm in no way implying this is the way it'll work in scharfi's future releases. :p I added a yv12out boolean parameter.


getparity(i) ? i.separatefields().eedi2(field = 3) : i.separatefields().eedi2(field = 2)

I believe this should be simplified to

i.separatefields().eedi2(field=-2)

In addition most of the isyv12 protections are useless, as ianb says a spurious ConvertToYV12 takes 0 time and no memory copies. (Just a pointer copy.)

Anyway, I, uh, have no interlaced material to test, so I just chopped up some cg video with one of your bob-to-interlace lines. It seemed to work the same, and was marginally faster... don't expect miracles though. (Looks very very good with cgi, btw.)

I submit the modified mvbob (http://foxyshadis.slightlydark.com/random/mvbob.avs) to your vetting. As usual, masktools2 is at its thread (http://forum.doom9.org/showthread.php?t=98985).

@kle500
Ugh, venetian blinds are going to be hard, if they're near the limit of pixel-differentiation. Many high-frequency patterns like that cause trouble for bobbers.

Boulder
12th April 2006, 06:41
Thanks :)

kle500
12th April 2006, 08:28
@scharfis_brain
Even if i raise the Iterate, there is no difference.
I tested the Mvfpsscd(50), and i see lower distortion in the above clip i mention.
But, way slower than with MotionProtectFPS(50).

Forgive me for my ignorance but, do you suggest to use Mvfpsscd in my clips?
As i mentioned before, i have NTSC interlaced videos that are all shot with camera (a lot of panning).
Any good suggestions?

zambelli
11th June 2006, 02:10
@scharfis_brain:

Hi Scharfis! I'm having some trouble getting MVbob() and SecureDeint() to work with the latest MVtools (1.3.0). Could you please take a look at http://forum.doom9.org/showthread.php?p=838637#post838637 and let me know if I'm doing something obviously wrong? Thanks!

Revgen
11th June 2006, 03:05
You need to download the corrector function separately since it's not included in recent versions of mvtools.

You can get it separately here http://avisynth.org.ru/mvtools/corrector.html

zambelli
11th June 2006, 09:16
You need to download the corrector function separately since it's not included in recent versions of mvtools.
You can get it separately here http://avisynth.org.ru/mvtools/corrector.html
Yeah, I've got it. My problem is not that MVbob() doesn't work at all - but that it produces combing artifacts even in non-moving images. See my linked post above.

boombastic
23rd October 2006, 18:42
With this script i'm getting the error:

ther's no mvfps function.Why?Thanks!!

SetMtMode(5)
mpeg2source("F:\1x02\VIDEO_TS\VTS_01_1.d2v")
import("d:\Programmi\AviSynth 2.5\plugins\SeeSaw.avs")
import("d:\Programmi\AviSynth 2.5\plugins\mvbob.avs")
#import("d:\Programmi\AviSynth 2.5\plugins\spresso.avs")
ColorMatrix(d2v="F:\1x02\VIDEO_TS\VTS_01_1.d2v")
Crop(8,80,-32,-80)
SeparateFields()
a=SelectEven().DeGrainMedian(limitY=0,limitUV=4,mode=1).SeeSaw(NRlimit=2, NRlimit2=2, Sstr=1.0, Slimit=7, Spower=2, Sdamplo=8, Szp=10, bias=1)
b=SelectOdd().DeGrainMedian(limitY=0,limitUV=4,mode=1).SeeSaw(NRlimit=2, NRlimit2=2, Sstr=1.0, Slimit=7, Spower=2, Sdamplo=8, Szp=10, bias=1)
weave()
#TomsMoComp(1,3,1)
mvbob()
mvfps(25)
LumaYV12(0,0.9)

zambelli
24th October 2006, 01:38
Yeah, I've got it. My problem is not that MVbob() doesn't work at all - but that it produces combing artifacts even in non-moving images. See my linked post above.
If anyone runs into the same problem... Turns out this was causes by Avisynth's memory cap being set too low (16MB). It appears that some plugin in the MVBob suite doesn't report out of memory errors but produces bad results instead. So... Remember to give MVBob plenty of room to breathe!

canuckerfan
7th August 2007, 19:18
not sure if this is the right place to ask, but here goes. is there anyway to update mvbob to take advantage of SSE2 capabilities?

Revgen
7th August 2007, 19:21
not sure if this is the right place to ask, but here goes. is there anyway to update mvbob to take advantage of SSE2 capabilities?

I don't think it would matter.

MVBob needs RAM more than SSE2 or a faster CPU.

It's also a function, so SSE2 would have to be present in all plugins in order to work.

halsboss
10th March 2008, 07:45
Is the latest MT2 version of MVbob here from foxyshadis ? http://forum.doom9.org/showthread.php?p=812334#post812334

TSchniede
29th March 2008, 02:49
I think the newest version is on
http://forum.doom9.org/showthread.php?p=1052018#post1052018

I myself use a modified version of mvbob as mvbob.mrestore usually gives better results than restore24 or other ivtc but it is really dead slow


#needs mvtools >= 1.8.2 for pelclip, was: clip2x, dct is available since 1.6.1
#based on mvbob, a motion compensated bobber, build by scharfis_brain.
##nnedi and nnedibob was made possible by tritical and the fellow Doom9 community who contributed CPU cycles.

#Helper functions:
Function DumbBob(clip Input, int "Height")
{
Input.Bob(0, 0.5, height = Height)
GetParity(Input) ? AssumeTFF() : AssumeBFF()
}
#slow, but accurate EEDI-bob, always dumb ;)
function eedibob(clip i, bool "s")
{
s=default(s,false)
i.separatefields().eedi2(field = (getparity(i) ? 3 : 2), nt = (s ? 35 : 50), pp = (s ? 3 : 1))
assumeframebased()
getparity(i) ? assumetff() : assumebff()
}
Function nnEDIbob(clip Input)
{
Input.nnedi(field=-2)
}
# BSec is based on SecureBob, default is only different for YUY2 color.
# l > 2 : different motiondedection, compares each field wih its temporal predessors, it reacts faster to "static" areas => anime
# similar to motion/interlacing dedection of Kerneldeint
#
# postprocessing: (touces even non-interpolated fields in default code, one possible solution is included below)
# edgeth,calmHEddge calms all nearly horizontal edges with strong temporal filtering (ReduceFlicker),
# makes the bob-weakness less obvious, luma only => anime, edgeth is the threshold for the edge dedection.
function BSec(clip Input, int "th", int "l",int "type", int "edgeth", bool "calmHEddge"){
function staticmask(clip e, int th, int l, int chromafilt){
e0 = e.MotionMask(thY1 = th, thY2 = th, thC1 = Round(th * 0.5), thC2 = Round(th * 0.5), thSD = 255, U = 3, V = 3)
e1 = e0.trim(1, 0)
e2 = e0.trim(2, 0)
e3 = e0.trim(3, 0)
e4 = e0.trim(4, 0)
e5 = e0.trim(5, 0)
e6 = e0.trim(6, 0)
e7 = e0.trim(7, 0)

ea0 = mt_logic(e0, e1, "or", u = chromafilt, v = chromafilt)
ea1 = mt_logic(e2, e3, "or", u = chromafilt, v = chromafilt)
ea2 = mt_logic(e4, e5, "or", u = chromafilt, v = chromafilt)
ea3 = mt_logic(e6, e7, "or", u = chromafilt, v = chromafilt)

eb0 = mt_logic(ea0, ea1, "or", u = chromafilt, v = chromafilt)
eb1 = mt_logic(ea2, ea3, "or", u = chromafilt, v = chromafilt)

ec = mt_logic(eb0, eb1, "or", u = chromafilt, v = chromafilt)

(l==0) ? ec .duplicateframe(0).duplicateframe(0).duplicateframe(0) :\
(l==1) ? eb0.duplicateframe(0) :\
(l==2) ? ea0 : e0

return last
}

th = default(th, 3)
l = default(l, 2)
type=default(type,3)
edgeth = default(edgeth, (default(calmHEddge,false) ? 110 : -1))

YV12input = isyv12(Input)
i2=YV12input ? Input : Input.converttoyv12(interlaced = true)
i3=i2.separatefields()
YVtype = YV12input ? 3 : 1

Bobbed = (Type == 0) ? Input.DumbBob() :\
(Type == 1) ? Input.eedibob() :\
(Type == 2) ? Input.eedibob(s=true) :\
Input.nnEDIBob()

Weaved = i2.DoubleWeave()

EvenFields = i3.SelectEven().StaticMask(th, l, YVtype)
OddFields = i3.SelectOdd() .StaticMask(th, l, YVtype)

BobbedYV12= (YV12input ? Bobbed : Bobbed.converttoyv12())

CombMaskT = Interleave(EvenFields, OddFields).dumbbob()
CombMask = (l > 2) ? Weaved.StaticMask(th, l-2, YVtype).fadein0(3,color=$FFFFFF) : Merge(CombMaskT.Trim(1, 0), CombMaskT, 0.5).mt_binarize(threshold=20,upper=true,u = YVtype,v = YVtype).fadein0(2).invert()


HLMask = edgeth > 0 ? mt_lutxy(BobbedYV12.mt_edge(mode = "3 3 3 -1 -1 -1 -2 -2 -2 4", thY1=0, thY2=255, thC1=255, thC2=255,u=1,v=1),
\BobbedYV12.mt_edge(mode = "-2 -2 -2 -1 -1 -1 3 3 3 4", thY1=0, thY2=255, thC1=255, thC2=255,u=1,v=1)
\,yexpr="x y + "+string(edgeth * 2)+" > 255 0 ?",u=1,v=1).mt_expand(u=1,v=1).removegrain(12) : i3 #HLMask chroma is garbage !!!

BobbedYV12 = edgeth > 0 ? mt_merge(BobbedYV12,BobbedYV12.ReduceFlicker(),HLMask, u = 2, v = 2) : BobbedYV12

####### restrict temporal filtering to interpolated fields, instead to only moving "horizontal" lines (IMHO those are always "moving" due to interpolation)
# BobbedYV12 = interleave(i2.separatefields(),BobbedYV12.separatefields().selectevery(4,1,2)).weave()

# merge bobbed moving areas with weaved static areas
mt_merge(Weaved, BobbedYV12, CombMask, u = YVtype, v = YVtype)

####### Debug: show difference between normal motiondedection and alternative eg. l==x and l==x+2, only useful for x <= 2
# stackhorizontal(mt_merge(Weaved, Bobbed, CombMask, u = 3, v = 3),mt_merge(Weaved, Bobbed, Weaved.StaticMask(th, l), u = 3, v = 3))

YV12input ? last : last.converttoyuy2().mergechroma(Bobbed,1.0)
getparity(Input) ? assumetff() : assumebff()
assumeframebased()
return getparity(Input) ? assumetff() : assumebff()
}


# MCF (MotionCompensateFields) is based on different versions of MVBob, BSec.MCF(simplemv=true) should yield results similar to recent MVBob()
# MCF makes motioncompensation on the interpolated fields on a bobbed clip, unlike MVBob which includes SecureBob.
# differences:
# uses pelclip instead of idx => more MT friendly
# uses dct option (mdct) helps for (flickering video / fadeout) but is slow
# thSAD (tSAD) makes motion compensation only in areas with reasonable results =>
# the blurred check in the corrector makes nearly never obvious artifacts, even for threasholds >5
# otherwise areas with very high contrast can still contain arifacts which cancel each other out in the smoother
# debugtSAD: show the input and the motion compensated predesor and succesor, try on scenechanges and blends
# coherence: coherence of the motion vectors, default is 1000 for mvtools, 6000 for mvbob, I took 2000 because bad blocks get thrown away - thSAD
# mblur: is clip for mismatch analysis burred by simple kernelblur or medianblur?
function MCF(clip bobc, int "blksize", int "th", int "tSAD", bool "debugtSAD", int "mdct", int "coherence", bool "mblur")
{
function blurclip(clip oclip, bool blurtype){
return blurtype ? oclip.removegrain(12).removegrain(12) : oclip.BicubicResize(oclip.Width * 2, oclip.Height).MedianBlur().BicubicResize(oclip.Width, oclip.Height)
}
# threshold for correcting failed compensated motion
th=default(th, 10)

# defaults for the mocomp
blksize=default(blksize,8)
ol = blksize/2
tm = true
mdct= default(mdct,0)

# recent versions of mvtools can implicitly mask away blocks with SAD > x, only for mvcompensate
tSAD = default(tSAD,320)
debugtSAD = default(debugtSAD,false)
coherence = default(coherence,2000)

# blur type for mismatch analysis
mblur = default(mblur,false)

#determine clip Fieldorder
yv12 = isyv12(bobc)

# create the upscaled clips for mvtools
bob2x = bobc.Lanczos4Resize(bobc.width()*2,bobc.height()*2,src_left=0.25, src_top=0.25)

# create motion vectors
mvf=bobc.mvanalyse(blksize=blksize,pel=2,isb=false,chroma=true, pelclip=bob2x, truemotion=tm,overlap=ol, dct=mdct, lambda=coherence)
mvb=bobc.mvanalyse(blksize=blksize,pel=2,isb=true, chroma=true, pelclip=bob2x, truemotion=tm,overlap=ol, dct=mdct, lambda=coherence)

# create the motion compensated clip that are passed through to the output
mcf=bobc.MVCompensate(mvf,pelclip=bob2x, thSAD=tSAD)
mcb=bobc.MVCompensate(mvb,pelclip=bob2x, thSAD=tSAD)

# create clips for mismatch detection
bobcf= (yv12 == false) ? mcf.converttoyv12().blurclip(mblur).converttoyuy2() : mcf.blurclip(mblur)
bobcb= (yv12 == false) ? mcb.converttoyv12().blurclip(mblur).converttoyuy2() : mcb.blurclip(mblur)
bobcs= (yv12 == false) ? bobc.converttoyv12().blurclip(mblur).converttoyuy2() : bobc.blurclip(mblur)

# detect mismatches of mvtools and replace them with motion adaptive bobbed areas
mc=corrector(bobcs,bobc, bobcf,bobcb, mcf,mcb, mode=0,th=th)

# select the correct lines
compensated_even= mc.selecteven().separatefields().selectodd()
compensated_odd = mc.selectodd() .separatefields().selecteven()

# merge them with the original fields
original_even=bobc.selecteven().separatefields().selecteven()
original_odd =bobc.selectodd().separatefields().selectodd()

even = interleave(original_even, compensated_even).weave()
odd = interleave(original_odd , compensated_odd ).weave()

interleave(even,odd)

# output video
(bobc.getparity()) ? last.assumetff() : last.assumebff()
debugtSAD ? (isyv12 ? stackvertical(fields,mcf,mcb) : stackvertical(fields,mcf,mcb).converttoyuy2()) : last
}

# needed plugins
LoadPlugin("RemoveGrain.dll") #use SSE version if your CPU allows
LoadPlugin("masktools.dll")
LoadPlugin("mt_masktools.dll") #replacement for masktools, mt_motion broken - (th unused, at least when I checked, v29 I think)
LoadPlugin("mvtools.dll")#newest version recommended
LoadPlugin("corrector.dll")#for new mvtools
LoadPlugin("medianblur.dll") # can be used for mismatch detection instead of removegrain
LoadPlugin("nnedi.dll")
LoadPlugin("eedi2.dll")
LoadPlugin("ReduceFlicker.dll") #use SSE version if your CPU allows