utils ¶
Classes:
-
DitherType
–Enum for
zimg_dither_type_e
and fmtcdmode
.
Functions:
-
depth
–A convenience bitdepth conversion function using only internal plugins if possible.
-
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
–Join a list of planes together to form a single clip.
-
limiter
–Wraps
vs-zip <https://github.com/dnjulek/vapoursynth-zip>
.Limiter but only processes -
plane
–Extract a plane from the given clip.
-
sc_detect
– -
split
–Split a clip into a list of individual planes.
-
stack_clips
–Stack clips in the following repeating order: hor->ver->hor->ver->...
Attributes:
-
EXPR_VARS
–Variables to access clips in Expr.
-
depth_func
–
EXPR_VARS module-attribute
¶
EXPR_VARS = (alph := list(ascii_lowercase))[(idx := index('x')):] + alph[:idx]
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.
-
should_dither
–
Attributes:
-
ATKINSON
–Another error diffusion kernel.
-
AUTO
–Choose automatically.
-
ERROR_DIFFUSION
–Floyd-Steinberg error diffusion.
-
ERROR_DIFFUSION_FMTC
–Floyd-Steinberg error diffusion.
-
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
–A way to generate blue-noise dither and has a much better visual aspect than ordered dithering.
-
is_fmtc
(bool
) –Whether the DitherType is applied through fmtc.
ATKINSON class-attribute
instance-attribute
¶
ATKINSON = 'atkinson'
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'
Floyd-Steinberg error diffusion.
ERROR_DIFFUSION_FMTC class-attribute
instance-attribute
¶
ERROR_DIFFUSION_FMTC = 'error_diffusion_fmtc'
Floyd-Steinberg error diffusion. Modified for serpentine scan (avoids worm artefacts).
OSTROMOUKHOV class-attribute
instance-attribute
¶
OSTROMOUKHOV = 'ostromoukhov'
Another error diffusion kernel. Slow, available only for integer input at the moment. Avoids usual F-S artefacts.
QUASIRANDOM class-attribute
instance-attribute
¶
QUASIRANDOM = 'quasirandom'
Dither using quasirandom sequences. Good intermediary between void, cluster, and error diffusion algorithms.
SIERRA_2_4A class-attribute
instance-attribute
¶
SIERRA_2_4A = 'sierra_2_4a'
Another type of error diffusion. Quick and excellent quality, similar to Floyd-Steinberg.
STUCKI class-attribute
instance-attribute
¶
STUCKI = 'stucki'
Another error diffusion kernel. Preserves delicate edges better but distorts gradients.
VOID class-attribute
instance-attribute
¶
VOID = 'void'
A way to generate blue-noise dither and has a much better visual aspect than ordered dithering.
apply ¶
apply(
clip: VideoNode,
fmt_out: VideoFormat,
range_in: ColorRange,
range_out: ColorRange,
) -> ConstantFormatVideoNode
Apply the given DitherType to a clip.
Source code
116 117 118 119 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 150 151 |
|
should_dither staticmethod
¶
should_dither(
in_fmt: VideoFormatT | HoldsVideoFormatT,
out_fmt: VideoFormatT | HoldsVideoFormatT,
/,
in_range: ColorRangeT | None = None,
out_range: ColorRangeT | None = None,
) -> bool
should_dither(
in_bits: int,
out_bits: int,
/,
in_range: ColorRangeT | None = None,
out_range: ColorRangeT | None = None,
in_sample_type: SampleType | None = None,
out_sample_type: SampleType | None = None,
) -> bool
should_dither(
in_bits_or_fmt: int | VideoFormatT | HoldsVideoFormatT,
out_bits_or_fmt: int | VideoFormatT | HoldsVideoFormatT,
/,
in_range: ColorRangeT | None = None,
out_range: ColorRangeT | None = None,
in_sample_type: SampleType | None = None,
out_sample_type: SampleType | None = None,
) -> bool
Source code
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 262 263 264 265 266 267 268 269 270 271 |
|
depth ¶
depth(
clip: VideoNode,
bitdepth: VideoFormatT | HoldsVideoFormatT | int | None = None,
/,
sample_type: int | SampleType | None = None,
*,
range_in: ColorRangeT | None = None,
range_out: ColorRangeT | None = None,
dither_type: str | DitherType = AUTO,
) -> ConstantFormatVideoNode
A convenience bitdepth conversion function using only internal plugins if possible.
This uses exclusively internal plugins except for specific dither_types. To check whether your DitherType uses fmtc, use DitherType.is_fmtc
.
>>> src_8 = vs.core.std.BlankClip(format=vs.YUV420P8)
>>> src_10 = depth(src_8, 10)
>>> src_10.format.name
'YUV420P10'
>>> src2_10 = vs.core.std.BlankClip(format=vs.RGB30)
>>> src2_8 = depth(src2_10, 8, dither_type=Dither.RANDOM) # override default dither behavior
>>> src2_8.format.name
'RGB24'
Parameters:
-
clip
¶VideoNode
) –Input clip.
-
bitdepth
¶VideoFormatT | HoldsVideoFormatT | 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. Accepts
vapoursynth.SampleType
enumsvapoursynth.INTEGER
andvapoursynth.FLOAT
or their values,0
and1
respectively. -
range_in
¶ColorRangeT | None
, default:None
) –Input pixel range (defaults to input
clip
's range). -
range_out
¶ColorRangeT | None
, default:None
) –Output pixel range (defaults to input
clip
's range). -
dither_type
¶str | DitherType
, default:AUTO
) –Dithering algorithm. Allows overriding default dithering behavior. See Dither.
When integer output is desired but the conversion may produce fractional values, defaults to DitherType.VOID if it is available via the fmtc VapourSynth plugin, or to Floyd-Steinberg DitherType.ERROR_DIFFUSION for 8-bit output or DitherType.ORDERED for higher bit depths. In other cases, defaults to DitherType.NONE, or round to nearest. See DitherType.should_dither for more information.
Returns:
-
ConstantFormatVideoNode
–Converted clip with desired bit depth and sample type.
ColorFamily
will be same as input.
Source code
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 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 |
|
frame2clip ¶
frame2clip(frame: VideoFrame) -> ConstantFormatVideoNode
Convert a VideoFrame to a VideoNode.
Parameters:
-
frame
¶VideoFrame
) –Input frame.
Returns:
-
ConstantFormatVideoNode
–1-frame long VideoNode of the input frame.
Source code
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
|
get_b ¶
get_b(clip: VideoNode) -> ConstantFormatVideoNode
Extract the blue plane of the given clip.
Parameters:
-
clip
¶VideoNode
) –Input clip.
Returns:
-
ConstantFormatVideoNode
–B plane of the input clip.
Raises:
-
CustomValueError
–Clip is not RGB.
Source code
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
get_g ¶
get_g(clip: VideoNode) -> ConstantFormatVideoNode
Extract the green plane of the given clip.
Parameters:
-
clip
¶VideoNode
) –Input clip.
Returns:
-
ConstantFormatVideoNode
–G plane of the input clip.
Raises:
-
CustomValueError
–Clip is not RGB.
Source code
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
|
get_r ¶
get_r(clip: VideoNode) -> ConstantFormatVideoNode
Extract the red plane of the given clip.
Parameters:
-
clip
¶VideoNode
) –Input clip.
Returns:
-
ConstantFormatVideoNode
–R plane of the input clip.
Raises:
-
CustomValueError
–Clip is not RGB.
Source code
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
|
get_u ¶
get_u(clip: VideoNode) -> ConstantFormatVideoNode
Extract the first chroma (U) plane of the given clip.
Parameters:
-
clip
¶VideoNode
) –Input clip.
Returns:
-
ConstantFormatVideoNode
–Y plane of the input clip.
Raises:
-
CustomValueError
–Clip is not YUV.
Source code
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
get_v ¶
get_v(clip: VideoNode) -> ConstantFormatVideoNode
Extract the second chroma (V) plane of the given clip.
Parameters:
-
clip
¶VideoNode
) –Input clip.
Returns:
-
ConstantFormatVideoNode
–V plane of the input clip.
Raises:
-
CustomValueError
–Clip is not YUV.
Source code
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
get_y ¶
get_y(clip: VideoNode) -> ConstantFormatVideoNode
Extract the luma (Y) plane of the given clip.
Parameters:
-
clip
¶VideoNode
) –Input clip.
Returns:
-
ConstantFormatVideoNode
–Y plane of the input clip.
Raises:
-
CustomValueError
–Clip is not GRAY or YUV.
Source code
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
|
insert_clip ¶
insert_clip(
clip: VideoNode, /, insert: VideoNode, start_frame: int, strict: bool = True
) -> ConstantFormatVideoNode
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:
-
ConstantFormatVideoNode
–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
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
|
join ¶
join(
luma: VideoNode, chroma: VideoNode, family: ColorFamily | None = None
) -> ConstantFormatVideoNode
join(
y: VideoNode, u: VideoNode, v: VideoNode, family: Literal[YUV]
) -> ConstantFormatVideoNode
join(
y: VideoNode,
u: VideoNode,
v: VideoNode,
alpha: VideoNode,
family: Literal[YUV],
) -> ConstantFormatVideoNode
join(
r: VideoNode, g: VideoNode, b: VideoNode, family: Literal[RGB]
) -> ConstantFormatVideoNode
join(
r: VideoNode,
g: VideoNode,
b: VideoNode,
alpha: VideoNode,
family: Literal[RGB],
) -> ConstantFormatVideoNode
join(
*planes: VideoNode, family: ColorFamily | None = None
) -> ConstantFormatVideoNode
join(
planes: Iterable[VideoNode], family: ColorFamily | None = None
) -> ConstantFormatVideoNode
Join a list of planes together to form a single clip.
Parameters:
Returns:
-
VideoNode
–Combined planes.
Source code
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 751 752 753 754 755 756 757 758 759 760 761 762 |
|
limiter ¶
limiter(
clip: VideoNode,
/,
min_val: float | Sequence[float] | None = None,
max_val: float | Sequence[float] | None = None,
*,
tv_range: bool = False,
planes: PlanesT = None,
func: FuncExceptT | None = None,
) -> ConstantFormatVideoNode
limiter(
clip_or_func: (
VideoNode | Callable[P, ConstantFormatVideoNode] | None
) = None,
/,
min_val: float | Sequence[float] | None = None,
max_val: float | Sequence[float] | None = None,
*,
tv_range: bool = False,
planes: PlanesT = None,
func: FuncExceptT | None = None,
) -> Union[
ConstantFormatVideoNode,
Callable[P, ConstantFormatVideoNode],
Callable[
[Callable[P, ConstantFormatVideoNode]],
Callable[P, ConstantFormatVideoNode],
],
]
Wraps vs-zip <https://github.com/dnjulek/vapoursynth-zip>
.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, ConstantFormatVideoNode] | 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.
-
planes
¶PlanesT
, default:None
) –Planes to process.
-
func
¶FuncExceptT | None
, default:None
) –Function returned for custom error handling. This should only be set by VS package developers.
Returns:
-
Union[ConstantFormatVideoNode, Callable[P, ConstantFormatVideoNode], Callable[[Callable[P, ConstantFormatVideoNode]], Callable[P, ConstantFormatVideoNode]]]
–Clamped clip.
Source code
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 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 |
|
plane ¶
Extract a plane from the given clip.
Parameters:
Returns:
-
ConstantFormatVideoNode
–Grayscale clip of the clip's plane.
Source code
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 |
|
sc_detect ¶
sc_detect(clip: VideoNode, threshold: float = 0.1) -> ConstantFormatVideoNode
Source code
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 |
|
split ¶
Split a clip into a list of individual planes.
Parameters:
-
clip
¶VideoNode
) –Input clip.
Returns:
-
list[ConstantFormatVideoNode]
–List of individual planes.
Source code
788 789 790 791 792 793 794 795 796 797 798 799 800 801 |
|
stack_clips ¶
stack_clips(
clips: Sequence[
VideoNode
| Sequence[
VideoNode
| Sequence[
VideoNode
| Sequence[
VideoNode | Sequence[VideoNode | Sequence[VideoNode]]
]
]
]
],
) -> VideoNode
Stack clips in the following repeating order: hor->ver->hor->ver->...
Parameters:
-
clips
¶Sequence[VideoNode | Sequence[VideoNode | Sequence[VideoNode | Sequence[VideoNode | Sequence[VideoNode | Sequence[VideoNode]]]]]]
) –Sequence of clips to stack recursively.
Returns:
-
VideoNode
–Stacked clips.
Source code
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 |
|