clips ¶
Classes:
-
ProcessVariableClip–A helper class for processing variable format/resolution clip.
-
ProcessVariableFormatClip–A helper class for processing variable format clip.
-
ProcessVariableResClip–A helper class for processing variable resolution clip.
-
ProcessVariableResFormatClip–A helper class for processing variable format and resolution clip.
Functions:
-
finalize_clip–Finalize a clip for output to the encoder.
-
finalize_output–Decorator implementation of finalize_clip.
-
initialize_clip–Initialize a clip with core frame properties and convert its bit depth.
-
initialize_input–Decorator implementation of initialize_clip.
-
sc_detect–Detects scene changes in a video clip based on frame difference statistics.
-
shift_clip–Shift a clip forwards or backwards by N frames.
-
shift_clip_multi–Shift a clip forwards or backwards multiple times by a varying amount of frames.
ProcessVariableClip ¶
ProcessVariableClip(
clip: VideoNode,
out_dim: tuple[int, int] | Literal[False] | None = None,
out_fmt: SupportsInt | Literal[False] | None = None,
cache_size: int = 10,
)
Bases: DynamicClipsCache[T]
A helper class for processing variable format/resolution clip.
Initializes the class.
Parameters:
-
(clip¶VideoNode) –Clip to process
-
(out_dim¶tuple[int, int] | Literal[False] | None, default:None) –Output dimension.
-
(out_fmt¶SupportsInt | Literal[False] | None, default:None) –Output format.
-
(cache_size¶int, default:10) –The maximum number of items allowed in the cache. Defaults to 10.
Methods:
-
eval_clip– -
from_clip–Process a variable format/resolution clip.
-
from_func–Process a variable format/resolution clip with a given function
-
get_clip– -
get_key–Generate a unique key based on the node or frame.
-
normalize–Normalize the given node to the format/resolution specified by the unique key
cast_to. -
process–Process the given clip.
Attributes:
-
cache_size– -
clip– -
out–
Source code in vstools/functions/clips.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
eval_clip ¶
eval_clip() -> VideoNode
Source code in vstools/functions/clips.py
95 96 97 98 99 100 101 102 | |
from_clip classmethod ¶
from_clip(clip: VideoNode) -> VideoNode
Process a variable format/resolution clip.
Parameters:
-
(clip¶VideoNode) –Clip to process.
Returns:
-
VideoNode–Processed clip.
Source code in vstools/functions/clips.py
107 108 109 110 111 112 113 114 115 116 117 118 | |
from_func classmethod ¶
from_func(
clip: VideoNode,
func: Callable[[VideoNode], VideoNode],
out_dim: tuple[int, int] | Literal[False] | None = None,
out_fmt: int | VideoFormat | Literal[False] | None = None,
cache_size: int = 10,
) -> VideoNode
Process a variable format/resolution clip with a given function
Parameters:
-
(clip¶VideoNode) –Clip to process.
-
(func¶Callable[[VideoNode], VideoNode]) –Function that takes and returns a single VideoNode.
-
(out_dim¶tuple[int, int] | Literal[False] | None, default:None) –Output dimension.
-
(out_fmt¶int | VideoFormat | Literal[False] | None, default:None) –Output format.
-
(cache_size¶int, default:10) –The maximum number of VideoNode allowed in the cache. Defaults to 10.
Returns:
-
VideoNode–Processed variable clip.
Source code in vstools/functions/clips.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
get_clip ¶
get_clip(key: T) -> VideoNode
Source code in vstools/functions/clips.py
104 105 | |
get_key abstractmethod ¶
get_key(frame: VideoNode | VideoFrame) -> T
Generate a unique key based on the node or frame. This key will be used to temporarily assert a resolution and format for the clip to process.
Parameters:
-
(frame¶VideoNode | VideoFrame) –Node or frame from which the unique key is generated.
Returns:
-
T–Unique identifier.
Source code in vstools/functions/clips.py
151 152 153 154 155 156 157 158 159 160 161 162 | |
normalize abstractmethod ¶
Normalize the given node to the format/resolution specified by the unique key cast_to.
Parameters:
-
(clip¶VideoNode) –Clip to normalize.
-
(cast_to¶T) –The target resolution or format to which the clip should be cast or normalized.
Returns:
-
VideoNode–Normalized clip.
Source code in vstools/functions/clips.py
164 165 166 167 168 169 170 171 172 173 174 175 | |
process ¶
process(clip: VideoNode) -> VideoNode
Process the given clip.
Parameters:
-
(clip¶VideoNode) –Clip to process.
Returns:
-
VideoNode–Processed clip.
Source code in vstools/functions/clips.py
177 178 179 180 181 182 183 184 185 186 187 | |
ProcessVariableFormatClip ¶
ProcessVariableFormatClip(
clip: VideoNode,
out_dim: tuple[int, int] | Literal[False] | None = None,
out_fmt: SupportsInt | Literal[False] | None = None,
cache_size: int = 10,
)
Bases: ProcessVariableClip[VideoFormat]
A helper class for processing variable format clip.
Initializes the class.
Parameters:
-
(clip¶VideoNode) –Clip to process
-
(out_dim¶tuple[int, int] | Literal[False] | None, default:None) –Output dimension.
-
(out_fmt¶SupportsInt | Literal[False] | None, default:None) –Output format.
-
(cache_size¶int, default:10) –The maximum number of items allowed in the cache. Defaults to 10.
Methods:
-
eval_clip– -
from_clip–Process a variable format/resolution clip.
-
from_func–Process a variable format/resolution clip with a given function
-
get_clip– -
get_key–Generate a unique key based on the node or frame.
-
normalize–Normalize the given node to the format/resolution specified by the unique key
cast_to. -
process–Process the given clip.
Attributes:
-
cache_size– -
clip– -
out–
Source code in vstools/functions/clips.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
eval_clip ¶
eval_clip() -> VideoNode
Source code in vstools/functions/clips.py
95 96 97 98 99 100 101 102 | |
from_clip classmethod ¶
from_clip(clip: VideoNode) -> VideoNode
Process a variable format/resolution clip.
Parameters:
-
(clip¶VideoNode) –Clip to process.
Returns:
-
VideoNode–Processed clip.
Source code in vstools/functions/clips.py
107 108 109 110 111 112 113 114 115 116 117 118 | |
from_func classmethod ¶
from_func(
clip: VideoNode,
func: Callable[[VideoNode], VideoNode],
out_dim: tuple[int, int] | Literal[False] | None = None,
out_fmt: int | VideoFormat | Literal[False] | None = None,
cache_size: int = 10,
) -> VideoNode
Process a variable format/resolution clip with a given function
Parameters:
-
(clip¶VideoNode) –Clip to process.
-
(func¶Callable[[VideoNode], VideoNode]) –Function that takes and returns a single VideoNode.
-
(out_dim¶tuple[int, int] | Literal[False] | None, default:None) –Output dimension.
-
(out_fmt¶int | VideoFormat | Literal[False] | None, default:None) –Output format.
-
(cache_size¶int, default:10) –The maximum number of VideoNode allowed in the cache. Defaults to 10.
Returns:
-
VideoNode–Processed variable clip.
Source code in vstools/functions/clips.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
get_clip ¶
get_clip(key: T) -> VideoNode
Source code in vstools/functions/clips.py
104 105 | |
get_key ¶
get_key(frame: VideoNode | VideoFrame) -> VideoFormat
Generate a unique key based on the node or frame. This key will be used to temporarily assert a resolution and format for the clip to process.
Parameters:
-
(frame¶VideoNode | VideoFrame) –Node or frame from which the unique key is generated.
Returns:
-
T–Unique identifier.
Source code in vstools/functions/clips.py
208 209 210 | |
normalize ¶
Normalize the given node to the format/resolution specified by the unique key cast_to.
Parameters:
-
(clip¶VideoNode) –Clip to normalize.
-
(cast_to¶T) –The target resolution or format to which the clip should be cast or normalized.
Returns:
-
VideoNode–Normalized clip.
Source code in vstools/functions/clips.py
212 213 214 | |
process ¶
process(clip: VideoNode) -> VideoNode
Process the given clip.
Parameters:
-
(clip¶VideoNode) –Clip to process.
Returns:
-
VideoNode–Processed clip.
Source code in vstools/functions/clips.py
177 178 179 180 181 182 183 184 185 186 187 | |
ProcessVariableResClip ¶
ProcessVariableResClip(
clip: VideoNode,
out_dim: tuple[int, int] | Literal[False] | None = None,
out_fmt: SupportsInt | Literal[False] | None = None,
cache_size: int = 10,
)
Bases: ProcessVariableClip[tuple[int, int]]
A helper class for processing variable resolution clip.
Initializes the class.
Parameters:
-
(clip¶VideoNode) –Clip to process
-
(out_dim¶tuple[int, int] | Literal[False] | None, default:None) –Output dimension.
-
(out_fmt¶SupportsInt | Literal[False] | None, default:None) –Output format.
-
(cache_size¶int, default:10) –The maximum number of items allowed in the cache. Defaults to 10.
Methods:
-
eval_clip– -
from_clip–Process a variable format/resolution clip.
-
from_func–Process a variable format/resolution clip with a given function
-
get_clip– -
get_key–Generate a unique key based on the node or frame.
-
normalize–Normalize the given node to the format/resolution specified by the unique key
cast_to. -
process–Process the given clip.
Attributes:
-
cache_size– -
clip– -
out–
Source code in vstools/functions/clips.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
eval_clip ¶
eval_clip() -> VideoNode
Source code in vstools/functions/clips.py
95 96 97 98 99 100 101 102 | |
from_clip classmethod ¶
from_clip(clip: VideoNode) -> VideoNode
Process a variable format/resolution clip.
Parameters:
-
(clip¶VideoNode) –Clip to process.
Returns:
-
VideoNode–Processed clip.
Source code in vstools/functions/clips.py
107 108 109 110 111 112 113 114 115 116 117 118 | |
from_func classmethod ¶
from_func(
clip: VideoNode,
func: Callable[[VideoNode], VideoNode],
out_dim: tuple[int, int] | Literal[False] | None = None,
out_fmt: int | VideoFormat | Literal[False] | None = None,
cache_size: int = 10,
) -> VideoNode
Process a variable format/resolution clip with a given function
Parameters:
-
(clip¶VideoNode) –Clip to process.
-
(func¶Callable[[VideoNode], VideoNode]) –Function that takes and returns a single VideoNode.
-
(out_dim¶tuple[int, int] | Literal[False] | None, default:None) –Output dimension.
-
(out_fmt¶int | VideoFormat | Literal[False] | None, default:None) –Output format.
-
(cache_size¶int, default:10) –The maximum number of VideoNode allowed in the cache. Defaults to 10.
Returns:
-
VideoNode–Processed variable clip.
Source code in vstools/functions/clips.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
get_clip ¶
get_clip(key: T) -> VideoNode
Source code in vstools/functions/clips.py
104 105 | |
get_key ¶
Generate a unique key based on the node or frame. This key will be used to temporarily assert a resolution and format for the clip to process.
Parameters:
-
(frame¶VideoNode | VideoFrame) –Node or frame from which the unique key is generated.
Returns:
-
T–Unique identifier.
Source code in vstools/functions/clips.py
195 196 | |
normalize ¶
Normalize the given node to the format/resolution specified by the unique key cast_to.
Parameters:
-
(clip¶VideoNode) –Clip to normalize.
-
(cast_to¶T) –The target resolution or format to which the clip should be cast or normalized.
Returns:
-
VideoNode–Normalized clip.
Source code in vstools/functions/clips.py
198 199 200 | |
process ¶
process(clip: VideoNode) -> VideoNode
Process the given clip.
Parameters:
-
(clip¶VideoNode) –Clip to process.
Returns:
-
VideoNode–Processed clip.
Source code in vstools/functions/clips.py
177 178 179 180 181 182 183 184 185 186 187 | |
ProcessVariableResFormatClip ¶
ProcessVariableResFormatClip(
clip: VideoNode,
out_dim: tuple[int, int] | Literal[False] | None = None,
out_fmt: SupportsInt | Literal[False] | None = None,
cache_size: int = 10,
)
Bases: ProcessVariableClip[tuple[int, int, VideoFormat]]
A helper class for processing variable format and resolution clip.
Initializes the class.
Parameters:
-
(clip¶VideoNode) –Clip to process
-
(out_dim¶tuple[int, int] | Literal[False] | None, default:None) –Output dimension.
-
(out_fmt¶SupportsInt | Literal[False] | None, default:None) –Output format.
-
(cache_size¶int, default:10) –The maximum number of items allowed in the cache. Defaults to 10.
Methods:
-
eval_clip– -
from_clip–Process a variable format/resolution clip.
-
from_func–Process a variable format/resolution clip with a given function
-
get_clip– -
get_key–Generate a unique key based on the node or frame.
-
normalize–Normalize the given node to the format/resolution specified by the unique key
cast_to. -
process–Process the given clip.
Attributes:
-
cache_size– -
clip– -
out–
Source code in vstools/functions/clips.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
eval_clip ¶
eval_clip() -> VideoNode
Source code in vstools/functions/clips.py
95 96 97 98 99 100 101 102 | |
from_clip classmethod ¶
from_clip(clip: VideoNode) -> VideoNode
Process a variable format/resolution clip.
Parameters:
-
(clip¶VideoNode) –Clip to process.
Returns:
-
VideoNode–Processed clip.
Source code in vstools/functions/clips.py
107 108 109 110 111 112 113 114 115 116 117 118 | |
from_func classmethod ¶
from_func(
clip: VideoNode,
func: Callable[[VideoNode], VideoNode],
out_dim: tuple[int, int] | Literal[False] | None = None,
out_fmt: int | VideoFormat | Literal[False] | None = None,
cache_size: int = 10,
) -> VideoNode
Process a variable format/resolution clip with a given function
Parameters:
-
(clip¶VideoNode) –Clip to process.
-
(func¶Callable[[VideoNode], VideoNode]) –Function that takes and returns a single VideoNode.
-
(out_dim¶tuple[int, int] | Literal[False] | None, default:None) –Output dimension.
-
(out_fmt¶int | VideoFormat | Literal[False] | None, default:None) –Output format.
-
(cache_size¶int, default:10) –The maximum number of VideoNode allowed in the cache. Defaults to 10.
Returns:
-
VideoNode–Processed variable clip.
Source code in vstools/functions/clips.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
get_clip ¶
get_clip(key: T) -> VideoNode
Source code in vstools/functions/clips.py
104 105 | |
get_key ¶
Generate a unique key based on the node or frame. This key will be used to temporarily assert a resolution and format for the clip to process.
Parameters:
-
(frame¶VideoNode | VideoFrame) –Node or frame from which the unique key is generated.
Returns:
-
T–Unique identifier.
Source code in vstools/functions/clips.py
222 223 224 | |
normalize ¶
Normalize the given node to the format/resolution specified by the unique key cast_to.
Parameters:
-
(clip¶VideoNode) –Clip to normalize.
-
(cast_to¶T) –The target resolution or format to which the clip should be cast or normalized.
Returns:
-
VideoNode–Normalized clip.
Source code in vstools/functions/clips.py
226 227 228 229 230 231 | |
process ¶
process(clip: VideoNode) -> VideoNode
Process the given clip.
Parameters:
-
(clip¶VideoNode) –Clip to process.
Returns:
-
VideoNode–Processed clip.
Source code in vstools/functions/clips.py
177 178 179 180 181 182 183 184 185 186 187 | |
finalize_clip ¶
finalize_clip(
clip: VideoNode,
bits: VideoFormatLike | HoldsVideoFormat | int | None = 10,
clamp_tv_range: bool = False,
*,
func: FuncExcept | None = None,
**kwargs: Any,
) -> VideoNode
Finalize a clip for output to the encoder.
Parameters:
-
(clip¶VideoNode) –Clip to output.
-
(bits¶VideoFormatLike | HoldsVideoFormat | int | None, default:10) –Bitdepth to output to.
-
(clamp_tv_range¶bool, default:False) –Whether to clamp to tv range.
-
(func¶FuncExcept | None, default:None) –Function returned for custom error handling. This should only be set by VS package developers.
-
(**kwargs¶Any, default:{}) –Additional arguments passed to [depth][vstools.utils.depth].
Returns:
-
VideoNode–Converted and optionally clamped clip.
Source code in vstools/functions/clips.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
finalize_output ¶
finalize_output(
function: Callable[P, VideoNode] | None = None,
/,
*,
bits: int | None = 10,
clamp_tv_range: bool = False,
func: FuncExcept | None = None,
**kwargs: Any,
) -> (
Callable[P, VideoNode]
| Callable[[Callable[P, VideoNode]], Callable[P, VideoNode]]
)
Decorator implementation of finalize_clip.
Source code in vstools/functions/clips.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
initialize_clip ¶
initialize_clip(
clip: VideoNode,
bits: int | None = 32,
matrix: MatrixLike | None = None,
transfer: TransferLike | None = None,
primaries: PrimariesLike | None = None,
chroma_location: ChromaLocationLike | None = None,
color_range: RangeLike | None = None,
field_based: FieldBasedLike | None = None,
strict: Never = cast(Never, MISSING),
*,
func: FuncExcept | None = None,
**kwargs: Any,
) -> VideoNode
Initialize a clip with core frame properties and convert its bit depth.
This function ensures that key video metadata properties are explicitly set on the clip's frame properties.
If any property is not explicitly provided, it will be resolved by: 1. Checking the clip's existing frame properties. 2. Failing that, applying heuristics based on the clip's resolution and format.
It is HIGHLY recommended to always use this function at the beginning of your scripts!
Parameters:
-
(clip¶VideoNode) –The input clip to initialize.
-
(bits¶int | None, default:32) –The target bit depth to convert the clip to. If set to
None, no bit depth conversion will be performed. Defaults to 32. -
(matrix¶MatrixLike | None, default:None) –The color matrix of the clip. If
None, it is inferred. -
(transfer¶TransferLike | None, default:None) –The transfer characteristics. If
None, it is inferred. -
(primaries¶PrimariesLike | None, default:None) –The color primaries. If
None, it is inferred. -
(chroma_location¶ChromaLocationLike | None, default:None) –The chroma sample location. If
None, it is inferred. -
(color_range¶RangeLike | None, default:None) –The color range. If
None, it is inferred. -
(field_based¶FieldBasedLike | None, default:None) –The field order type. If
None, it is inferred. -
(func¶FuncExcept | None, default:None) –Function returned for custom error handling
-
(**kwargs¶Any, default:{}) –Additional keyword arguments forwarded to [depth][vstools.utils.depth]
Returns:
-
VideoNode–The initialized clip with all essential frame properties set and converted to the target bit depth.
Source code in vstools/functions/clips.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
initialize_input ¶
initialize_input(
function: Callable[P, VideoNode],
/,
*,
bits: int | None = 32,
matrix: MatrixLike | None = None,
transfer: TransferLike | None = None,
primaries: PrimariesLike | None = None,
chroma_location: ChromaLocationLike | None = None,
color_range: RangeLike | None = None,
field_based: FieldBasedLike | None = None,
func: FuncExcept | None = None,
**kwargs: Any,
) -> Callable[P, VideoNode]
initialize_input(
*,
bits: int | None = 32,
matrix: MatrixLike | None = None,
transfer: TransferLike | None = None,
primaries: PrimariesLike | None = None,
chroma_location: ChromaLocationLike | None = None,
color_range: RangeLike | None = None,
field_based: FieldBasedLike | None = None,
func: FuncExcept | None = None,
**kwargs: Any,
) -> Callable[[Callable[P, VideoNode]], Callable[P, VideoNode]]
initialize_input(
function: Callable[P, VideoNode] | None = None,
/,
*,
bits: int | None = 32,
matrix: MatrixLike | None = None,
transfer: TransferLike | None = None,
primaries: PrimariesLike | None = None,
chroma_location: ChromaLocationLike | None = None,
color_range: RangeLike | None = None,
field_based: FieldBasedLike | None = None,
strict: Never = cast(Never, MISSING),
func: FuncExcept | None = None,
**kwargs: Any,
) -> (
Callable[P, VideoNode]
| Callable[[Callable[P, VideoNode]], Callable[P, VideoNode]]
)
Decorator implementation of initialize_clip.
Initializes the first clip found in this order: positional arguments -> keyword arguments -> default arguments.
Source code in vstools/functions/clips.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
sc_detect ¶
Detects scene changes in a video clip based on frame difference statistics.
Parameters:
-
(clip¶VideoNode) –The input clip.
-
(threshold¶float, default:0.1) –Sensitivity for scene change detection. Higher values make detection less sensitive. Default is 0.1.
Returns:
-
VideoNode–vs.VideoNode: A clip with scene change props (
_SceneChangePrevand_SceneChangeNext) set for each frame.
Source code in vstools/functions/clips.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
shift_clip ¶
Shift a clip forwards or backwards by N frames.
This is useful for cases where you must compare every frame of a clip with the frame that comes before or after the current frame, like for example when performing temporal operations.
Both positive and negative integers are allowed. Positive values will shift a clip forward, negative will shift a clip backward.
Parameters:
-
(clip¶VideoNode) –Input clip.
-
(offset¶int) –Number of frames to offset the clip with. Negative values are allowed. Positive values will shift a clip forward, negative will shift a clip backward.
Returns:
-
VideoNode–Clip that has been shifted forwards or backwards by N frames.
Source code in vstools/functions/clips.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
shift_clip_multi ¶
shift_clip_multi(
clip: VideoNode, offsets: StrictRange = (-1, 1)
) -> list[VideoNode]
Shift a clip forwards or backwards multiple times by a varying amount of frames.
This will return a clip for every shifting operation performed. This is a convenience function that makes handling multiple shifts easier.
Example:
>>> shift_clip_multi(clip, (-3, 3))
[VideoNode, VideoNode, VideoNode, VideoNode, VideoNode, VideoNode, VideoNode]
-3 -2 -1 0 +1 +2 +3
Parameters:
-
(clip¶VideoNode) –Input clip.
-
(offsets¶StrictRange, default:(-1, 1)) –Tuple of offsets representing an inclusive range. A clip will be returned for every offset. Default: (-1, 1).
Returns:
-
list[VideoNode]–A list of clips, the amount determined by the amount of offsets.
Source code in vstools/functions/clips.py
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |