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 7th October 2019, 14:27   #3641  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,926
Quote:
Originally Posted by Myrsloik View Post
Does it work if you add core.std.SetMaxCPU("none") to the top of the script?
Yes . Do you have to specify it manually now , no autodetection ?

This was on a Haswell with AVX2 only
poisondeathray is offline   Reply With Quote
Old 7th October 2019, 16:22   #3642  |  Link
DJATOM
Registered User
 
DJATOM's Avatar
 
Join Date: Sep 2010
Location: Ukraine, Bohuslav
Posts: 185
Quote:
Originally Posted by poisondeathray View Post
Yes . Do you have to specify it manually now , no autodetection ?

This was on a Haswell with AVX2 only
No, auto-detection is still works, but now we can set lower instruction set (or fallback to C routines) on purpose. For example, if there are some bugs with avx2 optimizations, you can fallback to slower but well working functions.
__________________
Me on GitHub | My Telegram
PC Specs: Ryzen 3900X (no OC with 250W Air cooling), Asus ROG Crosshair Hero VII (WiFi) @ chipset x470, 32 GB RAM @ 3333MHz OC, Gigabyte RTX 2070, Kingston A1000 @ 240 GB
DJATOM is offline   Reply With Quote
Old 9th October 2019, 11:06   #3643  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,001
Several bugs were found already. Will post a new build soon when they're fixed. Apparently Expr is broken too in some cases.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 9th October 2019, 16:17   #3644  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,926
Quote:
Originally Posted by Myrsloik View Post
Several bugs were found already. Will post a new build soon when they're fixed. Apparently Expr is broken too in some cases.
Was it from any of the Expr AVS+ code from pinterf? If so, is AVS+ affected too ?
poisondeathray is offline   Reply With Quote
Old 9th October 2019, 18:36   #3645  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,001
Quote:
Originally Posted by poisondeathray View Post
Was it from any of the Expr AVS+ code from pinterf? If so, is AVS+ affected too ?
No and no. Also it could be a bug in the expression itself now that we've investigated it a bit...
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 10th October 2019, 04:48   #3646  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 75
about wrapping/decorating vapoursynth core functions:
Code:
import vapoursynth as vs
from vapoursynth import core
import functools
clip = core.std.BlankClip(width=640, height=360, format=vs.YUV420P8) 

