Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotSeekable = errors.New("media: source is not seekable")
ErrNotSeekable is returned by OpenAt when the source has no seekable input.
Functions ¶
func SetFFmpegPath ¶
func SetFFmpegPath(p string)
SetFFmpegPath overrides the binary used for transcoding. Empty resets to "ffmpeg".
func SetLogger ¶ added in v0.3.2
SetLogger sets the logger used by media-package ffmpeg shell readers. Pass nil to disable logging.
func SetStderrLog ¶ added in v0.6.0
func SetStderrLog(on bool)
SetStderrLog toggles the live-tee of ffmpeg stderr to the package logger.
func StderrLogEnabled ¶ added in v0.6.0
func StderrLogEnabled() bool
StderrLogEnabled reports the current setting (read by io.ShellReader).
Types ¶
type EncodeOptions ¶
type EncodeOptions struct {
VideoBitrateKbps int
VideoWidth int
VideoHeight int
VideoFPS int
AudioBitrateKbps int
AudioChannels int
// Tracks limits which tracks to produce. Zero means audio+video.
Tracks Track
}
EncodeOptions tunes the ffmpeg encode for transcoding sources. Zero values become sensible defaults.
type FrameReader ¶
type FrameReader = frameReader
FrameReader is the exported alias for the internal frameReader so other packages in the module can hold one.
func NewOpusFrameReader ¶
func NewOpusFrameReader(r stdio.Reader) (FrameReader, error)
NewOpusFrameReader exposes the internal opus reader for callers that have a raw ogg byte stream (e.g. instances/group_call).
func NewVP8FrameReader ¶
func NewVP8FrameReader(r stdio.Reader, fps int) (FrameReader, error)
NewVP8FrameReader exposes the internal vp8 reader.
type SeekableSource ¶
type SeekableSource interface {
Source
OpenAt(ctx context.Context, offset time.Duration) (*Streams, error)
}
SeekableSource is a Source that can begin playback at an offset. Only file/URL transcode sources implement it; pre-encoded passthrough sources and stdin-fed reader sources do not.
type Source ¶
Source is the public input abstraction. A Source is created lazily; Open spawns whatever processes are needed and returns the encoded audio+video byte streams.
func FromFile ¶
func FromFile(path string, opt EncodeOptions) Source
FromFile streams any ffmpeg-decodable file (mp4, mkv, webm, mp3, wav, ...). Seekable. Pass EncodeOptions{} for defaults.
func FromShell ¶
FromShell parses cmdline as a shell command (handling double-quoted arguments) and spawns it directly via exec — NOT via /bin/sh, so shell metacharacters in filenames cannot inject commands.
The command must produce Opus-in-OGG on stdout for audio or VP8-in-IVF for video. Missing essentials are filled in automatically:
- input-side fast-probe flags (`-analyzeduration 0`, `-probesize 64k`) are inserted before `-i` if absent — cuts ~1-2 s of startup latency.
- output-side flags (`-c:a libopus`, `-f ogg`, opus pacing/codec params, `pipe:1`) for audio, or (`-c:v libvpx`, `-f ivf`, `pipe:1`) for video, are appended if not already present.
Raw PCM output codecs (pcm_s16le, etc.) are still rejected up front since the frame readers can't parse them.
func FromShells ¶ added in v0.5.9
FromShells builds a Source from two separate ffmpeg commands — one for audio, one for video. Either string may be empty to skip that track. Mirrors ntgcalls' MediaDescription(microphone, camera) pattern for users who want full control over both legs.
Each cmd goes through the same auto-flag injection as FromShell, so a minimal `ffmpeg -i movie.mp4` works for either leg.
func FromURL ¶
func FromURL(url string, opt EncodeOptions) Source
FromURL streams from a URL (http(s), hls/.m3u8, rtmp, ...). Seekable. Pass EncodeOptions{} for defaults.
type SourcePath ¶
type SourcePath interface {
InputPath() string
InputArgs() []string
EncodeOpts() EncodeOptions
}
SourcePath is implemented by Sources backed by a plain file path or URL. The RTMP transport uses this to feed ffmpeg directly without going through the Source.Open() OGG/IVF pipeline.
type Streamer ¶
type Streamer struct {
// contains filtered or unexported fields
}
Streamer pulls Samples from a FrameReader at the sample's natural cadence and pushes them to a Writer. Mute (audio) skips WriteSample but keeps the clock advancing. Pause (set via SetPaused) blocks the pull loop on a channel without tearing down the underlying ffmpeg process — the OS pipe buffer absorbs ~1s of OGG bytes while paused; on resume the loop wakes and drains them at real-time pace.
func NewStreamer ¶
func (*Streamer) Done ¶
func (s *Streamer) Done() <-chan struct{}
Done is closed when the streamer has finished (EOF, error, or Stop).
func (*Streamer) IsPaused ¶ added in v0.3.0
IsPaused reports whether the gate is currently blocking the loop.
func (*Streamer) SetPaused ¶ added in v0.3.0
SetPaused gates the run loop without canceling the context or closing the source. While paused the pull loop blocks on a channel; ffmpeg keeps running and its stdout pipe buffers the next ~1s of frames. On resume the loop wakes and resumes at real time.
type Streams ¶
type Streams struct {
Audio stdio.Reader
Video stdio.Reader
// contains filtered or unexported fields
}
Streams is the encoded output of a Source: ogg/Opus audio and/or IVF/VP8 video. A nil reader means that track is absent. Close releases any underlying ffmpeg processes and pipes.