Log in

View Full Version : Creating/Loading Script Files


MysteryX
21st June 2021, 22:40
I'm looking into converting an Avisynth AVSI file to VapourSynth.

I'm stuck at the very basics: importing a script file into another one.

import FrameRateConverter as frc
Python exception: No module named 'FrameRateConverter'

from . import FrameRateConverter as frc
Python exception: attempted relative import with no known parent package

How am I supposed to do it? And do I have to create utility files with .py extension, while the main VapourSynth script file itself is .vpy?

MysteryX
22nd June 2021, 02:05
I found the sample scripts here
https://vsdb.top/

Obviously it will load if it's in the VapourSynth plugin folders. Does that mean I need to do all the development in the VapourSynth plugin folder?

Then for software like StaxRip coming with plugins bundled, how does it set to search in its own folder?

Selur
22nd June 2021, 19:25
This is how Hybrid which uses a portable Vapoursynth imports stuff:

# Imports
import os
import sys
import ctypes
# Loading Support Files
Dllref = ctypes.windll.LoadLibrary("I:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
import vapoursynth as vs
core = vs.get_core()
# Import scripts folder
scriptPath = 'I:/Hybrid/64bit/vsscripts'
sys.path.append(os.path.abspath(scriptPath))
# Loading Plugins
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/Support/EEDI3.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/vsznedi3.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/Support/temporalsoften.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
core.std.LoadPlugin(path="I:/Hybrid/64bit/vsfilters/SourceFilter/d2vSource/d2vsource.dll")
# Import scripts
import havsfunc


Cu Selur

MysteryX
23rd June 2021, 02:05
I'm having issues loading .py script files. If I put them in the same folder, it doesn't recognize them. If I put it in the VapourSynth\plugins folder, it loads the DLLs but doesn't recognize the scripts either.

How do I get them to be found?

MysteryX
23rd June 2021, 03:57
Installing the scripts via vsrepo does work, but that doesn't answer how to load scripts as I'm developing them, or how to load them from a set folder.

poisondeathray
23rd June 2021, 04:27
By default they are imported from the python site-packages directory

eg.
import havsfunc

would automatically look in the site-packages directory for havsfunc.py


Selur has an example above of how to use a custom location

Selur
23rd June 2021, 19:23
Through sys.path.append(os.path.abspath(scriptPath)) I tell Python to that 'scriptPath' is an additional path or for find scripts in side.
With 'import havsfunc' I tell it to search all the script paths for a file named havsfunc(.py) and load it under the name havsfunc, if I would use 'import havsfunc as havs' it would be available under 'havs'.
When using 'import havsfunc' I can access QTGMC through 'clip = havsfunc.QTGMC(...)'
So unless you use the one of the autoloading/importing folders from Python, this is the way it goes afailk. :)

Your
from . import FrameRateConverter as frc
should be

import os
import sys
# append current dir, the current script file resides in, to sys.path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# import FrameRateConver script file under the name frc
import FrameRateConverter as frc

__file__ = current file
os.path.abspath(__file__)) = absolute path to current file
os.path.dirname(os.path.abspath(__file__))) = absolute path to the directory the current file resides in

Cu Selur

Ps.: I hope this helps a bit :)