mosaic

AI Agent Guide

This file is for AI coding agents and automated contributors working on Mosaic.

Human contributors should start with README.md and CONTRIBUTING.md.

Project Summary

Mosaic is a Go library for ABR encoding to HLS and DASH CMAF.

Core flow:

Job -> probe -> ladder -> optimize -> encoder -> FFmpeg

Do not bypass this flow unless the task explicitly requires it.

Required Reading Before Changes

For code changes, read:

For public API changes, also read:

Repository Rules

Behavioral Contracts

Aspect Ratio

Ladders preserve source display aspect ratio.

Do not reintroduce fixed 16:9 output sizing for square, portrait, or non-standard inputs.

Orientation

Probe and ladder logic use display dimensions, not raw stored dimensions.

When normalization is enabled:

Do not remove output rotation metadata clearing unless replacing it with a tested equivalent.

Output Directories

HLS and DASH encoders create outDir automatically.

Tests should use t.TempDir() rather than root-level paths like /output.

Tests

Prefer mock executor tests for command construction.

Use real FFmpeg smoke tests only when necessary and keep generated files under /tmp.

Standard Commands

gofmt -w <changed-go-files>
GOCACHE=/tmp/go-build go test ./...
GOCACHE=/tmp/go-build go vet ./...

Optional:

golangci-lint run

Documentation Requirements

Update docs when behavior changes.

Common mappings:

Change Type Docs To Update
Public API README.md, docs/API.md, CHANGELOG.md
Encode behavior README.md, docs/ENCODING.md, CHANGELOG.md
Package structure STRUCTURE.md, docs/ARCHITECTURE.md
Test workflow docs/TESTING.md, CONTRIBUTING.md
User-facing bug fix CHANGELOG.md, relevant troubleshooting docs

Git Hygiene

Useful Smoke Tests

Square input should produce square rungs:

1080x1080 -> 1080x1080, 720x720, 360x360

Rotated portrait input with stored 1920x1080 and rotation -90 should produce portrait rungs:

608x1080, 404x720, 202x360

Non-standard landscape input 1280x718 should not be forced to 640x360; it should preserve ratio approximately:

642x360

Common Mistakes