Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ vectorbench report DIR/results.json # Markdown tables
`run` refuses a VTracer or resvg of another version unless
`--allow-unpinned-tools` is given, and then stamps the difference into the
results. ffmpeg is not pinned (distributions differ); its full version line and
the encoder library versions are recorded instead.
the encoder library versions are recorded instead. When no single ffmpeg has the
encoders and libvmaf, `--ffmpeg-quality BIN` names a second build that only
measures PSNR and VMAF; its version is recorded as `ffmpeg_quality`.

## Clips

Expand Down Expand Up @@ -75,8 +77,17 @@ so matched-quality sizes are interpolated (log size against quality) and marked.
## Results

`results/` holds the published results JSON, each with its tool versions,
machine and load. Rendered tables and the discussion are on the docs page
"Vector video vs codecs" of go-avkit/docs.
machine and load, and its rendered report.

- `results/fractal-core9.json` and `results/fractal-core9.md`: all nine clips,
24 frames each, on host `fractal` (Linux amd64) with the process pinned to
core 9 (`taskset -c 9`), one-minute load 1.77 at the start and 2.05 at the
end (limit 8). Encoders: Ubuntu ffmpeg 6.1.1 (x264, x265, SVT-AV1 1.7.0,
libvpx-vp9). PSNR and VMAF: a static ffmpeg 7.0.2 with libvmaf, because no
single build there had both (`--ffmpeg-quality`). VTracer 0.6.5 and resvg
0.50.0; the sha256 of the three binaries is in the note of the file.

The discussion is on the docs page "Vector video vs codecs" of go-avkit/docs.

## Licences

