encode

package
v0.0.0-...-d0fda0e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2026 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package encode provides the parallel chunk encoding pipeline.

Index

Constants

This section is empty.

Variables

View Source
var ErrMemoryPressure = errors.New("memory pressure critical; canceled before swap exhaustion")

ErrMemoryPressure is returned when Reel cancels encoding to avoid system OOM.

Functions

func EncodeAll

func EncodeAll(
	ctx context.Context,
	chunks []chunk.Chunk,
	inputPath string,
	inf *video.Info,
	cfg *EncodeConfig,
	workDir string,
	cropRect *video.CropRect,
	progressCb ProgressCallback,
) (int, error)

EncodeAll runs the parallel encoding pipeline. Uses streaming frame pipeline: each worker decodes and encodes one frame at a time, avoiding the need to hold all frames in memory at once.

Returns (maxWorkers, error) where maxWorkers is the adaptive concurrency ceiling.

func EncodeTargetQuality

func EncodeTargetQuality(
	ctx context.Context,
	chunks []chunk.Chunk,
	inputPath string,
	inf *video.Info,
	cfg *EncodeConfig,
	workDir string,
	cropRect *video.CropRect,
	progressCb ProgressCallback,
	tq TargetQualityConfig,
) (int, *perf.TargetQualityStats, error)

func GrainTreatmentSummary

func GrainTreatmentSummary(stats *perf.GrainTreatmentStats) []string

GrainTreatmentSummary is the human-readable verdict for the Encoding section: what was measured and what it bought.

func MaxAdaptiveWorkers

func MaxAdaptiveWorkers() int

MaxAdaptiveWorkers returns the hardware-derived adaptive concurrency ceiling.

Types

type EncodeConfig

type EncodeConfig struct {
	CRF        float32 // Quality (CRF value)
	Preset     uint8   // SVT-AV1 preset
	Tune       uint8   // SVT-AV1 tune
	GrainTable *string // Optional film grain table path
	// Denoise is an experimental libavfilter graph string (for example
	// "hqdn3d=2:1.5:3:2.25") applied to every frame before it reaches the
	// encoder AND to every reference frame the quality metric reads, so
	// target-quality scoring measures the encode against the denoised source
	// rather than the original. Empty disables it.
	Denoise            string
	LevelOfParallelism uint32 // SVT-AV1 level_of_parallelism (1-6); 0 lets Reel choose
	// StatusCallback receives verbose-only limiter status (ramp-up messages).
	StatusCallback func(message string)
	// WarningCallback receives degraded-behavior limiter status (worker
	// reductions and the critical cancel) unconditionally, independent of
	// verbose mode, since these describe output-affecting decisions.
	WarningCallback func(message string)

	// Advanced SVT-AV1 parameters
	ACBias                float32
	EnableVarianceBoost   bool
	VarianceBoostStrength uint8
	VarianceOctile        uint8
}

EncodeConfig contains configuration for the parallel encode pipeline.

type GrainGateInput

type GrainGateInput struct {
	InputPath string
	WorkDir   string
	Info      *video.Info
	Chunks    []chunk.Chunk
	CropRect  *video.CropRect
	// DisplayPath is the CVVDP display model used to score the denoise
	// ceiling; empty skips the ceiling measurement.
	DisplayPath string
	// BandTopJOD is the top of the configured target-quality band, recorded
	// in the stats for consumers judging the measured ceiling.
	BandTopJOD float64
	// BandCenterJOD is the target the band is centered on; stage 2 measures
	// what the sample chunks cost there. Zero disables stage 2.
	BandCenterJOD float64
	Verbose       func(string)
}

GrainGateInput describes the title the gate measures.

type GrainTreatment

type GrainTreatment struct {
	// Denoise is the libavfilter graph to run every encoder input and metric
	// reference frame through; empty means untreated.
	Denoise string
	// TablePath is the film grain table to attach, materialized in the work
	// directory; empty means none.
	TablePath string
	Stats     *perf.GrainTreatmentStats
}

GrainTreatment is the resolved per-title treatment plus the record of how it was decided.

func RecordedGrainTreatment

func RecordedGrainTreatment(mode string, cfg *EncodeConfig, in GrainGateInput) (GrainTreatment, error)

RecordedGrainTreatment returns the treatment this work directory has already settled on, without running the gate: an explicit override, the verdict a previous run recorded, or nothing decided yet. The chunked pipeline builds the resume manifest from it, so a work directory can never be resumed under a treatment its finished chunks were not encoded with.

func ResolveGrainTreatment

func ResolveGrainTreatment(ctx context.Context, mode string, cfg *EncodeConfig, in GrainGateInput) (GrainTreatment, error)

ResolveGrainTreatment decides how a title is treated and materializes what the encode needs. mode is config.GrainTreatmentAuto or GrainTreatmentOff. Explicit experimental cfg.Denoise/cfg.GrainTable win over the gate.

A verdict recorded by an earlier run of the same work directory is reused verbatim: re-running the gate could disagree with the treatment the already encoded chunks were produced under. The resume manifest discards the verdict along with the rest of the state when the input or encode settings change.

type ProgressCallback

type ProgressCallback func(progress worker.Progress)

ProgressCallback is called to report encoding progress.

type TargetQualityConfig

type TargetQualityConfig struct {
	// Metric selects the probe metric; Target/Tolerance are denominated in
	// its units (CVVDP JOD or SSIMU2 points). Empty means CVVDP.
	Metric        quality.MetricKind
	Target        float32
	Tolerance     float32
	CRFMin        float32
	CRFMax        float32
	MaxProbes     int
	MetricWorkers int
	DisplayPath   string
	InitialCRF    float32
	// GrainTreatment is the grain gate's verdict for this title, recorded in
	// target-quality.json so a run's scores can be read next to the treatment
	// (and the honest denoise ceiling) they were measured under.
	GrainTreatment *perf.GrainTreatmentStats
	Verbose        func(string)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL