Last active
January 31, 2017 21:12
-
-
Save stuxcrystal/8e22e4d86b68ef5f3b486a94749d0d5a to your computer and use it in GitHub Desktop.
Idea for Vapoursynth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from vapoursynth import core, YUV | |
def shuffle_uv(clip): | |
""" | |
This function should always work as the get_core-call is deferred until | |
getattr or setattr is actually called on the proxy. | |
""" | |
return core.std.ShufflePlanes([clip], [0,2,1], colorfamily=YUV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from vapoursynth import * | |
# copy from here | |
class _CoreProxy(object): | |
""" | |
This class acts like a proxy for the current vapoursynth.Core-Instance. | |
The idea is to allow something like this: | |
>>> from vapoursynth import core | |
>>> core # doctest: +ELLIPSIS | |
<vapoursynth.Core ...> | |
>>> core.std # doctest: +ELLIPSIS | |
<vapoursynth.Plugin ...> | |
>>> core.std.BlankClip # doctest: +ELLIPSIS | |
<vapoursynth.Function ...> | |
>>> core.num_threads = 2 | |
>>> core.num_threads | |
2 | |
""" | |
@property | |
def _core(self): | |
return get_core() | |
def __getattr__(self, name): | |
# This is actually faster than calling hasattr because | |
# hasattr is actuall implemented by doing an attribute-lookup | |
# and return False if an AttributeError is raised. | |
try: | |
return getattr(self._core, name) | |
except AttributeError: | |
return super(_CoreProxy, self).__getattr__(name) | |
def __setattr__(self, name, value): | |
setattr(self._core, name, value) | |
def __delattr__(self, name): | |
# I suspect this function is useless but I'll include it anyways. | |
self._core.__delattr__(name) | |
def __repr__(self): | |
return repr(self._core) | |
core = _CoreProxy() | |
del _CoreProxy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment