Documentation
¶
Overview ¶
Package codec provides low-latency video encoding, decoding and hardware capability probing on top of NSGo Media's bundled FFmpeg libraries.
Encoders are configured for interactive streaming: no B-frames, low-delay settings, on-demand keyframes with inline parameter sets (Annex B), and dynamic bit-rate updates. Decoders prefer platform hardware acceleration and fall back to software automatically.
Index ¶
Constants ¶
const (
H264 = "h264"
)
Codec names match FFmpeg's short codec names, for use in capability negotiation handshakes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessUnit ¶
AccessUnit is one encoded video frame in Annex B format. Keyframes carry inline SPS/PPS so a decoder can recover immediately after dropped frames.
type Capability ¶
type Capability struct {
// Codec is the standard codec name, such as H264 ("h264").
Codec string
// Name is the underlying FFmpeg codec or hardware backend name
// (e.g. "h264_videotoolbox", "h264_nvenc", "h264_vaapi", "libopenh264").
Name string
// Hardware reports whether the implementation uses hardware acceleration.
Hardware bool
}
Capability describes an encoder or decoder available on this machine.
func Decoders ¶
func Decoders() ([]Capability, error)
Decoders probes the machine's available video decoders, ordered with hardware acceleration first and software fallback after.
func Encoders ¶
func Encoders() ([]Capability, error)
Encoders probes the machine's available video encoders, ordered with preferred hardware encoders first and software fallbacks after. Each reported encoder has been verified to open on the current system.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes Annex B video access units into RGBA images ready for an NSGo view (core.ImageSource{Pixels: img}). It prefers hardware decoding and falls back to software automatically on failure.
func NewDecoder ¶
func NewDecoder(cfg DecoderConfig) (*Decoder, error)
NewDecoder opens a low-latency video decoder, preferring the platform's hardware decoder and falling back to software when unavailable.
func (*Decoder) Decode ¶
Decode feeds one Annex B access unit and returns the decoded picture as an *image.RGBA, or (nil, nil) if no picture is ready yet.
type DecoderConfig ¶
type DecoderConfig struct {
// Codec is the stream codec name; defaults to H264 when empty.
Codec string
// SoftwareOnly skips hardware acceleration and decodes in software.
SoftwareOnly bool
}
DecoderConfig configures a low-latency video decoder.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes uncompressed BGRA or NV12 frames into low-latency video access units without B-frames.
func NewEncoder ¶
func NewEncoder(cfg EncoderConfig) (*Encoder, error)
NewEncoder opens a low-latency video encoder for cfg, preferring hardware encoders and falling back to available alternatives unless cfg.Name or cfg.SoftwareOnly restricts the choice.
func (*Encoder) Encode ¶
func (e *Encoder) Encode(frame Frame, keyframe bool) (AccessUnit, error)
Encode encodes frame into a single AccessUnit. Setting keyframe forces an IDR keyframe with inline SPS/PPS so a remote decoder can recover after packet or frame loss.
func (*Encoder) SetBitRate ¶
SetBitRate changes the target bit rate (in bits per second) while running.
type EncoderConfig ¶
type EncoderConfig struct {
// Codec is the target codec name; defaults to H264 when empty.
Codec string
// Width and Height are the picture dimensions in pixels (must be positive
// and even for 4:2:0 encoding).
Width int
Height int
// FPS is the nominal frame rate used for rate control; defaults to 60.
FPS int
// BitRate is the target bit rate in bits per second; defaults to 8 Mbps.
BitRate int
// SoftwareOnly skips hardware encoders and opens a software encoder.
SoftwareOnly bool
// Name, when non-empty, forces a specific FFmpeg encoder backend
// (e.g. "h264_nvenc", "h264_mf", "libopenh264").
Name string
}
EncoderConfig configures a low-latency video encoder.
type Frame ¶
type Frame struct {
Format PixelFormat
Width int
Height int
// Data holds BGRA pixels or, for NV12, the Y plane (and optionally the
// interleaved UV plane immediately after Stride*Height when UV is nil).
Data []byte
// Stride is the byte stride of Data rows. When zero, it defaults to
// Width*4 for BGRA and Width for NV12.
Stride int
// UV optionally holds the NV12 interleaved chroma plane separately from
// Data. Ignored for BGRA.
UV []byte
// UVStride is the byte stride of UV rows. When zero, it defaults to
// Stride (or Width).
UVStride int
}
Frame is an uncompressed video frame passed to Encoder.Encode.
type PixelFormat ¶
type PixelFormat int
PixelFormat identifies the layout of an uncompressed input Frame.
const ( // BGRA is packed 32-bit BGRA (4 bytes per pixel: B, G, R, A). BGRA PixelFormat = iota // NV12 is semi-planar 4:2:0 YUV: a full-resolution Y plane followed by // a half-resolution interleaved UV plane. NV12 )
func (PixelFormat) String ¶
func (f PixelFormat) String() string
String returns the pixel format's name.