Beispiel #1
0
    def load_script(self, script_path: Path) -> None:
        from traceback import print_exc

        self.toolbars.playback.stop()

        self.statusbar.label.setText('Evaluating')
        self.script_path = script_path
        sys.path.append(str(self.script_path.parent))
        try:
            exec(self.script_path.read_text(), {})  # pylint: disable=exec-used
        except Exception:  # pylint: disable=broad-except
            logging.error(
                'Script contains error(s). Check following lines for details.')
            self.handle_script_error(
                'Script contains error(s). See console output for details.')
            print_exc()
            return
        finally:
            sys.path.pop()

        if len(vs.get_outputs()) == 0:
            logging.error('Script has no outputs set.')
            self.handle_script_error('Script has no outputs set.')
            return

        self.toolbars.main.rescan_outputs()
        # self.init_outputs()
        self.switch_output(self.OUTPUT_INDEX)

        self.load_storage()
Beispiel #2
0
    def __init__(self, local_storage: Optional[Mapping[str, Output]] = None) -> None:
        super().__init__()
        self.items: List[Output] = []

        local_storage = local_storage if local_storage is not None else {}

        if main_window().ORDERED_OUTPUTS:
            outputs = OrderedDict(sorted(vs.get_outputs().items()))
        else:
            outputs = vs.get_outputs()

        for i, vs_output in outputs.items():
            try:
                output = local_storage[str(i)]
                output.__init__(vs_output, i)  # type: ignore
            except KeyError:
                output = Output(vs_output, i)

            self.items.append(output)
Beispiel #3
0
def vs_clear_cache() -> None:
    import vapoursynth as vs

    cache_size = vs.core.max_cache_size
    vs.core.max_cache_size = 1
    output = list(vs.get_outputs().values())[0]
    if isinstance(output, vs.AlphaOutputTuple):
        output = output.clip
    output.get_frame(0)
    vs.core.max_cache_size = cache_size
 def get_results(self) -> t.Dict[str, Clip]:
     """
     Returns a dictionary with clips
     that represent the results of the script.
     """
     with self.use():
         return {
             str(k): WrappedClip(self.env, v)
             for k, v in vs.get_outputs().items()
         }
Beispiel #5
0
    def load_script(self, script_path: Path, external_args: str = '', reloading = False) -> None:
        from traceback import print_exc
        import shlex

        self.toolbars.playback.stop()

        self.statusbar.label.setText('Evaluating')
        self.script_path = script_path
        sys.path.append(str(self.script_path.parent))

        # Rewrite args so external args will be forwarded correctly
        if external_args:
            self.external_args = shlex.split(external_args)
        try:
            argv_orig = sys.argv
            sys.argv = [script_path.name] + self.external_args
        except AttributeError:
            pass

        try:
            # pylint: disable=exec-used
            exec(self.script_path.read_text(encoding='utf-8'), {
                '__file__': sys.argv[0]
            })
        except Exception:  # pylint: disable=broad-except
            self.script_exec_failed = True
            logging.error(
                'Script contains error(s). Check following lines for details.')
            self.handle_script_error(
                'Script contains error(s). See console output for details.')
            print_exc()
            return
        finally:
            sys.argv = argv_orig
            sys.path.pop()

        self.script_exec_failed = False

        if len(vs.get_outputs()) == 0:
            logging.error('Script has no outputs set.')
            self.handle_script_error('Script has no outputs set.')
            return

        if not reloading :
            self.toolbars.main.rescan_outputs()
            for toolbar in self.toolbars:
                toolbar.on_script_loaded()
            self.switch_output(self.OUTPUT_INDEX)

            self.load_storage()
        else:
            self.load_storage()
            for toolbar in self.toolbars:
                toolbar.on_script_loaded()
    def __init__(self,
                 local_storage: Optional[Mapping[str, Output]] = None) -> None:
        super().__init__()
        self.items: List[Output] = []

        local_storage = local_storage if local_storage is not None else {}
        for i, vs_output in vs.get_outputs().items():
            try:
                output = local_storage[str(i)]
                output.__init__(vs_output, i)  # type: ignore
            except KeyError:
                output = Output(vs_output, i)

            self.items.append(output)
Beispiel #7
0
    def __init__(self,
                 local_storage: Optional[Mapping[str, Output]] = None) -> None:
        super().__init__()
        self.items: List[Output] = []

        local_storage = local_storage if local_storage is not None else {}
        for i, vs_output in vs.get_outputs().items():
            pixel_format = vs_output.format
            vs_output = vs.core.resize.Bicubic(vs_output,
                                               format=vs.COMPATBGR32,
                                               matrix_in_s='709',
                                               chromaloc=0,
                                               prefer_props=1)
            vs_output = vs.core.std.FlipVertical(vs_output)

            try:
                output = local_storage[str(i)]
                output.__init__(vs_output, i, pixel_format)  # type: ignore
            except KeyError:
                output = Output(vs_output, i, pixel_format)

            self.items.append(output)
Beispiel #8
0
 def get_global_outputs():
     import vapoursynth
     if Features.EXPORT_OUTPUT_DICT:
         return vapoursynth.get_outputs()
     return types.MappingProxyType(
         vapoursynth._get_output_dict("OutputManager.get_outputs"))
Beispiel #9
0
 async def retrieve_clips(self) -> Mapping[str, Clip]:
     await self.ensure_acquired()
     with self.inside():
         outputs = get_outputs().items()
     return {str(k): VapourSynthClip(self, d) for k, d in outputs}
Beispiel #10
0
    def load_script(self,
                    script_path: Path,
                    external_args: str = '',
                    reloading=False) -> None:
        import shlex
        from traceback import FrameSummary, TracebackException

        self.toolbars.playback.stop()

        self.statusbar.label.setText('Evaluating')
        self.script_path = script_path
        sys.path.append(str(self.script_path.parent))

        # Rewrite args so external args will be forwarded correctly
        if external_args:
            self.external_args = shlex.split(external_args)
        try:
            argv_orig = sys.argv
            sys.argv = [script_path.name] + self.external_args
        except AttributeError:
            pass

        try:
            # pylint: disable=exec-used
            exec(self.script_path.read_text(encoding='utf-8'),
                 {'__file__': sys.argv[0]})
        except Exception as e:  # pylint: disable=broad-except
            self.script_exec_failed = True
            logging.error(e)

            te = TracebackException.from_exception(e)
            # remove the first stack frame, which contains our exec() invocation
            del te.stack[0]

            # replace <string> with script path only for the first stack frames
            # in order to keep intact exec() invocations down the stack
            # that we're not concerned with
            for i, frame in enumerate(te.stack):
                if frame.filename == '<string>':
                    te.stack[i] = FrameSummary(str(self.script_path),
                                               frame.lineno, frame.name)
                else:
                    break
            print(''.join(te.format()))

            self.handle_script_error(
                f'''An error occured while evaluating script:
                \n{str(e)}
                \nSee console output for details.''')
            return
        finally:
            sys.argv = argv_orig
            sys.path.pop()

        self.script_exec_failed = False

        if len(vs.get_outputs()) == 0:
            logging.error('Script has no outputs set.')
            self.handle_script_error('Script has no outputs set.')
            return

        if not reloading:
            self.toolbars.main.rescan_outputs()
            for toolbar in self.toolbars:
                toolbar.on_script_loaded()
            self.switch_output(self.OUTPUT_INDEX)

            self.load_storage()
        else:
            self.load_storage()
            for toolbar in self.toolbars:
                toolbar.on_script_loaded()
Beispiel #11
0
 def _get_outputs(self):
     return vapoursynth.get_outputs()