Ejemplo n.º 1
0
 /// <summary>
 /// Initializes the VapourSynth environment. It will be automatically finalized when the process exits.
 /// </summary>
 public static void Init()
 {
     if (!isInit)
     {
         // Increments on success, returns 0 on failure.
         if (VsInvoke.vsscript_init() > 0)
         {
             AppDomain.CurrentDomain.ProcessExit += (s, e) => {
                 // Decrements on success.
                 if (VsInvoke.vsscript_finalize() == 0)
                 {
                     isInit = false;
                 }
                 else
                 {
                     throw new Exception("Failed to finalize VapourSynth environment.");
                 }
             };
             isInit = true;
         }
         else
         {
             throw new Exception("Failed to initialize VapourSynth environment. 'vsscript.dll' could not be loaded.");
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an empty script environment.
        /// </summary>
        public static VsScript CreateEmpty()
        {
            IntPtr H = IntPtr.Zero;

            VsInvoke.vsscript_createScript(ref H);
            return(new VsScript(H));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads a script directly from a file. It will not be converted to COMPATBGR32.
        /// </summary>
        /// <param name="path">The path of the script file to open.</param>
        /// <param name="setWorkingDir">If true, current working directory will be changed to the path of the script.</param>
        public static VsScript LoadFileDirect(string path, bool setWorkingDir)
        {
            IntPtr H = IntPtr.Zero;

            if (VsInvoke.vsscript_evaluateFile(ref H, new Utf8Ptr(path).ptr, setWorkingDir ? VsInvoke.FlagSetWorkingDir : 0) == 0)
            {
                return(new VsScript(H));
            }
            else
            {
                string Err = new VsScript(H).GetError();
                VsInvoke.vsscript_freeScript(H);
                throw new VsException(Err);
            }
        }
Ejemplo n.º 4
0
        internal VsOutput(IntPtr scriptPtr, int nodeIndex)
        {
            getFrameAsyncCallback    = GetFrameAsync_Callback;
            getFrameAsyncCallbackPtr = Marshal.GetFunctionPointerForDelegate(getFrameAsyncCallback);
            this.scriptPtr           = scriptPtr;
            this.nodeIndex           = nodeIndex;

            nodePtr = VsInvoke.vsscript_getOutput(scriptPtr, nodeIndex);
            if (nodePtr == IntPtr.Zero)
            {
                throw new Exception("Failed to retrieve VapourSynth output node.");
            }

            this.apiPtr = VsInvoke.vsscript_getVSApi2(VsInvoke.VSSCRIPT_API_VERSION);
            if (this.apiPtr == IntPtr.Zero)
            {
                throw new Exception("Failed to get VapourSynth API.");
            }
            this.Api = Marshal.PtrToStructure <VsInvokeApi>(this.apiPtr);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads specified script.
        /// </summary>
        /// <param name="script">The script to load.</param>
        /// <param name="convertToCompatBgr32">If true, the script output will be converted to COMPATBGR32.</param>
        public static VsScript LoadScript(string script, bool convertToCompatBgr3)
        {
            if (convertToCompatBgr3)
            {
                script = AppendConvertCompoatScript(script);
            }

            IntPtr H = IntPtr.Zero;

            if (VsInvoke.vsscript_evaluateScript(ref H, new Utf8Ptr(script).ptr, IntPtr.Zero, 0) == 0)
            {
                return(new VsScript(H));
            }
            else
            {
                string Err = new VsScript(H).GetError();
                VsInvoke.vsscript_freeScript(H);
                throw new VsException(Err);
            }
        }
Ejemplo n.º 6
0
 public void Dispose()
 {
     VsInvoke.vsscript_clearOutput(apiPtr, nodeIndex);
     Api.freeNode(nodePtr);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Clears specified script video output.
 /// </summary>
 /// <param name="index">The output index specified in 'set_output'.</param>
 public int ClearOutput(int index)
 {
     return(VsInvoke.vsscript_clearOutput(handle, index));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns the error message returned by the script, or null.
        /// </summary>
        private String GetError()
        {
            IntPtr Err = VsInvoke.vsscript_getError(handle);

            return(Utf8Ptr.FromUtf8Ptr(Err));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Releases all resources associated with the script. Make sure all frames have been released first.
 /// </summary>
 public void Dispose()
 {
     VsInvoke.vsscript_freeScript(handle);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Returns the API version of the loaded Vapoursynth DLL.
 /// </summary>
 public static int GetApiVersion()
 {
     return(VsInvoke.vsscript_getApiVersion());
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Loads VapourSynth DLLs from specified path. Call this before calling any other functions if DLLs can't be found by default.
 /// </summary>
 /// <param name="path">The path containing the DLLs.</param>
 public static void SetDllPath(string path)
 {
     VsInvoke.SetDllPath(path);
 }