frame_upsample ¶
Pixel-space spatial resampling for decoded MLX Wan frames.
Spatial fast mode denoises on a smaller latent grid and has to get back to the requested output size. That resize belongs here — after the VAE decode — and not in latent space.
A Wan latent cell is a learned code for an 8x8 (Wan2.1) or 16x16 (Wan2.2) pixel block, not a low-pass sample of the image. Linearly blending two adjacent codes does not produce the code of the blended blocks; it produces a vector the decoder was never trained on. The decoder answers with smeared, ringing texture laid over otherwise-correct structure — the silhouette survives, the detail turns to haze. Measured on Wan2.1-1.3B at 480x832, a 2x bilinear latent upsample destroys 62% of the latent's high-frequency energy while leaving its overall magnitude intact, which is exactly the signature of that veil.
Resampling decoded RGB frames has none of that problem: an image is a sampled 2-D signal, so Lanczos/cubic interpolation is the operation it was defined for. The result is soft — it carries stage-1's real detail budget and no more — but it is clean and coherent.
Functions:¶
fastvideo.mlx_runtime.frame_upsample.unsharp ¶
unsharp(frame: ndarray, amount: float) -> ndarray
Light unsharp mask, used to counter resampling / optical-flow softening.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame | ndarray | HxWx3 uint8 RGB frame. | required |
amount | float | Strength; | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: A new frame; the input is never modified in place. |
Source code in fastvideo/mlx_runtime/frame_upsample.py
fastvideo.mlx_runtime.frame_upsample.upsample_frame ¶
upsample_frame(frame: ndarray, *, width: int, height: int, mode: str = DEFAULT_PIXEL_UPSAMPLE_MODE, sharpen: float = 0.0) -> ndarray
Resample one decoded RGB frame to the target pixel size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame | ndarray | HxWx3 uint8 RGB frame. | required |
width | int | Target width in pixels. | required |
height | int | Target height in pixels. | required |
mode | str | Interpolation kernel, one of :data: | DEFAULT_PIXEL_UPSAMPLE_MODE |
sharpen | float | Unsharp strength applied after the resize. | 0.0 |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: A new frame at |
Raises:
| Type | Description |
|---|---|
ValueError | If the frame is not HxWx3, or the target size is not positive. |
Source code in fastvideo/mlx_runtime/frame_upsample.py
fastvideo.mlx_runtime.frame_upsample.upsample_frames ¶
upsample_frames(frames: Iterable[ndarray], *, width: int, height: int, mode: str = DEFAULT_PIXEL_UPSAMPLE_MODE, sharpen: float = 0.0) -> list[ndarray]
Resample every decoded frame to the target pixel size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames | Iterable[ndarray] | Decoded HxWx3 uint8 RGB frames. | required |
width | int | Target width in pixels. | required |
height | int | Target height in pixels. | required |
mode | str | Interpolation kernel, one of :data: | DEFAULT_PIXEL_UPSAMPLE_MODE |
sharpen | float | Unsharp strength applied after each resize. | 0.0 |
Returns:
| Type | Description |
|---|---|
list[ndarray] | list[np.ndarray]: New frames at the target size, in input order. |