PDA

View Full Version : Deinterlacing hybrid footage


changeandy
1st January 2007, 00:50
Hi I just spent about 2 months tweaking this deinterlacing algorithm, and it turned out quite nicely (I think), so I thought I'd share.

It may be a bit slow, but it manages stuff like window blind flicker and keeping progressive frames progressive quite well. It outputs at double the original framerate, so you can also use it to create SloMo footage.
Issues:
- It seems to have some problems with YV12 footage, so you might have to convert to YUY2 first.
- Frames with very little motion are interpreted as progressive, so this algorithm will put out two identical frames. Shouldn't matter much though, as you probably will be reducing the framerate, or, if you are using it for SloMo the frames will be high motion anyway.
- Speed. I'm just a script kid, not a real coder. I just combined what other people have written. Sorry :-(

Well, so without any further ado here it is, hope you like it:

IntFootage=avisource("myvideo.avi")

doubled = IntFootage.separatefields().DoubleWeave()
# What we base our interlaced/progressive decision on

smoothie = IntFootage.SmoothDeinterlace(tff=false, doublerate=true,lacethresh=0)
# Deinterlaces with very little flicker for pure interlaced, but does not handle progressive frames that well.
#! You might have to change the tff parameter

TreatAsCombed = IntFootage.tdeint(mode=1,cthresh=2,tryweave=true,edeint=smoothie)
# This replaces the combed parts with the corresponding parts of smoothie. Cthresh is at very low tolerance.

TreatAs1Frame = IntFootage.tdeint(mode=1,cthresh=10,tryweave=true,edeint=smoothie)
# Same as TreatAsCombed, but cthresh is set so that it uses as much of the original scanlines as possible


ConditionalFilter(doubled, TreatAsCombed, TreatAs1Frame, "IsCombed(11)", "equals", "true", show=false)
# Chooses the appropriate proc. method, whether the frame shoud be treated as combed or progressive

FieldDeinterlace(map =false, blend=true, dthreshold=3)
# Removes most of the remaining combing atifacts

msharpen(threshold=8,strength=23,mask=false,highq=false)
# Sharpens the image slightly after processing. Not strictly part of the deinterlacing, but I like the results

selectevery(2,0)
# Use this if you want to keep the original framerate. If you want to convert NTSC video (29.97i) to look like film (23.976p) use selectevery(10,0,2,5,7). For SloMo use assumefps(*your project's framerate*) instead.


Well that's it, I hope I assembled something useful to you here. If you use it please post where you find it to work well, and where it causes problems, so people can decide if this is useful for them.

Thanx go out to all the coders who created and contributed to AviSynth, without whom this script kid's contribution would have been impossible. Thank you.


Changeandy

foxyshadis
1st January 2007, 08:18
I think that's very awesome. I'll incorporate the first few steps into the VFR faq once it comes back online. The FieldDeinterlace could be better replaced with Vinverse, without too much of a slowdown. (The SelectEven and sharpening should be separate from the script.) I'll give it a try later on versus the standard bobbers.

changeandy
2nd January 2007, 00:54
Glad you like it. It's good to see that my work is also useful to others. I just downloaded Vinverse, and will give it a try.

True the sharpening is not part of the script. But I also pointed that out in the comments. I just included it because I thought it might be helpful to some people. Frame reduction, I believe, would be part of the script if you are talking deinterlacing, but not when you're talking bobbing, and here also I just included it because I thought it might help someone. The important part of the script though (and what I spent my time on), is what comes before, I do agree. And I feel honored that you want to include it in the FAQ.

Let me know how it turns out with the other bobbers.

Thank you,

Changeandy

ToS_Maverick
2nd January 2007, 09:40
wouldn't be "tdeint(mode=1,full=false,tryweave=true)" be the same? if not, where's the difference?

i used it for backing up babylon 5 (pal version), where the live-action was shot on film (in pal 25 fps prog.) and the CGIs were interlaced. TDeint was perfectly able to leave the film content untouced and just deinterlace the CGIs.

changeandy
2nd January 2007, 16:01
NICE. And fast, too. There seems to be slightly more window blind flicker (that was one of the big issues of the material that I was trying to deinterlace), but not very much.

I tried modifying it a bit, namely:

