Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 19th March 2015, 21:03   #1  |  Link
Pat357
Registered User
 
Join Date: Jun 2006
Posts: 452
TDeintMod : need some help

I'm looking for a good deinterlacer that is faster and "lighter" than QTGMC.
I came to the ported TDeint called TDeintMod (https://github.com/HomeOfVapourSynth...ynth-TDeintMod )

The example on this page :
Code:
import vapoursynth as vs
import functools

core = vs.get_core()
clip = Whatever

def conditionalDeint(n, f, orig, deint):
    if f.props._Combed:
        return deint
    else:
        return orig

deint = core.tdm.TDeintMod(clip, order=1, edeint=core.nnedi3.nnedi3(clip, field=1))
combProps = core.tdm.IsCombed(clip)
clip = core.std.FrameEval(clip, functools.partial(conditionalDeint, orig=clip, deint=deint), combProps)
clip.set_output()
Now what is this functools.partial in the FrameEval line ? Any more info about this would be nice.
What does this functools.partial exactly do ? I don't fully understand how this script works.
Can anyone explain this script to me ?
Like why does ConditionalDeint(n, f, orig, deint) need 4 arguments when we use only 3 of them ? (f, orig and Deint) , and "n" appears to be never used... ?
Has anyone a better or more comprehensive way to do this ?

This example should work for the same output rate as the input. How about double rate (bobbing) ?
Can this script be adapted for double rate output ?
Just letting NNEDI3 output double rate by setting "field=3" option won't obviously work, as the "edeint" clip will have double rate which doesn't match anymore.

Last edited by Pat357; 20th March 2015 at 00:28.
Pat357 is offline   Reply With Quote
Old 20th March 2015, 03:55   #2  |  Link
captainadamo
Guest
 
Posts: n/a
Functools documentation:

Quote:
functools.partial(func, *args, **keywords)
Return a new partial object which when called will behave like func called with the positional arguments args and keyword arguments keywords. If more arguments are supplied to the call, they are appended to args. If additional keyword arguments are supplied, they extend and override keywords. Roughly equivalent to:

Code:
def partial(func, *args, **keywords):
    def newfunc(*fargs, **fkeywords):
        newkeywords = keywords.copy()
        newkeywords.update(fkeywords)
        return func(*(args + fargs), **newkeywords)
    newfunc.func = func
    newfunc.args = args
    newfunc.keywords = keywords
    return newfunc
The partial() is used for partial function application which “freezes” some portion of a function’s arguments and/or keywords resulting in a new object with a simplified signature. For example, partial() can be used to create a callable that behaves like the int() function where the base argument defaults to two:
  Reply With Quote
Old 20th March 2015, 11:34   #3  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
It may help to read the documentation for the FrameEval filter too.

I'm not sure how helpful it is, but here's a picture:


For every frame n requested from FrameEval, it requests the corresponding frame from IsCombed (combProps), then passes said frame to the conditionalDeint() function, along with the frame number n, and the two arguments given to functools.partial(), orig and deint. IsCombed examines the frame and attaches the "_Combed" property, with the value of 0 or 1. The conditionalDeint() function then looks at that property and returns either orig or deint. FrameEval then takes the clip returned by conditionalDeint() and requests frame n from it, then returns that frame.

A better way to do this would be to make TDeintMod examine the "_Combed" property on its own, without involving Python and FrameEval. That's up to the author of TDeintMod, though.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 20th March 2015, 13:04   #4  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,548
What is the source material? If it's truly interlaced you probably should process all of it and skip the FrameEval stuff.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 20th March 2015, 13:35   #5  |  Link
TheFluff
Excessively jovial fellow
 
Join Date: Jun 2004
Location: rude
Posts: 1,100
Quote:
Originally Posted by Pat357 View Post
Now what is this functools.partial in the FrameEval line ? Any more info about this would be nice.
It creates a partial function.

Let's say you have a function that takes two arguments, a and b:

Code:
def a_function(a, b):
do something with a and b
Now, if you figure that you want to call the function without explicitly specifying argument a. You create a partial function:

Code:
new_function = functools.partial(a_function, a_value_for_a)
Now you have a function called new_function, that, when called, will behave just as if you called a_function with the a argument being a_value_for_a. More importantly, new_function won't even have an a parameter, you can call it with only b.

In VS this is sometimes useful for passing a function as an argument to another function with extra parameters passed along.

Last edited by TheFluff; 20th March 2015 at 13:39.
TheFluff is offline   Reply With Quote
Old 20th March 2015, 16:58   #6  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 760
Quote:
Originally Posted by HolyWu View Post
Actually in the earlier releases, TDeintMod itself already contained the functionality of IsCombed, but got separated into another filter later on. The reason is, when users feed edeint with a clip that comes from a kinda slow upstream, like QTGMC for example, the frames from edeint are requested in arInitial state anyway, even though they are not used in the final arAllFramesReady state when the frames are detected as not combed, and the time is wasted.
That makes sense.

You could use fmUnordered and only request frames from edeint when they're needed:
Code:
if (activationReason == arInitial) {
    // request n from IsCombed()
} else if (activationReason == arAllFramesReady) {
    if ((intptr_t)(*frameData) == 1) {
        // get n from edeint and return it
    } else {
        // get n from IsCombed()
        if (!_Combed)
            // return n
        else
            // request n from edeint
            *frameData = (void *)1;
    }
}
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 20th March 2015, 18:58   #7  |  Link
Pat357
Registered User
 
Join Date: Jun 2006
Posts: 452
Thanks for the for all your reactions !
After re-reading the things you all mentioned here, I think I now understands how it works.

I can't accept it for myself to use a script that I don't fully understand :-)

Thanks again to all !
Pat357 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 14:16.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.