Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions content/en/upscale.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: "Upscaling frames"
weight: 18
---

# Upscaling frames {#upscale}

`upscale.Upscale(src, w, h, opt)` in [`go-avkit/avkit`](https://github.com/go-avkit/avkit)
(since v0.21.0) is a pure-Go port of AMD FidelityFX Super Resolution 1.0 (EASU edge-adaptive
upsampling, then RCAS sharpening) from `ffx_fsr1.h`, MIT licence. It takes an
`image.Image` (a decoder's `*image.YCbCr`, or RGBA, NRGBA, Gray), scales 1x to 4x per
axis and returns an `*image.RGBA`. Sizes are checked before allocation; downscaling is
refused. `Options.Sharpness` is the RCAS attenuation in stops (0 sharpest, negative = no
RCAS, default 0.2).

## Accuracy {#accuracy}

Against a float64 transliteration of the reference, the float32 pipeline stays within
`ErrorBound` = 2e-4 on a 0..1 scale: 2.7e-5 measured over 662 520 samples, up to 1.1e-4 where
the compiler fuses multiply-adds. The vector rows (below) are tested against the scalar code
under the same bound.

## Quality {#quality}

Measured with ffmpeg 6.1.1's `psnr` and `ssim` filters. The ground truth is a real frame,
scaled with ffmpeg `area`, downscaled by the factor and upscaled back. PSNR dB / SSIM:

| Source (factor) | bilinear | bicubic | lanczos | FSR EASU | FSR EASU+RCAS 0.2 |
|---|---|---|---|---|---|
| Wikipedia 1080p (2x) | 22.07 / 0.863 | 22.64 / 0.881 | 22.71 / 0.877 | 22.67 / 0.889 | 22.75 / 0.892 |
| Slides 1080p (2x) | 25.03 / 0.923 | 26.43 / 0.939 | 26.64 / 0.939 | 26.40 / 0.944 | 26.47 / 0.945 |
| KristenAndSara 720p (2x) | 31.68 / 0.950 | 33.22 / 0.961 | 33.59 / 0.961 | 33.38 / 0.961 | 33.29 / 0.956 |
| GlassHalf 1080p (2x) | 31.55 / 0.936 | 32.42 / 0.947 | 32.51 / 0.946 | 32.99 / 0.953 | 32.91 / 0.955 |
| SolLevanteFace 1080p (1.5x) | 37.23 / 0.929 | 38.72 / 0.950 | 39.24 / 0.955 | 38.93 / 0.951 | 38.56 / 0.953 |

FSR has the highest SSIM on four of five sources; lanczos is slightly ahead on PSNR on some.

## Speed {#speed}

One core of a Ryzen 9 7950X (load about 2), 1280x720 to 1920x1080, milliseconds per frame:

| Scaler | ms per frame |
|---|---|
| ffmpeg 6.1.1 `scale` bilinear | 3.3 |
| ffmpeg bicubic | 2.0 |
| ffmpeg lanczos | 2.8 |
| `upscale`, scalar (default build) | 242 (EASU alone 193) |
| `upscale`, `GOEXPERIMENT=simd` (v0.22.0) | 82 (EASU alone 73) |

ffmpeg's figures subtract the source and the pixel conversion. The vector build uses the
portable Go 1.27 `simd` package (AVX2 and AVX-512 on amd64, NEON on arm64); it is chosen at
start-up, so the default build is unchanged. It is still about 30 times slower than
ffmpeg's hand-written scaler, **an open defect**: the 12-tap gather per output pixel
dominates. Today `upscale` suits stills, offline work and small frames, not real-time 1080p.

## Reproduce {#reproduce}

`tools/fsrbench` in the avkit repository (a module of its own; `ffmpeg` on the PATH):

```
go run ./tools/fsrbench quality --gt in.png --dir <workdir>
go run ./tools/fsrbench speed --core 9
GOEXPERIMENT=simd go test -bench 720to1080 ./upscale
```
Loading