launch

package
v0.1.0-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 28 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package launch is goav's pipeline language: a goav recipe written as text, for command lines, configuration files, and control sockets.

in := file in.webm
v  := in ! video ! decode
v ! resize 1280x720 ! encode vp9 bitrate=2M ! as hd ! file hd.webm
v ! resize 640x360  ! encode vp9 bitrate=800k ! as sd ! file sd.webm
in ! audio ! decode ! encode opus ! file hd.webm, file sd.webm

Compile turns a program into goav Outputs — the values the same recipe written in Go produces, so a program costs nothing at run time and runs, describes, and explains like any recipe:

outs, err := launch.Compile(program, launch.Files(launch.OS()))
err = rt.Run(ctx, outs...)

Programs

A program is statements, one per line or separated by ;, with # comments. A statement is a pipeline: a first step, then operations joined by !, then one or more destinations separated by commas. name := pipeline binds a stream (or an input) to reuse; using a binding twice forks it, and the work before the fork runs once. A line that starts with ! or , continues the statement above it.

A step is an element with settings: positional values first, then key=value. Values are words or quoted text; numbers take k, M, and G suffixes (96k, 2M), durations are Go durations (20ms, 2s), sizes are WxH.

file names a file: at a pipeline's start it is an input, at its end a destination. Every use of one path is one input, or one mux: two pipelines that end at file call.webm write one file. Files are opened and created only when the recipe runs, and only through the FileSystem given to Files.

uri names a URL the same way, and a quoted URL alone is one: "https://cdn.example/in.mp4" ! video ! .... The runtime's schemes resolve it (goav.FromURI), and only for the schemes URIs grants; a file URL is a file, opened through Files.

Elements

Sources: file PATH, uri URL, testsrc video|audio [size= fps= pattern= rate= channels= tone= frames= duration=] [live], and tap NAME (on a running task, see Task).

Operations: video, audio, and stream [id= index=] select an input's stream; decode; encode CODEC [bitrate= fps= keyframe_interval= profile= level= channels= sample_rate= clock_rate= media=] with native adapter settings passed through; resize WxH [mode=exact|fit|fill]; resample RATE CHANNELS; tap NAME; as NAME; buffer block|drop-oldest|drop-newest N, buffer latest|unbounded [max_bytes= max_delay=]; sync NAME [tolerance=] [drop_late] (one timeline per name); playout [NAME]; auto [resample] [resize] [convert]; at X Y (a composite input's position).

Joins: mix(a, b, ...), composite(a, b ! at X Y, ...), select(a, b, ...). Each input is a pipeline yielding a stream. Mix and composite take sync=arrival|pts (sync=pts is goav.ByPTS()): mix(a, b, sync=pts).

Destinations: file PATH [format=], uri URL [format=], hls PATH [segment=] [window=] [parts=], null.

Use adds a host's own sources, stages, encoders, sinks, and joins, with typed settings; Elements lists the vocabulary for help and discovery.

Refusals

A program that cannot compile returns a *Error naming the problem, its line and column, and the fix; Error() underlines the offending text:

launch: 2:14: unknown element "resise"
    in ! video ! resise 1280x720 ! file out.webm
                 ^^^^^^
    did you mean "resize"?

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(program string, options ...Option) ([]goav.Output, error)

Compile turns a program into the Outputs it describes. The Outputs are ordinary goav values — run them with rt.Run, describe them with rt.Describe — and they are exactly the values the same recipe written in Go would produce: a program costs nothing at run time.

outs, err := launch.Compile(`
    in := file in.webm
    v  := in ! video ! decode
    v ! resize 1280x720 ! encode vp9 bitrate=2M ! as hd ! file hd.webm
    v ! resize 640x360  ! encode vp9 bitrate=800k ! as sd ! file sd.webm
`, launch.Files(launch.OS()))

A refusal is a *Error that points at the offending text.

Example

ExampleCompile compiles a program and prints the graph it builds, without running it.

package main

import (
	"fmt"

	"github.com/thesyncim/goav/bundle"
	"github.com/thesyncim/goav/graphrender"
	"github.com/thesyncim/goav/launch"
)

