Documentation
¶
Overview ¶
Package export renders a project to a file.
Index ¶
- Constants
- type Check
- type Format
- type GIFEstimate
- type Job
- type Loudness
- type PixelRenderer
- type Progress
- type RenderConfig
- type Renderer
- func (r *Renderer) Close() error
- func (r *Renderer) MixFrom(ctx context.Context, from, n int, sink func([]float32) error) error
- func (r *Renderer) Render(ctx context.Context, t int, outScale float64) (*image.RGBA, error)
- func (r *Renderer) RenderSize(ctx context.Context, t, w, h int) (*image.RGBA, error)
- type Result
- type Verified
Constants ¶
const ( CodeLintBlocking = "E_LINT_BLOCKING" CodeExportFailed = "E_EXPORT_FAILED" CodeVerifyFailed = "E_VERIFY_FAILED" )
Error codes of SDD-000 section 8 that an export raises. E_NO_ENCODER and E_INTERNAL come from engine/ffmpeg; a cancelled export returns the error of its context.
const ( ReasonEncoder = "encoder_failed" ReasonDecoder = "decoder_failed" ReasonRender = "render_failed" ReasonAudio = "audio_failed" ReasonTimeout = "timeout" ReasonStalled = "stalled" ReasonPublish = "publish_failed" ReasonBadOutput = "bad_output_dir" ReasonBadFormat = "bad_format" )
Reasons of E_EXPORT_FAILED (details.reason).
const ReasonSizeLimit = "size_limit"
ReasonSizeLimit is details.reason of an export whose file passed STUARTY_MAX_EXPORT_BYTES.
const ReasonUnsupportedSize = "unsupported_size"
ReasonUnsupportedSize is details.reason of an export the chosen encoder cannot do at the size or the frame rate of the project.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Check ¶
type Check struct {
Name string `json:"name"`
Expected string `json:"expected"`
Got string `json:"got"`
}
Check is one failed check of the verification of section 8 step 7.
type Format ¶
type Format string
Format is what an export writes (SDD-004 section 8, RF-064). The zero value is MP4.
const ( FormatMP4 Format = "mp4" // H.264 and AAC, the default FormatGIF Format = "gif" // composed frames, a fixed palette, written by the engine FormatWAV Format = "wav" // the 48 kHz stereo 16-bit mix FormatAAC Format = "aac" // the mix as AAC in an MP4 container, extension .m4a )
The formats of an export. Audio is a project's mix only: no picture is composed.
type GIFEstimate ¶
type GIFEstimate struct {
Width, Height int // the pixel size of the GIF (gifMaxWidth wide at most)
Frames int // the number of GIF frames, after the frame rate is lowered
TypicalBytes int64 // the size of ordinary footage
WorstBytes int64 // the size of the noisiest picture, which no export passes
}
GIFEstimate is what a GIF export of a project will be, known before it starts.
func EstimateGIF ¶
func EstimateGIF(st timeline.Settings, frames int) GIFEstimate
EstimateGIF is the size of the GIF of a project of frames timeline frames, from the size and the frame rate the export will use (gifSize and gifStep). It is an estimate to warn a person before a huge file is written (VV-056), not a promise: the real size depends on the picture.
type Job ¶
type Job struct {
Runner *ffmpeg.Runner
// Caps is ffmpeg's capability list, for the encoder detection.
Caps *ffmpeg.Capabilities
Doc *timeline.Document
// JobID names the run directory under <workspace>/tmp.
JobID string
// ArtifactsDir is <workspace>/artifacts, where the normalized media of the assets is.
ArtifactsDir string
// ExportsDir and ProjectID make the destination: <ExportsDir>/<ProjectID>/<JobID>.mp4, from
// identifiers that are checked, written through os.Root (SDD-004 section 8 step 8). There is no
// way to name another destination. Nothing is written there unless the file passed its verification.
ExportsDir string
ProjectID string
// OutPath is the old way to name the destination, used only when ExportsDir is empty; the service
// moves to ExportsDir and ProjectID and OutPath is then removed.
OutPath string
// Format is what the export writes; the zero value is FormatMP4.
Format Format
// MaxBytes is STUARTY_MAX_EXPORT_BYTES: a larger file ends the job with reason "size_limit".
// Zero is no limit.
MaxBytes int64
// Encoder is STUARTY_ENCODER and STUARTY_ALLOW_USER_X264 (ADR-0011 item 5).
Encoder ffmpeg.DetectOptions
// Start and End are the frames [Start, End) of the timeline to export. End 0 is the end of the
// last item; Start 0 and End 0 export the whole timeline (VV-018).
Start, End int
// Lint is the environment of the lint that gates the export (unready media, text sizes).
Lint lint.Env
// Fonts is the font set of the rasterizer; the bundled fonts when nil.
Fonts *rasterize.FontSet
// Bands is the number of bands of the compositor; zero is one per CPU, at most 8.
Bands int
// PixelRenderer is STUARTY_EXPORT_RENDERER: the Go compositor (the zero value) or the Rust renderer
// running as WebAssembly under wazero (SDD-013 section 4.6). Both draw the same bytes.
PixelRenderer PixelRenderer
// GPUHost is the absolute path of the native GPU host stuarty-render. With PixelRendererGPU and a path the
// frames are drawn by the child when the machine has a graphics adapter, and by the WebAssembly module
// otherwise (SDD-013 section 4.9); empty means no GPU host.
GPUHost string
// OnProgress is called at most 4 times per second and once at the last frame.
OnProgress func(Progress)
// contains filtered or unexported fields
}
Job is one export (SDD-004 section 8).
type Loudness ¶
type Loudness struct {
IntegratedLUFS *float64 `json:"integrated_lufs"` // before the gain; nil for a silent mix
TruePeakDBTP *float64 `json:"true_peak_dbtp"` // before the gain
GainDB float64 `json:"gain_db"`
TargetLUFS float64 `json:"target_lufs"`
// Limited is true when the gain took the mix over the true peak ceiling and the limiter held
// the peaks. OutputLUFS is then the loudness of the file after the limiter, and ShortfallDB how
// far it stays under the target (0 when it reached it).
Limited bool `json:"limited"`
OutputLUFS *float64 `json:"output_lufs,omitempty"`
ShortfallDB float64 `json:"shortfall_db"`
}
Loudness is what the mix measured and the gain that was applied to it (SDD-004 section 7).
type PixelRenderer ¶
type PixelRenderer string
PixelRenderer names what places the pixels of an exported frame (SDD-013 section 4.6, ADR-0029 item 8).
const ( PixelRendererGo PixelRenderer = "go" PixelRendererRust PixelRenderer = "rust" // PixelRendererGPU draws on the GPU in the child process stuarty-render when there is an adapter and a // GPU host, and as PixelRendererRust otherwise. The GPU frames are held to the CPU path by SSIM, not byte // for byte (SDD-013 section 3.8). PixelRendererGPU PixelRenderer = "gpu" )
The two renderers. The Go compositor stays the default until the byte-for-byte gate of stage C passes on Linux, macOS and Windows; the Rust renderer is the same frames drawn by the WebAssembly module.
func ParsePixelRenderer ¶
func ParsePixelRenderer(s string) (PixelRenderer, error)
ParsePixelRenderer reads STUARTY_EXPORT_RENDERER: empty is the default, the Go compositor.
type Progress ¶
type Progress struct {
Frame, Total int
}
Progress is the share of the frames written to the encoder.
type RenderConfig ¶
type RenderConfig struct {
Runner *ffmpeg.Runner
Doc *timeline.Document
JobID string
ArtifactsDir string
Fonts *rasterize.FontSet // the bundled fonts when nil
Bands int
}
RenderConfig is what a Renderer needs: the same inputs as an export, without the output.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer composes single frames of a project through the same compositor and decoders as the export (SDD-004 section 9), for the paused frame of the editor and for the views of an agent. It owns a work directory and, while a frame is being made, FFmpeg processes: Close ends both. It is not safe for concurrent use.
func NewRenderer ¶
func NewRenderer(ctx context.Context, cfg RenderConfig) (*Renderer, error)
NewRenderer makes the renderer and its work directory. Each frame is independent: a decoder is not kept open for the next frame. ViewFrame and the paused frame use this.
func NewSequenceRenderer ¶
func NewSequenceRenderer(ctx context.Context, cfg RenderConfig) (*Renderer, error)
NewSequenceRenderer is NewRenderer for frames asked in order, which is how an export reads a clip. Decoders stay open and read ahead. A jump backwards, or of more than the restart gap, starts the process at the new frame. Close ends them. It is not safe for concurrent use, same as Renderer.
func (*Renderer) MixFrom ¶
MixFrom mixes the timeline audio from frame from, for n frames, and hands the result to sink in blocks of stereo float32 at 48 kHz (engine/audio.Mix). The sources are the same ones an export mixes. A range with no sound still calls sink with silence, so a player can keep its clock. n must be at least 1.
func (*Renderer) Render ¶
Render composes frame t at outScale times the project's size. The result is RGBA of round(width*outScale) by round(height*outScale) pixels. Uncovered pixels are opaque unless the plan is transparent, in which case their alpha is 0.
func (*Renderer) RenderSize ¶
RenderSize composes frame t into exactly w by h pixels, scaled by w over the project width, for a caller that owns the rounding of the height (the size table of SDD-003 section 3.11). The layers are placed at the width scale, so the picture differs from Render only by the rounding of the last row.
type Result ¶
type Result struct {
Path string
Format Format
Size int64
DurationMS int64
Frames int
Encoder string
Loudness Loudness
// Width and Height are the pixels of the file when they differ from the project's (a GIF is
// capped at 480 pixels wide); zero means the project's size.
Width, Height int
}
Result is what a successful export produced.