def CropAbs_extra(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        print('some extra work')
        return f(*args, **kwargs)
    return wrapper

#this does not work:
#core.std.CropAbs =  CropAbs_extra(core.std.CropAbs)
#clip = core.std.CropAbs(clip, 360,240, 0,0) #to crop + some extra work
      #AttributeError: 'vapoursynth.Plugin' object has no attribute 'CropAbs'

#this works but script lines would need to be rewritten:
temp =  CropAbs_extra(core.std.CropAbs)
clip = temp(clip, 360,240, 0,0) #to crop + some extra work
I edited code above, because it did not work before.
Is there any way to keep :
clip = core.std.CropAbs(clip, 360,240, 0,0) and use a wrapper to it?
Thanks.

this does not work also:
Code:
setattr(core.std, 'CropAbs', CropAbs_extra(core.std.CropAbs))
    #AttributeError: 'vapoursynth.Plugin' object has no attribute 'CropAbs'

Last edited by _Al_; 10th October 2019 at 05:38.
_Al_ is offline   Reply With Quote
Old 10th October 2019, 22:34   #3647  |  Link
jackoneill
unsigned int
 
jackoneill's Avatar
 
Join Date: Oct 2012
Location: 🇪🇺
Posts: 723
Quote:
Originally Posted by _Al_ View Post
about wrapping/decorating vapoursynth core functions:
Code:
import vapoursynth as vs
from vapoursynth import core
import functools
clip = core.std.BlankClip(width=640, height=360, format=vs.YUV420P8) 

def CropAbs_extra(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        print('some extra work')
        return f(*args, **kwargs)
    return wrapper

#this does not work:
#core.std.CropAbs =  CropAbs_extra(core.std.CropAbs)
#clip = core.std.CropAbs(clip, 360,240, 0,0) #to crop + some extra work
      #AttributeError: 'vapoursynth.Plugin' object has no attribute 'CropAbs'

#this works but script lines would need to be rewritten:
temp =  CropAbs_extra(core.std.CropAbs)
clip = temp(clip, 360,240, 0,0) #to crop + some extra work
I edited code above, because it did not work before.
Is there any way to keep :
clip = core.std.CropAbs(clip, 360,240, 0,0) and use a wrapper to it?
Thanks.

this does not work also:
Code:
setattr(core.std, 'CropAbs', CropAbs_extra(core.std.CropAbs))
    #AttributeError: 'vapoursynth.Plugin' object has no attribute 'CropAbs'
I think it's a lot more work than you want, but you can replace vs.get_core with a function that returns a fake core, which will be a wrapper object around the real core:
Code:
import vapoursynth as vs
vs.get_core = function that returns fake core

import other, stuff

core = vs.get_core()
...
I'm not sure this actually works.
__________________
Buy me a "coffee" and/or hire me to write code!
jackoneill is offline   Reply With Quote
Old 11th October 2019, 07:57   #3648  |  Link
WolframRhodium
Registered User
 
Join Date: Jan 2016
Posts: 109
Agree with jackoneill, the cython part of VS prevents you from modifying attributes of "core" and its attribute "plugin". You should define your own "core" instead.

Last edited by WolframRhodium; 12th October 2019 at 15:35.
WolframRhodium is offline   Reply With Quote
Old 11th October 2019, 16:06   #3649  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 75
thank you guys,
WolframRhodium thank you for the script, it might be over my head , I'll tackle it though, thank you
_Al_ is offline   Reply With Quote
Old 11th October 2019, 16:44   #3650  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 75
At the end of vapoursynth2.py I put:
Code:
print(core.version())
if hasattr(core, 'ffms2'):
    print('ffms2 is loaded')
else:
    print('ffms2 is not loaded')
clip = core.ffms2.Source(video.mp4)
#clip = core.std.BlankClip(width=640, height=360)#BlankClip does not create VideoNode as well
if isinstance(clip, vs.VideoNode):
    print('clip was created')
else:
    print('clip is not  vs.VideoNode')
def CropAbs_extra(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        print('working in wrapper')
        return f(*args, **kwargs)
    return wrapper
print(clip)
core.std.CropAbs =  CropAbs_extra(core.std.CropAbs)  
clip = core.std.CropAbs(clip, 360,240,0,0)
print(clip)
I got output:
Code:
VapourSynth Video Processing Library
Copyright (c) 2012-2018 Fredrik Mellbin
Core R45
API R3.5
Options: -

ffms2 is loaded
clip is not  vs.videoNode
<__main__._VideoNode object at 0x00000000037B2A58>
so i t prints clip is a videonode but it does not work as a regular clip
But it does not throw any error trying to wrap that core.std.CropAbs function though, but also it is not in that wrapper.

Anyway , it might take a while to grasp it all.

Last edited by _Al_; 11th October 2019 at 16:47.
_Al_ is offline   Reply With Quote
Old 12th October 2019, 00:50   #3651  |  Link
WolframRhodium
Registered User
 
Join Date: Jan 2016
Posts: 109
Sorry for the confusion, for your code here is a tiny example.
WolframRhodium is offline   Reply With Quote
Old 12th October 2019, 01:44   #3652  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 75
Thank you so much.
So far I got quickly this together:

tinyvs.py:
Code:
import vapoursynth as vs
from vapoursynth import core as _vscore
import functools
class _Plugin:
    def __init__(self, namespace):
        self.__dict__.update((name, getattr(namespace, name)) for name in dir(namespace)) # func_name : func

class _Core:
    def __init__(self):
        self.__dict__.update((name, get_plugin(name)) for name in dir(_vscore)) # (namespace : (func_name : func)) or (attr_name : attr)

def get_plugin(name):
    attr = getattr(_vscore, name)
    if isinstance(attr, vs.Plugin):
        return _Plugin(attr)
    else:
        return attr

core = _Core()

def CropAbs_extra(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        print('extra work with calling vs function')
        c=  f(*args, **kwargs)
        return c
    return wrapper

core.std.CropAbs =  CropAbs_extra(core.std.CropAbs)
and actual script could be:
Code:
import importlib
import tinyvs
importlib.reload(tinyvs)  #mandatory reload so wrapper always works

core = tinyvs.core

clip = core.std.BlankClip(width=640, height=360)
clip = core.std.CropAbs(clip, 360,240, 0,0)
output:
Code:
extra work with calling vs function
Thanks

Last edited by _Al_; 12th October 2019 at 01:46.
_Al_ is offline   Reply With Quote
Old 12th October 2019, 05:55   #3653  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 75
Looking at that tinyvs.py, ...,this is a magic. How can you come up with stuff like this ,
core object is not copied, not wrapped but instead its attributes, plugins dir is just forwarded/copied to a new object so domains can be hijacked in script but functionality is kept.
_Al_ is offline   Reply With Quote
Old 12th October 2019, 06:42   #3654  |  Link
Cary Knoop
Cary Knoop
 
Cary Knoop's Avatar
 
Join Date: Feb 2017
Location: Newark CA, USA
Posts: 185
It must be me but I fail to see any benefit in overriding Vapoursynth core functions, I only see disadvantages.
Cary Knoop is offline   Reply With Quote
Old 12th October 2019, 09:32   #3655  |  Link
WolframRhodium
Registered User
 
Join Date: Jan 2016
Posts: 109
Quote:
Originally Posted by _Al_ View Post
Looking at that tinyvs.py, ...,this is a magic. How can you come up with stuff like this ,
core object is not copied, not wrapped but instead its attributes, plugins dir is just forwarded/copied to a new object so domains can be hijacked in script but functionality is kept.
I just want it to be tiny to show that it's possible. If you want certain level of safety, consider protections like using __getattr__ method to get attribute from "core".

Last edited by WolframRhodium; 12th October 2019 at 09:54.
WolframRhodium is offline   Reply With Quote
Old 12th October 2019, 22:21   #3656  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 75
Quote:
Originally Posted by Cary Knoop View Post
It must be me but I fail to see any benefit in overriding Vapoursynth core functions, I only see disadvantages.
you could branch to the whole lot of stuff, checking for correct cmd , returning error that is easier to understand, launch helper utility , program, gui for cropping and returning those values...

Quote:
Originally Posted by WolframRhodium View Post
I just want it to be tiny to show that it's possible. If you want certain level of safety, consider protections like using __getattr__ method to get attribute from "core".
so would this be any safer?, I don't know really why. It just creates an attribute if needed:
Code:
import vapoursynth as vs
from vapoursynth import core as _vscore
import functools

class _Core:
    def __getattr__(self, name):
        attr = getattr(_vscore, name)
        if isinstance(attr, vs.Plugin):
            self.__dict__.update({name : _Plugin(attr)})
            return _Plugin(attr)
        else:
            self.__dict__.update({name : attr})
            return attr     
    
class _Plugin:
    def __init__(self, namespace):
        self.__dict__.update((name, getattr(namespace, name)) for name in dir(namespace)) # func_name : func

def CropAbs_extra(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        print('in wrapper')
        c = f(*args, **kwargs)
        return c
    return wrapper

core = _Core()
core.std.CropAbs = CropAbs_extra(core.std.CropAbs)
clip = core.std.BlankClip(width=640, height=360, format = vs.YUV420P8)
clip = core.std.CropAbs(clip, 360,240, 0,0)
at the moment I try to pass that vs.Plugin attribute to __getatttr__as well so it is _Plugin does not go thru the all namespace dir functions

Last edited by _Al_; 12th October 2019 at 22:42.
_Al_ is offline   Reply With Quote
Old 12th October 2019, 22:32   #3657  |  Link
Cary Knoop
Cary Knoop
 
Cary Knoop's Avatar
 
Join Date: Feb 2017
Location: Newark CA, USA
Posts: 185
Quote:
Originally Posted by _Al_ View Post
you could branch to the whole lot of stuff, checking for correct cmd , returning error that is easier to understand, launch helper utility , program, gui for cropping and returning those values...
Sure, but the classical way is to use wrappers with your own functions.

Redefining API's to me is like writing a novel while changing the meaning of the words. It's possible, but what would be the point?

Please don't get me wrong, if you feel like doing it you certainly can, and if you want to do it don't let me stop you, but I personally think it is not a good idea.
Cary Knoop is offline   Reply With Quote
Old 12th October 2019, 23:07   #3658  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 75
It might be a dumb idea, I don't deny it and dealing should be done using outputs only.
_Al_ is offline   Reply With Quote
Old 12th October 2019, 23:21   #3659  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,001
If you really want to change the API that much it's a lot easier to just poke the cython code that generates the module directly. It's basically normal python with a few extensions.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 13th October 2019, 22:38   #3660  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Ikea Chair
Posts: 2,001
R48-test2 64bit

Nothing new as such, just fixes all found regressions. Give it a try again. Speed comparisons with R46 also welcome.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Reply

Tags
speed, vaporware, vapoursynth

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 16:34.


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