helpers ¶
Classes:
-
CropAbs– -
CropRel– -
ScalingArgs–
Functions:
-
get_gpu–Return the GPU available for the requested device id.
-
is_gpu_available–Check if a GPU is available for the requested device id.
-
pre_ss–Supersamples the input clip, applies a given function to the higher-resolution version, and then downscales it back to the original resolution.
-
pscale_blend–Apply pscale-based error correction/scaling expression.
-
scale_var_clip–Scale a variable clip to constant or variable resolution.
CropAbs ¶
CropRel ¶
Bases: NamedTuple
Attributes:
ScalingArgs dataclass ¶
ScalingArgs(
width: int,
height: int,
src_width: float,
src_height: float,
src_top: float,
src_left: float,
mode: str = "hw",
)
Methods:
Attributes:
-
height(int) – -
mode(str) – -
src_height(float) – -
src_left(float) – -
src_top(float) – -
src_width(float) – -
width(int) –
from_args classmethod ¶
from_args(
base_clip: VideoNode,
height: int,
width: int | None = None,
*,
src_top: float = ...,
src_left: float = ...,
sample_grid_model: int = MATCH_EDGES,
mode: str = "hw",
) -> Self
from_args(
base_clip: VideoNode,
height: float,
width: float | None = ...,
base_height: int | None = ...,
base_width: int | None = ...,
src_top: float = ...,
src_left: float = ...,
crop: tuple[LeftCrop, RightCrop, TopCrop, BottomCrop]
| CropRel
| CropAbs
| None = ...,
sample_grid_model: int = MATCH_EDGES,
mode: str = "hw",
) -> Self
from_args(
base_clip: VideoNode,
height: int | float,
width: int | float | None = None,
base_height: int | None = None,
base_width: int | None = None,
src_top: float = 0,
src_left: float = 0,
crop: tuple[LeftCrop, RightCrop, TopCrop, BottomCrop]
| CropRel
| CropAbs
| None = None,
sample_grid_model: int = MATCH_EDGES,
mode: str = "hw",
) -> Self
Get (de)scaling arguments for integer scaling.
Parameters:
-
(base_clip¶VideoNode) –Source clip.
-
(height¶int | float) –Target (de)scaling height. Casting to float will ensure fractional calculations.
-
(width¶int | float | None, default:None) –Target (de)scaling width. Casting to float will ensure fractional calculations. If None, it will be calculated from the height and the aspect ratio of the base_clip.
-
(base_height¶int | None, default:None) –The height from which to contain the clip. If None, it will be calculated from the height.
-
(base_width¶int | None, default:None) –The width from which to contain the clip. If None, it will be calculated from the width.
-
(src_top¶float, default:0) –Vertical offset.
-
(src_left¶float, default:0) –Horizontal offset.
-
(crop¶tuple[LeftCrop, RightCrop, TopCrop, BottomCrop] | CropRel | CropAbs | None, default:None) –Tuple of cropping values, or relative/absolute crop specification.
-
(mode¶str, default:'hw') –Scaling mode:
- "w" means only the width is calculated.
- "h" means only the height is calculated.
- "hw" or "wh" mean both width and height are calculated.
-
(sample_grid_model¶int, default:MATCH_EDGES) –Model used to align sampling grid.
Returns:
-
Self–ScalingArgs object suitable for scaling functions.
Source code in vsscale/helpers.py
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 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 272 273 274 275 276 277 278 279 280 281 282 283 284 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 | |
kwargs ¶
Source code in vsscale/helpers.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
get_gpu cached ¶
get_gpu(device_id: int = 0) -> Device | None
Return the GPU available for the requested device id.
Source code in vsscale/helpers.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 | |
is_gpu_available ¶
Check if a GPU is available for the requested device id.
Source code in vsscale/helpers.py
553 554 555 556 557 | |
pre_ss ¶
pre_ss(
clip: VideoNode,
function: VSFunctionNoArgs,
rfactor: float = 2.0,
sp: type[MixedScalerProcess[Any, Any]] = ComplexSuperSamplerProcess,
*,
mod: int = 4,
pscale: float = 1.0,
planes: Planes = None,
func: FuncExcept | None = None,
) -> VideoNode
pre_ss(
clip: VideoNode,
*,
rfactor: float = 2.0,
sp: MixedScalerProcess[Any, Any],
mod: int = 4,
pscale: float = 1.0,
planes: Planes = None,
func: FuncExcept | None = None,
) -> VideoNode
pre_ss(
clip: VideoNode,
function: VSFunctionNoArgs,
rfactor: float = 2.0,
*,
supersampler: ScalerLike | Callable[[VideoNode, int, int], VideoNode],
downscaler: ScalerLike | Callable[[VideoNode, int, int], VideoNode],
mod: int = 4,
pscale: float = 1.0,
planes: Planes = None,
func: FuncExcept | None = None,
) -> VideoNode
pre_ss(
clip: VideoNode,
function: VSFunctionNoArgs | None = None,
rfactor: float = 2.0,
sp: type[MixedScalerProcess[Any, Any]]
| MixedScalerProcess[Any, Any] = ComplexSuperSamplerProcess,
supersampler: ScalerLike
| Callable[[VideoNode, int, int], VideoNode]
| None = None,
downscaler: ScalerLike
| Callable[[VideoNode, int, int], VideoNode]
| None = None,
mod: int = 4,
pscale: float = 1.0,
planes: Planes = None,
func: FuncExcept | None = None,
) -> VideoNode
Supersamples the input clip, applies a given function to the higher-resolution version, and then downscales it back to the original resolution.
This function generalizes the behavior of SuperSamplerProcess and ComplexSuperSamplerProcess.
-
Examples:
out = pre_ss(clip, lambda clip: cool_function(clip, ...), planes=0)- Passing NNEDI3 as a supersampler:
from vsaa import SuperSamplerProcess out = pre_ss(clip, lambda clip: cool_function(clip, ...), SuperSamplerProcess) -
This works too:
from vsaa import SuperSamplerProcess out = pre_ss(clip, sp=SuperSamplerProcess(function=lambda clip: cool_function(clip, ...))) -
Specifying
supersampleranddownscaler:from vskernels import Point out = pre_ss(clip, lambda clip: cool_function(clip, ...), supersampler=Point, downscaler=Point, planes=0)
- Passing NNEDI3 as a supersampler:
Parameters:
-
(clip¶VideoNode) –Source clip.
-
(function¶VSFunctionNoArgs | None, default:None) –A function to apply on the supersampled clip.
-
(rfactor¶float, default:2.0) –Scaling factor for supersampling. Defaults to 2.
-
(sp¶type[MixedScalerProcess[Any, Any]] | MixedScalerProcess[Any, Any], default:ComplexSuperSamplerProcess) –A MixedScalerProcess instance or class. Default is ComplexSuperSamplerProcess[Lanczos]. It upscales with Lanczos and downscales with Point.
-
(supersampler¶ScalerLike | Callable[[VideoNode, int, int], VideoNode] | None, default:None) –Scaler used to upscale the input clip if
spis not specified. -
(downscaler¶ScalerLike | Callable[[VideoNode, int, int], VideoNode] | None, default:None) –Downscaler used for undoing the upscaling done by the supersampler if
spis not specified. -
(mod¶int, default:4) –Ensures the supersampled resolution is a multiple of this value. Defaults to 4.
-
(pscale¶float, default:1.0) –Scaling correction strength.
-
(planes¶Planes, default:None) –Which planes to process.
-
(func¶FuncExcept | None, default:None) –An optional function to use for error handling.
Returns:
-
VideoNode–A clip with the given function applied at higher resolution, then downscaled back.
Source code in vsscale/helpers.py
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 467 468 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 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
pscale_blend ¶
pscale_blend(
clip: VideoNode,
processed: VideoNode,
unprocessed: VideoNode | Callable[[], VideoNode],
pscale: float = 0.0,
planes: Planes = None,
func: FuncExcept | None = None,
) -> VideoNode
Apply pscale-based error correction/scaling expression.
This function calculates a blend of the processed clip, the original clip, and an unprocessed, re-scaled and downscaled clip to correct downscaling artifacts/ringing.
The formula evaluated is
y + (1 - pscale) * (x - z)
Where
xisclip(original input clip)yisprocessed(processed and downscaled clip)zisunprocessed(unprocessed and downscaled clip)
- Behavior of
pscale:1.0: No correction is applied (yis returned).0.5: The scaling change is blended back at half strength.0.0: The scaling change is blended back at full strength.> 1.0: Subtracts scaling changes (acts as a low-pass/blur).< 0.0: Amplifies scaling changes (acts as a low-quality sharpen).
Parameters:
-
(clip¶VideoNode) –Original input clip (x).
-
(processed¶VideoNode) –Processed and resampled/downscaled clip (y).
-
(unprocessed¶VideoNode | Callable[[], VideoNode]) –Unprocessed resampled/downscaled clip or a callable that returns it (z).
-
(pscale¶float, default:0.0) –Scale factor/correction strength.
-
(planes¶Planes, default:None) –Planes to process.
-
(func¶FuncExcept | None, default:None) –Function returned for custom error handling.
Returns: The blended/corrected clip.
Source code in vsscale/helpers.py
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 371 372 373 | |
scale_var_clip ¶
scale_var_clip(
clip: VideoNode,
scaler: Scaler | Callable[[tuple[int, int]], Scaler],
width: int | Callable[[tuple[int, int]], int] | None,
height: int | Callable[[tuple[int, int]], int],
shift: tuple[float, float]
| Callable[[tuple[int, int]], tuple[float, float]] = (0, 0),
debug: bool = False,
) -> VideoNode
Scale a variable clip to constant or variable resolution.
Parameters:
-
(clip¶VideoNode) –Source clip.
-
(scaler¶Scaler | Callable[[tuple[int, int]], Scaler]) –A scaler instance or a callable that returns a scaler instance.
-
(width¶int | Callable[[tuple[int, int]], int] | None) –A width integer or a callable that returns the width. If None, it will be calculated from the height and the aspect ratio of the clip.
-
(height¶int | Callable[[tuple[int, int]], int]) –A height integer or a callable that returns the height.
-
(shift¶tuple[float, float] | Callable[[tuple[int, int]], tuple[float, float]], default:(0, 0)) –Optional top shift, left shift tuple or a callable that returns the shifts. Defaults to no shift.
-
(debug¶bool, default:False) –If True, the
var_widthandvar_heightprops will be added to the clip.
Returns:
-
VideoNode–Scaled clip.
Source code in vsscale/helpers.py
36 37 38 39 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |