utils ¶
Classes:
-
DitherType–Enum for
zimg_dither_type_eand fmtcdmode.
Functions:
-
depth–A convenience bitdepth conversion function using only internal plugins if possible.
-
expect_bits–Expected output bitdepth for a clip.
-
flatten_vnodes–Flatten an array of VideoNodes.
-
frame2clip–Convert a VideoFrame to a VideoNode.
-
get_b–Extract the blue plane of the given clip.
-
get_g–Extract the green plane of the given clip.
-
get_r–Extract the red plane of the given clip.
-
get_u–Extract the first chroma (U) plane of the given clip.
-
get_v–Extract the second chroma (V) plane of the given clip.
-
get_y–Extract the luma (Y) plane of the given clip.
-
insert_clip–Replace frames of a longer clip with those of a shorter one.
-
join–General interface to combine clips or planes into a single clip.
-
limiter–Wraps vszip.Limiter
-
plane–Extract a plane from the given clip.
-
split–Split a clip into a list of individual planes.
-
stack_clips–Recursively stack clips in alternating directions: horizontal → vertical → horizontal → ...
-
stack_planes–Split a clip into its individual planes and stack them visually for inspection.
Attributes:
-
EXPR_VARS–Variables to access clips in Expr.
EXPR_VARS module-attribute ¶
EXPR_VARS = [
"x",
"y",
"z",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
]
Variables to access clips in Expr.
DitherType ¶
Bases: CustomStrEnum
Enum for zimg_dither_type_e and fmtc dmode.
Methods:
-
apply–Apply the given DitherType to a clip.
-
from_param–Return the enum value from a parameter.
-
is_fmtc–Whether the DitherType is exclusive to fmtc.
-
value–
Attributes:
-
ATKINSON–Another error diffusion kernel.
-
ERROR_DIFFUSION–Floyd-Steinberg error diffusion.
-
FLOYD_STEINBERG– -
NONE–Round to nearest.
-
ORDERED–Bayer patterned dither.
-
OSTROMOUKHOV–Another error diffusion kernel.
-
QUASIRANDOM–Dither using quasirandom sequences.
-
RANDOM–Pseudo-random noise of magnitude 0.5.
-
SIERRA_2_4A–Another type of error diffusion.
-
STUCKI–Another error diffusion kernel.
-
VOID–
ATKINSON class-attribute instance-attribute ¶
ATKINSON = ('atkinson', 5)
Another error diffusion kernel. Generates distinct patterns but keeps clean the flat areas (noise modulation).
ERROR_DIFFUSION class-attribute instance-attribute ¶
ERROR_DIFFUSION = ('error_diffusion', 6)
Floyd-Steinberg error diffusion.
OSTROMOUKHOV class-attribute instance-attribute ¶
OSTROMOUKHOV = ('ostromoukhov', 7)
Another error diffusion kernel. Slow, available only for integer input at the moment. Avoids usual F-S artifacts.
QUASIRANDOM class-attribute instance-attribute ¶
QUASIRANDOM = ('quasirandom', 9)
Dither using quasirandom sequences. Good intermediary between void, cluster, and error diffusion algorithms.
RANDOM class-attribute instance-attribute ¶
RANDOM = ('random', 8)
Pseudo-random noise of magnitude 0.5.
SIERRA_2_4A class-attribute instance-attribute ¶
SIERRA_2_4A = ('sierra_2_4a', 3)
Another type of error diffusion. Quick and excellent quality, similar to Floyd-Steinberg.
STUCKI class-attribute instance-attribute ¶
STUCKI = ('stucki', 4)
Another error diffusion kernel. Preserves delicate edges better but distorts gradients.
apply ¶
apply(
clip: VideoNode,
out_fmt: VideoFormat,
range_in: RangeLike | None,
range_out: RangeLike | None,
force_fmtc: bool,
) -> VideoNode
Apply the given DitherType to a clip.
Source code in vstools/functions/utils.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
from_param classmethod ¶
from_param(value: Any, func_except: FuncExcept | None = None) -> Self
Return the enum value from a parameter.
Parameters:
-
(value¶Any) –Value to instantiate the enum class.
-
(func_except¶FuncExcept | None, default:None) –Exception function.
Returns:
-
Self–Enum value.
Raises:
-
NotFoundEnumValue–Variable not found in the given enum.
Source code in jetpytools/enums/base.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
is_fmtc ¶
is_fmtc() -> bool
Whether the DitherType is exclusive to fmtc.
Source code in vstools/functions/utils.py
181 182 183 184 185 186 187 188 189 190 191 192 | |
depth ¶
depth(
clip: VideoNode,
bitdepth: VideoFormatLike | HoldsVideoFormat | int | None = None,
/,
sample_type: int | SampleType | None = None,
*,
range_in: RangeLike | None = None,
range_out: RangeLike | None = None,
dither_type: str | DitherType = RANDOM,
force_fmtc: bool = False,
) -> VideoNode
A convenience bitdepth conversion function using only internal plugins if possible.
This uses exclusively internal plugins except for specific dither_types.
Example
rc_8 = vs.core.std.BlankClip(format=vs.YUV420P8)
rc_10 = depth(src_8, 10)
print(rc_10.format.name) # YUV420P10
rc2_10 = vs.core.std.BlankClip(format=vs.RGB30)
rc2_8 = depth(src2_10, 8, dither_type=Dither.RANDOM) # override default dither behavior
print(rc2_8.format.name) # RGB24
Parameters:
-
(clip¶VideoNode) –Input clip.
-
(bitdepth¶VideoFormatLike | HoldsVideoFormat | int | None, default:None) –Desired bitdepth of the output clip.
-
(sample_type¶int | SampleType | None, default:None) –Desired sample type of output clip. Allows overriding default float/integer behavior.
-
(range_in¶RangeLike | None, default:None) –Input pixel range (defaults to input
clip's range). -
(range_out¶RangeLike | None, default:None) –Output pixel range (defaults to input
clip's range). -
(dither_type¶str | DitherType, default:RANDOM) –Dithering algorithm. Allows overriding default dithering behavior.
-
(force_fmtc¶bool, default:False) –Force usage of fmtc to apply dithering.
Returns:
-
VideoNode–Converted clip with desired bit depth and sample type.
ColorFamilywill be same as input.
Source code in vstools/functions/utils.py
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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
expect_bits ¶
Expected output bitdepth for a clip.
This function is meant to be used when a clip may not match the expected input bitdepth. Both the dithered clip and the original bitdepth are returned.
Parameters:
-
(clip¶VideoNode) –Input clip.
-
(expected_depth¶int, default:16) –Expected bitdepth. Default: 16.
Returns:
-
tuple[VideoNode, int]–Tuple containing the clip dithered to the expected depth and the original bitdepth.
Source code in vstools/functions/utils.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
flatten_vnodes ¶
flatten_vnodes(
*clips: VideoNodeIterable, split_planes: bool = False
) -> Sequence[VideoNode]
Flatten an array of VideoNodes.
Parameters:
-
(*clips¶VideoNodeIterable, default:()) –An array of clips to flatten into a list.
-
(split_planes¶bool, default:False) –Optionally split the VideoNodes into their individual planes as well. Default: False.
Returns:
-
Sequence[VideoNode]–Flattened list of VideoNodes.
Source code in vstools/functions/utils.py
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
frame2clip ¶
frame2clip(frame: VideoFrame) -> VideoNode
Convert a VideoFrame to a VideoNode.
Parameters:
-
(frame¶VideoFrame) –Input frame.
Returns:
-
VideoNode–1-frame long VideoNode of the input frame.
Source code in vstools/functions/utils.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
get_b ¶
get_b(clip: VideoNode) -> VideoNode
Extract the blue plane of the given clip.
Parameters:
-
(clip¶VideoNode) –Input clip.
Returns:
-
VideoNode–B plane of the input clip.
Raises:
-
UnsupportedColorFamilyError–Clip is not RGB.
Source code in vstools/functions/utils.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
get_g ¶
get_g(clip: VideoNode) -> VideoNode
Extract the green plane of the given clip.
Parameters:
-
(clip¶VideoNode) –Input clip.
Returns:
-
VideoNode–G plane of the input clip.
Raises:
-
UnsupportedColorFamilyError–Clip is not RGB.
Source code in vstools/functions/utils.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
get_r ¶
get_r(clip: VideoNode) -> VideoNode
Extract the red plane of the given clip.
Parameters:
-
(clip¶VideoNode) –Input clip.
Returns:
-
VideoNode–R plane of the input clip.
Raises:
-
UnsupportedColorFamilyError–Clip is not RGB.
Source code in vstools/functions/utils.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
get_u ¶
get_u(clip: VideoNode) -> VideoNode
Extract the first chroma (U) plane of the given clip.
Parameters:
-
(clip¶VideoNode) –Input clip.
Returns:
-
VideoNode–Y plane of the input clip.
Raises:
-
UnsupportedColorFamilyError–Clip is not YUV.
Source code in vstools/functions/utils.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
get_v ¶
get_v(clip: VideoNode) -> VideoNode
Extract the second chroma (V) plane of the given clip.
Parameters:
-
(clip¶VideoNode) –Input clip.
Returns:
-
VideoNode–V plane of the input clip.
Raises:
-
UnsupportedColorFamilyError–Clip is not YUV.
Source code in vstools/functions/utils.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
get_y ¶
get_y(clip: VideoNode) -> VideoNode
Extract the luma (Y) plane of the given clip.
Parameters:
-
(clip¶VideoNode) –Input clip.
Returns:
-
VideoNode–Y plane of the input clip.
Raises:
-
UnsupportedColorFamilyError–Clip is not GRAY or YUV.
Source code in vstools/functions/utils.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
insert_clip ¶
insert_clip(
clip: VideoNode, /, insert: VideoNode, start_frame: int, strict: bool = True
) -> VideoNode
Replace frames of a longer clip with those of a shorter one.
The insert clip may NOT exceed the final frame of the input clip. This limitation can be circumvented by setting strict=False.
Parameters:
-
(clip¶VideoNode) –Input clip.
-
(insert¶VideoNode) –Clip to insert into the input clip.
-
(start_frame¶int) –Frame to start inserting from.
-
(strict¶bool, default:True) –Throw an error if the inserted clip exceeds the final frame of the input clip. If False, truncate the inserted clip instead. Default: True.
Returns:
-
VideoNode–Clip with frames replaced by the insert clip.
Raises:
-
CustomValueError–Insert clip is too long,
strict=False, and exceeds the final frame of the input clip.
Source code in vstools/functions/utils.py
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 | |
join ¶
join(
luma: VideoNode,
chroma: VideoNode,
/,
*,
prop_src: VideoNode | SupportsIndex | None = ...,
) -> VideoNode
join(
plane0: VideoNode,
plane1: VideoNode,
plane2: VideoNode,
alpha: VideoNode | None = None,
/,
*,
family: ColorFamily = YUV,
prop_src: VideoNode | SupportsIndex | None = ...,
) -> VideoNode
join(
planes: Sequence[VideoNode],
family: ColorFamily = YUV,
/,
*,
prop_src: VideoNode | SupportsIndex | None = ...,
) -> VideoNode
join(
clips: VideoNode | Sequence[VideoNode] | Mapping[Planes, VideoNode | None],
plane1_or_family: VideoNode | ColorFamily | None = None,
plane2: VideoNode | None = None,
alpha: VideoNode | None = None,
/,
*,
family: ColorFamily = YUV,
prop_src: VideoNode | SupportsIndex | None = None,
) -> VideoNode
General interface to combine clips or planes into a single clip.
Parameters:
-
(clips¶VideoNode | Sequence[VideoNode] | Mapping[Planes, VideoNode | None]) –First plane, sequence of single-plane clips or mapping of planes to clips:
-
(plane1_or_family¶VideoNode | ColorFamily | None, default:None) –Chroma clip, second plane or color family, depending on usage.
-
(plane2¶VideoNode | None, default:None) –Third plane when combining three planes.
-
(alpha¶VideoNode | None, default:None) –Optional alpha clip.
-
(family¶ColorFamily, default:YUV) –Output color family. Defaults to YUV.
-
(prop_src¶VideoNode | SupportsIndex | None, default:None) –Optional clip or index to copy frame properties from.
Raises:
-
CustomIndexError–Invalid plane index.
-
CustomTypeError–Invalid input type.
Returns:
-
VideoNode–Clip with combined planes.
Source code in vstools/functions/utils.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
limiter ¶
limiter(
clip: VideoNode,
/,
min_val: float | Sequence[float] | None = None,
max_val: float | Sequence[float] | None = None,
*,
tv_range: bool = False,
mask: bool = False,
planes: Planes = None,
func: FuncExcept | None = None,
) -> VideoNode
limiter(
clip_or_func: VideoNode | Callable[P, VideoNode] | None = None,
/,
min_val: float | Sequence[float] | None = None,
max_val: float | Sequence[float] | None = None,
*,
tv_range: bool = False,
mask: bool = False,
planes: Planes = None,
func: FuncExcept | None = None,
) -> (
VideoNode
| Callable[P, VideoNode]
| Callable[[Callable[P, VideoNode]], Callable[P, VideoNode]]
)
Wraps vszip.Limiter but only processes if clip format is not integer, a min/max val is specified or tv_range is True.
Parameters:
-
(clip_or_func¶VideoNode | Callable[P, VideoNode] | None, default:None) –Clip to process or function that returns a VideoNode to be processed.
-
(min_val¶float | Sequence[float] | None, default:None) –Lower bound. Defaults to the lowest allowed value for the input. Can be specified for each plane individually.
-
(max_val¶float | Sequence[float] | None, default:None) –Upper bound. Defaults to the highest allowed value for the input. Can be specified for each plane individually.
-
(tv_range¶bool, default:False) –Changes min/max defaults values to LIMITED.
-
(mask¶bool, default:False) –Float chroma range from -0.5/0.5 to 0.0/1.0.
-
(planes¶Planes, default:None) –Which planes to process.
-
(func¶FuncExcept | None, default:None) –Function returned for custom error handling. This should only be set by VS package developers.
Returns:
-
VideoNode | Callable[P, VideoNode] | Callable[[Callable[P, VideoNode]], Callable[P, VideoNode]]–Clamped clip.
Source code in vstools/functions/utils.py
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 | |
plane ¶
plane(
clip: VideoNode, index: SupportsIndex, /, strict: bool = True
) -> VideoNode
Extract a plane from the given clip.
Parameters:
-
(clip¶VideoNode) –Input clip.
-
(index¶SupportsIndex) –Index of the plane to extract.
-
(strict¶bool, default:True) –If False, removes
_Matrixproperty when the input clip is RGB.
Returns:
-
VideoNode–Grayscale clip of the clip's plane.
Source code in vstools/functions/utils.py
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | |
split ¶
Split a clip into a list of individual planes.
Parameters:
-
(clip¶VideoNode) –Input clip.
-
(strict¶bool, default:True) –If False, removes
_Matrixproperty when the input clip is RGB.
Returns:
-
list[VideoNode]–List of individual planes.
Source code in vstools/functions/utils.py
645 646 647 648 649 650 651 652 653 654 655 656 | |
stack_clips ¶
stack_clips(clips: Iterable[VideoNodeIterable]) -> VideoNode
Recursively stack clips in alternating directions: horizontal → vertical → horizontal → ...
This function takes a nested sequence of clips (or lists of clips) and stacks them alternately along the horizontal and vertical axes at each nesting level.
Examples:
-
Stack a list of clips horizontally:
from vstools import core, split, vs clip = core.std.BlankClip(format=vs.RGB24) clips = split(clip) stacked = stack_clips(clips) -
Stack a list of clips vertically (wrap in another list):
from vstools import core, split, vs clip = core.std.BlankClip(format=vs.RGB24) clips = split(clip) stacked = stack_clips([clips]) -
Stack the Y plane horizontally with the U and V planes stacked vertically:
from vstools import core, split, vs clip = core.std.BlankClip(format=vs.YUV420P8) y, u, v = split(clip) stacked = stack_clips([y, [u, v]]) -
Stack multiple YUV clips, with Y planes horizontally and UV planes vertically:
from vstools import core, split, vs yuv_clips = [...] # all must share format and height clips = [] for yuv_clip in yuv_clips: y, *uv = split(yuv_clip) clips.extend([y, uv]) stacked = stack_clips(clips) -
Using
appendinstead ofextend(and wrapping the sequence, e.g.stack_clips([clips])) changes the stacking layout, since it alters the nesting depth.
Parameters:
-
(clips¶Iterable[VideoNodeIterable]) –A (possibly nested) sequence of clips to be stacked.
Returns:
-
VideoNode–Stacked clips.
Source code in vstools/functions/utils.py
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
stack_planes ¶
stack_planes(
clip: VideoNode,
shift_float_chroma: bool = True,
offset_chroma: Literal["min", "max", False] | float = False,
mode: Literal["h", "v"] = "h",
write_plane_name: Literal[False] = False,
) -> VideoNode
stack_planes(
clip: VideoNode,
shift_float_chroma: bool = True,
offset_chroma: Literal["min", "max", False] | float = False,
mode: Literal["h", "v"] = "h",
write_plane_name: bool = ...,
alignment: int = 7,
scale: int = 1,
) -> VideoNode
stack_planes(
clip: VideoNode,
shift_float_chroma: bool = True,
offset_chroma: Literal["min", "max", False] | float = False,
mode: Literal["h", "v"] = "h",
write_plane_name: bool = False,
alignment: int = 7,
scale: int = 1,
) -> VideoNode
Split a clip into its individual planes and stack them visually for inspection.
Parameters:
-
(clip¶VideoNode) –Input clip to be split and visually stacked.
-
(shift_float_chroma¶bool, default:True) –If True, shift U and V by +0.5 when working in float YUV formats.
-
(offset_chroma¶Literal['min', 'max', False] | float, default:False) –Apply chroma plane offseting:
- "min": match luma minimum
- "max": match luma maximum
- float: add value directly
- False: no chroma offseting
-
(mode¶Literal['h', 'v'], default:'h') –Stacking direction:
- "h": horizontal (default)
- "v": vertical
-
(write_plane_name¶bool, default:False) –If True, overlays the short plane name ("Y", "U", "V", "R", "G", ...) on each plane.
-
(alignment¶int, default:7) –Text alignment for plane labels (only used if
write_plane_name=True). -
(scale¶int, default:1) –Font scale for plane labels (only used if
write_plane_name=True).
Returns:
-
VideoNode–A clip containing the stacked planes.
Source code in vstools/functions/utils.py
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 | |