Expand Down
5 changes: 3 additions & 2 deletions cmd/vectorbench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func runCmd() *cobra.Command {
work, only, note, waiver, clipsFile string
frames, jobs int
maxLoad float64
ffmpeg, vtracer, resvg string
ffmpeg, vtracer, resvg, qffmpeg string
unpinned bool
)
cmd := &cobra.Command{
Expand All @@ -96,7 +96,7 @@ func runCmd() *cobra.Command {
}
cfg := bench.Config{
Work: work, Frames: frames, Clips: clips, Variant: bench.DefaultVariants(), Jobs: jobs,
FFmpeg: ffmpeg, VTracer: vtracer, Resvg: resvg,
FFmpeg: ffmpeg, QualityFFmpeg: qffmpeg, VTracer: vtracer, Resvg: resvg,
MaxLoad: maxLoad, LoadWaiver: waiver, AllowUnpinned: unpinned, Note: note,
Version: version(), Log: cmd.ErrOrStderr(), Load: bench.SystemLoad, Pins: pins,
Client: newClient(),
Expand All @@ -118,6 +118,7 @@ func runCmd() *cobra.Command {
f.StringVar(&only, "only", "", "comma-separated clip names (default all)")
f.IntVar(&jobs, "jobs", 1, "parallel VTracer processes (1 keeps timings honest)")
f.StringVar(&ffmpeg, "ffmpeg", "ffmpeg", "ffmpeg binary (with libx264, libx265, libsvtav1, libvpx-vp9, libvmaf)")
f.StringVar(&qffmpeg, "ffmpeg-quality", "", "ffmpeg binary with libvmaf that measures PSNR and VMAF, when --ffmpeg has none (default: --ffmpeg)")
f.StringVar(&vtracer, "vtracer", "vtracer", "vtracer binary")
f.StringVar(&resvg, "resvg", "resvg", "resvg binary")
f.Float64Var(&maxLoad, "max-load", 8, "refuse to start when the one-minute load is above this")
Expand Down
27 changes: 23 additions & 4 deletions internal/bench/churn.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,17 @@ func colourDist(a, b Path) float64 {
// indexed by their four corners and their centre only, which is enough to find
// any box of IoU >= 0.5 with them.
func cells(p Path) []cellKey {
x0, y0 := int(math.Floor(p.X0/cellSize)), int(math.Floor(p.Y0/cellSize))
x1, y1 := int(math.Floor(p.X1/cellSize)), int(math.Floor(p.Y1/cellSize))
if x1-x0 >= 32 || y1-y0 >= 32 {
cx, cy := int(math.Floor(p.CX()/cellSize)), int(math.Floor(p.CY()/cellSize))
fx0, fy0 := math.Floor(p.X0/cellSize), math.Floor(p.Y0/cellSize)
fx1, fy1 := math.Floor(p.X1/cellSize), math.Floor(p.Y1/cellSize)
// A box from an untrusted SVG can carry NaN, an infinity or a coordinate
// beyond int: it is indexed by its corners, from clamped values, and the
// span test is written so that NaN takes that branch.
if !(fx1-fx0 < 32 && fy1-fy0 < 32) {
cx, cy := clampCell(math.Floor(p.CX()/cellSize)), clampCell(math.Floor(p.CY()/cellSize))
x0, y0, x1, y1 := clampCell(fx0), clampCell(fy0), clampCell(fx1), clampCell(fy1)
return []cellKey{{x0, y0}, {x1, y0}, {x0, y1}, {x1, y1}, {cx, cy}}
}
x0, y0, x1, y1 := int(fx0), int(fy0), int(fx1), int(fy1)
out := make([]cellKey, 0, (x1-x0+1)*(y1-y0+1))
for y := y0; y <= y1; y++ {
for x := x0; x <= x1; x++ {
Expand All @@ -148,6 +153,20 @@ func cells(p Path) []cellKey {
return out
}

// clampCell converts a floored coordinate to a cell index; NaN is cell 0 and
// values beyond +-1<<30 are clamped (also safe on 32-bit int).
func clampCell(f float64) int {
switch {
case f != f:
return 0
case f > 1<<30:
return 1 << 30
case f < -(1 << 30):
return -(1 << 30)
}
return int(f)
}

// ChurnSummary is the mean of the consecutive-frame Churn values of a clip.
type ChurnSummary struct {
Pairs int `json:"pairs"`
Expand Down
23 changes: 23 additions & 0 deletions internal/bench/churn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,26 @@ func TestSummarise(t *testing.T) {
t.Fatal("empty")
}
}

// A box read from an SVG can carry NaN, an infinity or a coordinate beyond int:
// cells must neither panic (makeslice) nor enumerate a huge range. Found by
// FuzzParsePaths in CI.
func TestMatchPathsNonFiniteBoxes(t *testing.T) {
nan, inf := math.NaN(), math.Inf(1)
boxes := []Path{
box(nan, 0, 10, 10, 1, 2, 3),
box(0, 0, inf, 10, 1, 2, 3),
box(-inf, -inf, inf, inf, 1, 2, 3),
box(0, 0, 1e300, 1e300, 1, 2, 3),
box(nan, nan, nan, nan, 1, 2, 3),
box(10, 10, 0, 0, 1, 2, 3),
}
for i, a := range boxes {
for j, b := range boxes {
c := MatchPaths([]Path{a}, []Path{b})
if c.Prev != 1 || c.Cur != 1 || c.Matched > 1 {
t.Errorf("%d,%d: %+v", i, j, c)
}
}
}
}
17 changes: 14 additions & 3 deletions internal/bench/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type Config struct {
Jobs int // parallel VTracer processes; 1 keeps the timings honest

FFmpeg, VTracer, Resvg string
// QualityFFmpeg measures PSNR and VMAF when no single ffmpeg build has both
// the encoders and libvmaf; empty means FFmpeg does both.
QualityFFmpeg string

MaxLoad float64 // refuse to start above this one-minute load
LoadWaiver string // why a run above MaxLoad goes ahead anyway
Expand Down Expand Up @@ -125,9 +128,13 @@ func contains(l []string, s string) bool {

// recordTools stores the version of every tool and checks the pinned ones.
func (cfg *Config) recordTools(ctx context.Context, res *Results) error {
for _, t := range []struct{ key, bin, flag string }{
tools := []struct{ key, bin, flag string }{
{"ffmpeg", cfg.FFmpeg, "-version"}, {"vtracer", cfg.VTracer, "--version"}, {"resvg", cfg.Resvg, "--version"},
} {
}
if cfg.QualityFFmpeg != "" {
tools = append(tools, struct{ key, bin, flag string }{"ffmpeg_quality", cfg.QualityFFmpeg, "-version"})
}
for _, t := range tools {
r, err := cfg.Exec.Run(ctx, t.bin, t.flag)
if err != nil {
return fmt.Errorf("%s: %w", t.key, err)
Expand Down Expand Up @@ -289,7 +296,11 @@ func (cfg *Config) quality(ctx context.Context, distArgs []string, src string) (
// frame k-1 of the y4m source and report a false ~29 dB.
"[0:v]format=yuv420p,settb=1/1000,setpts=N,split[a][b];[1:v]format=yuv420p,settb=1/1000,setpts=N,split[c][d];[a][c]psnr;[b][d]libvmaf=n_threads=4",
"-f", "null", "-")
r, err := cfg.Exec.Run(ctx, cfg.FFmpeg, args...)
bin := cfg.FFmpeg
if cfg.QualityFFmpeg != "" {
bin = cfg.QualityFFmpeg
}
r, err := cfg.Exec.Run(ctx, bin, args...)
if err != nil {
return 0, 0, err
}
Expand Down
33 changes: 33 additions & 0 deletions internal/bench/runner_fail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,36 @@ func TestExecuteLoadReadLater(t *testing.T) {
}
}
}

func TestQualityFFmpegMeasuresOnly(t *testing.T) {
fx := &fakeExec{vtVer: "visioncortex VTracer 0.6.5"}
cfg := testConfig(t, fx, 1)
cfg.QualityFFmpeg = "qffmpeg"
res, err := Execute(context.Background(), cfg)
if err != nil {
t.Fatal(err)
}
if res.Tools["ffmpeg_quality"] == "" || res.Tools["ffmpeg"] == "" {
t.Fatalf("tools: %+v", res.Tools)
}
n := 0
for _, c := range fx.calls {
if strings.Contains(c, "-lavfi") {
n++
if !strings.HasPrefix(c, "qffmpeg ") {
t.Fatalf("quality measured by the wrong binary: %s", c)
}
} else if strings.HasPrefix(c, "qffmpeg ") && !strings.HasSuffix(c, "-version") {
t.Fatalf("the quality binary encoded: %s", c)
}
}
if n == 0 {
t.Fatal("no quality call")
}
bad := &fakeExec{vtVer: "visioncortex VTracer 0.6.5", fail: "qffmpeg -version"}
cfg = testConfig(t, bad, 1)
cfg.QualityFFmpeg = "qffmpeg"
if _, err := Execute(context.Background(), cfg); err == nil || !strings.Contains(err.Error(), "ffmpeg_quality") {
t.Fatalf("%v", err)
}
}
Loading
Loading