func main() {
	outs, err := launch.Compile(`
		v := testsrc video size=640x360 duration=1s
		v ! resize 320x180 ! encode vp8 ! as small ! null
		v ! encode vp8 bitrate=1M ! as full ! null
	`)
	if err != nil {
		fmt.Println(err)
		return
	}
	spec, err := bundle.Describe(outs...)
	if err != nil {
		fmt.Println(err)
		return
	}
	text, _ := graphrender.RenderURI(spec, "goav:graph")
	fmt.Print(text)
}
Output:
pipeline goav
  source video [generated test video]
  stage select-video [select, type=video]
  stage resize-small [resize, 320x180, exact]
  stage encode-small [frames -> packets, codec=vp8, backend=govpx (go)]
  stage encode-full [frames -> packets, codec=vp8, backend=govpx (go)]
  sink null
  video -> select-video
  select-video -> resize-small
  select-video -> encode-full
  resize-small -> encode-small
  encode-small -> null
  encode-full -> null

Types

type Element

type Element struct {
	// contains filtered or unexported fields
}

Element is one name a program can use: a source that starts a pipeline, an operation on a stream, a destination that ends one, or a join called with streams. The built-ins cover goav's grammar; Use adds your own.

func Encoder

func Encoder[T any](name, summary string, build func(T) (codec.Spec, error)) Element

Encoder defines an operation that encodes a stream with a codec of your own spelling: acme bitrate=128k → s.Encode(spec).

func Join

func Join[T any](name, summary string, build func(T) (pipeline.Stage, error)) Element

Join defines a join called with streams, name(a, b, key=value), that converges them through a custom stage: goav.Join(name, stage, streams...).

func Sink

func Sink[T any](name, summary string, open func(T) (goav.Destination, error)) Element

Sink defines a destination that ends a pipeline.

func Source

func Source[T any](name, summary string, open func(T) (goav.Input, error)) Element

Source defines an element that starts a pipeline with an input. Its settings are T's fields tagged `launch:"name"` (see Size for the value forms); open runs once, when the program compiles.

func Stage

func Stage[T any](name, summary string, build func(T) (pipeline.Stage, error)) Element

Stage defines an operation that runs a custom stage on a stream (s.Do).

type ElementInfo

type ElementInfo struct {
	Name    string `json:"name"`
	Kind    string `json:"kind"` // source, operation, destination, or join
	Summary string `json:"summary"`
	Usage   string `json:"usage"`
}

ElementInfo describes one element for help and capability listings.

func Elements

func Elements(options ...Option) []ElementInfo

Elements lists the vocabulary a program compiled with options can use, by kind, then name.

type Error

type Error struct {
	Line, Column int
	Msg          string
	// Hint is the fix: a corrected spelling, the expected form, or the
	// option that enables an element.
	Hint string
	// Pos and End are byte offsets of the offending span in the program.
	Pos, End int
	// contains filtered or unexported fields
}

Error is a refusal of a program, located in its source: what is wrong, where (1-based line and column), and how to fix it. Error() renders the offending line with the span underlined.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the error that caused the refusal, such as an element's constructor error or a codec setting refusal.

type FileSystem

type FileSystem interface {
	Open(name string) (io.Reader, error)
	Create(name string) (io.Writer, error)
}

FileSystem opens the files a program reads and creates the files it writes.

func Dir

func Dir(root string) (FileSystem, error)

Dir is the files under root and nothing else: a path that escapes root, through .. or a symlink, is refused. A control server hands attached programs a Dir. Each operation opens root for its own duration, so a Dir holds no handle: it needs no Close, and root stays removable.

func OS

func OS() FileSystem

OS is the process's files, as os.Open and os.Create see them.

type Option

type Option func(*config)

Option configures Compile.

func Files

func Files(fs FileSystem) Option

Files lets a program read and write files through fs: file in.webm opens fs.Open("in.webm") when the run starts, and file out.webm creates its output then. Without Files a program touches no files.

func HLS

func HLS(server *hls.Server) Option

HLS packages a program's hls outputs into server, which serves them over HTTP, instead of writing them to its files. Low-latency HLS (parts=) needs it: a server holds the blocking requests LL-HLS players make.

func Task

func Task(task goav.Task) Option

Task compiles a program against a running task, for task.Attach: a pipeline may start at one of its taps, tap live ! encode vp8 ! file p.webm.

func URIs

func URIs(schemes ...string) Option

URIs lets a program read and write URLs of the named schemes, resolved through the schemes of the runtime it runs on: uri "https://cdn/in.mp4", or the URL bare. With no names it grants every scheme the runtime registers. A file URL is a file whatever URIs grants: it opens through the FileSystem given to Files, so a program compiled with Dir stays in its directory. Without URIs a program opens no URLs.

func Use

func Use(elements ...Element) Option

Use adds elements to the program's vocabulary; an element named like a built-in replaces it.

type Size

type Size struct{ Width, Height int }

Size is a width and height, written WxH: resize 1280x720.

Jump to

Keyboard shortcuts

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