- putting in smoothdeinterlace as the bobber
- changing the cthresh value (some oft the CGI logos in my material are quite sharp and can cause tdeint to think some parts of the frame are combed)
- adding FieldDeinterlace for postprocessing (vinverse does not seem to work quite as well for the material I have, although I haven't played with the parameters yet)

like so:

smoothie = IntFootage.SmoothDeinterlace(tff=false, doublerate=true,lacethresh=0) #! You might have to change the tff parameter
tdeint(mode=1,full=false,cthresh=7,tryweave=true,edeint=smoothie)
FieldDeinterlace(map =false, blend=true, dthreshold=3)

and I must say I REALLY like the results. Much more elegant than my two-pronged approach. Most artifacts I found to be pretty much invisible in real time playback. It makes for a fast and effective all-rounder. Thanks for the tip!

changeandy
2nd January 2007, 17:23
The main difference between the two approaches is: with your approach, tdeint with full=false returns a frame it thinks is progressive unchanged. With my approach only the threshold for combing gets raised, but it is still checked for combed areas. IsCombed does not really determine if a frame is combed or not, but if combing exceeds a certain level. So in case of the progresive logos I mentioned, the decombing will not be as rigourous (to keep as much of the original data as possible), but if there is anything obviously combed in that frame it will be processed. To make it simple: In my approach the second analysis questions the validity of the first. Is that fuzzy logic?


PS: I just found some artefacts that occur with my original approach at some scene changes caused by the low cthresch. I had put it at 2 before I used FieldDeinterlace for postprocessing. Now a cthresh of 4 for interlaced is probably low enough (at least I don't see those artefacts anymore).

So it's probably best to change that line to:
TreatAsCombed = IntFootage.tdeint(mode=1,cthresh=4,tryweave=true,edeint=smoothie)

ToS_Maverick
3rd January 2007, 09:22
NICE. And fast, too. There seems to be slightly more window blind flicker (that was one of the big issues of the material that I was trying to deinterlace), but not very much.

I tried modifying it a bit, namely:

- putting in smoothdeinterlace as the bobber
- changing the cthresh value (some oft the CGI logos in my material are quite sharp and can cause tdeint to think some parts of the frame are combed)
- adding FieldDeinterlace for postprocessing (vinverse does not seem to work quite as well for the material I have, although I haven't played with the parameters yet)

like so:

smoothie = IntFootage.SmoothDeinterlace(tff=false, doublerate=true,lacethresh=0) #! You might have to change the tff parameter
tdeint(mode=1,full=false,cthresh=7,tryweave=true,edeint=smoothie)
FieldDeinterlace(map =false, blend=true, dthreshold=3)

and I must say I REALLY like the results. Much more elegant than my two-pronged approach. Most artifacts I found to be pretty much invisible in real time playback. It makes for a fast and effective all-rounder. Thanks for the tip!

i'm glad you like my approach ;)

the speed is really great, since tdeint just does a quick check if the frame is interlaced, and if not, just skips to the next one. great for content with 90 % of film, like B5 :D

have you checked the parameter-list of TDeint? you can tweak the threshold with the "map" parameter. i really like the defaults and i also don't have that much time to tweak it.

have you tired EEDI2? you could try to replace SmoothDeinterlace. i don't know this filter, maybe you prefer eedi2 ;)

you can use it like this:
interp = separatefields().eedi2(field=-2)
tdeint(mode=1,full=false,tryweave=true,edeint=interp)

i wonder if you are interested in doing a VFR-video? if so, you can check DeDup, it works really well with tdeint! DeDup checks for identical frames (with a threshold), and since tdeint outputs 2 identical ones if they are not interlaced... i guess you know what i mean :cool:
if 2 identical frames a found, the duplicate is removed and an entry in a vfr-timecode-file is made.

have fun playing around!

IanB
3rd January 2007, 10:16
doubled = IntFootage.separatefields().DoubleWeave() will internally use DoubleWeaveFields which does a full frame blit every frame.

doubled = IntFootage.DoubleWeave() will do the same thing and internally use the faster DoubleWeaveFrames which only does 1 blit per 2 frames.

changeandy
4th January 2007, 10:21
@ IanB: Thank you for the tip!

@ToS_Maverick: Yes, I tried eedi2 and it is quite a good bobber. What I especially like about it is how it produces very smooth edges. But I was having issues with some window blinds in the background and eedi2 produced too much flicker there. I looked long and hard for a command that would reduce this very annoying artefact and finally stumbled upon Smoothdeinterlace, which has quite excellent flicker reduction. It does, however, have shortcomings with progressive footage as well as producing somewhat pixellated edges. Here TDeint could compensate quite well, since it definitely knows which scanlines to keep and which to bob. And it allows you to use any bobber you like, how great is that? Finally I used FieldDeinterlace to smooth out the pixellated edges, and Bob was my uncle, so to say :p.

As for VFR video, I have not yet done anything in that area, but I will keep your tip in mind.