Skip to content

props

CT module-attribute

CT = TypeVar('CT')

DT module-attribute

DT = TypeVar('DT')

get_prop module-attribute

get_prop = _get_prop()

get_clip_filepath

get_clip_filepath(
    clip: VideoNode,
    fallback: SPathLike | None = ...,
    strict: Literal[False] = ...,
    *,
    func: FuncExceptT | None = ...
) -> SPath | None
get_clip_filepath(
    clip: VideoNode,
    fallback: SPathLike | None = ...,
    strict: Literal[True] = ...,
    *,
    func: FuncExceptT | None = ...
) -> SPath
get_clip_filepath(
    clip: VideoNode,
    fallback: SPathLike | None = ...,
    strict: bool = ...,
    *,
    func: FuncExceptT | None = ...
) -> SPath | None
get_clip_filepath(
    clip: VideoNode,
    fallback: SPathLike | None = None,
    strict: bool = False,
    *,
    func: FuncExceptT | None = None
) -> SPath | None

Helper function to get the file path from a clip.

This functions checks for the IdxFilePath frame property. It also checks to ensure the file exists, and throws an error if it doesn't.

Parameters:

  • clip

    (VideoNode) –

    The clip to get the file path from.

  • fallback

    (SPathLike | None, default: None ) –

    Fallback file path to use if the prop is not found.

  • strict

    (bool, default: False ) –

    If True, will raise an error if the prop is not found. This makes it so the function will NEVER return False. Default: False.

  • func

    (FuncExceptT | None, default: None ) –

    Function returned for error handling. This should only be set by VS package developers.

Raises:

  • FileWasNotFoundError

    The file path was not found.

  • FramePropError

    The property was not found in the clip.

Source code
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
def get_clip_filepath(
    clip: vs.VideoNode, fallback: SPathLike | None = None, strict: bool = False, *, func: FuncExceptT | None = None
) -> SPath | None:
    """
    Helper function to get the file path from a clip.

    This functions checks for the `IdxFilePath` frame property.
    It also checks to ensure the file exists, and throws an error if it doesn't.

    :param clip:                    The clip to get the file path from.
    :param fallback:                Fallback file path to use if the `prop` is not found.
    :param strict:                  If True, will raise an error if the `prop` is not found.
                                    This makes it so the function will NEVER return False.
                                    Default: False.
    :param func:                    Function returned for error handling.
                                    This should only be set by VS package developers.

    :raises FileWasNotFoundError:   The file path was not found.
    :raises FramePropError:         The property was not found in the clip.
    """

    func = func or get_clip_filepath

    if fallback is not None and not (fallback_path := SPath(fallback)).exists() and strict:
        raise FileWasNotFoundError('Fallback file not found!', func, fallback_path.absolute())

    if not (path := get_prop(clip, 'IdxFilePath', str, default=MISSING if strict else False, func=func)):
        return fallback_path if fallback is not None else None

    if not (spath := SPath(str(path))).exists() and not fallback:
        raise FileWasNotFoundError('File not found!', func, spath.absolute())

    if spath.exists():
        return spath

    if fallback is not None and fallback_path.exists():
        return fallback_path

    raise FileWasNotFoundError('File not found!', func, spath.absolute())

merge_clip_props

merge_clip_props(*clips: VideoNode, main_idx: int = 0) -> VideoNode

Merge frame properties from all provided clips.

The props of the main clip (defined by main_idx) will be overwritten, and all other props will be added to it.

Parameters:

  • clips

    (VideoNode, default: () ) –

    Clips which will be merged.

  • main_idx

    (int, default: 0 ) –

    Index of the main clip to which all other clips props will be merged.

Returns:

  • VideoNode

    First clip with all the frameprops of every other given clip merged into it.

Source code
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
def merge_clip_props(*clips: vs.VideoNode, main_idx: int = 0) -> vs.VideoNode:
    """
    Merge frame properties from all provided clips.

    The props of the main clip (defined by main_idx) will be overwritten,
    and all other props will be added to it.

    :param clips:       Clips which will be merged.
    :param main_idx:    Index of the main clip to which all other clips props will be merged.

    :return:            First clip with all the frameprops of every other given clip merged into it.
    """

    if len(clips) == 1:
        return clips[0]

    def _merge_props(f: list[vs.VideoFrame], n: int) -> vs.VideoFrame:
        fdst = f[main_idx].copy()

        for i, frame in enumerate(f):
            if i == main_idx:
                continue

            fdst.props.update(frame.props)

        return fdst

    return clips[0].std.ModifyFrame(clips, _merge_props)