Documentation
¶
Overview ¶
Package videocodec binds the native video codecs a WebRTC peer encodes and decodes with: libvpx for VP8, and OpenH264 for H.264. Both are loaded at run time through purego from the shared libraries a distribution installs, so the build needs no C toolchain.
The frames the codecs exchange are I420 (planar YUV 4:2:0), converted to and from packed RGB by I420ToRGB and RGBToI420.
Index ¶
Constants ¶
const ( DefaultBitrate = 500000 MinBitrate = 250000 MaxBitrate = 1500000 )
The VP8 encoder's bitrates, in bits per second: the one it starts at, and the range a receiver's estimate is held to.
Variables ¶
var ( // ErrVPXNotAvailable is returned when libvpx cannot be loaded, so a caller // can tell a missing install from a failure of the codec. ErrVPXNotAvailable = errors.New("videocodec: libvpx not available") // ErrOpenH264NotAvailable is returned when libopenh264 cannot be loaded. ErrOpenH264NotAvailable = errors.New("videocodec: libopenh264 not available") )
Errors from loading the libraries.
Functions ¶
Types ¶
type H264Decoder ¶
type H264Decoder struct {
// contains filtered or unexported fields
}
H264Decoder decodes H.264 access units, in Annex B form, to I420 with OpenH264. It is safe for concurrent use.
func NewH264Decoder ¶
func NewH264Decoder(libPath string) (*H264Decoder, error)
NewH264Decoder builds an H.264 decoder over libopenh264, loaded from libPath or by its conventional names when libPath is empty.
type I420Frame ¶
I420Frame is a picture in I420: a full-resolution luma plane followed by two chroma planes at half the width and height, rounded up. The rows of each plane are packed, with no padding.
func NewI420Frame ¶
NewI420Frame allocates a black picture of the given size.
func RGBToI420 ¶
RGBToI420 converts packed 8-bit RGB, three bytes a pixel, to a picture, with the BT.601 limited-range coefficients. Each chroma sample is taken from the average of the pixels it covers.
type VP8Decoder ¶
type VP8Decoder struct {
// contains filtered or unexported fields
}
VP8Decoder decodes VP8 frames to I420 with libvpx. It is safe for concurrent use.
func NewVP8Decoder ¶
func NewVP8Decoder(libPath string) (*VP8Decoder, error)
NewVP8Decoder builds a VP8 decoder over libvpx, loaded from libPath or by its conventional names when libPath is empty.
type VP8Encoder ¶
type VP8Encoder struct {
// contains filtered or unexported fields
}
VP8Encoder encodes I420 frames to VP8 with libvpx, configured for live, constant-bitrate video. It is safe for concurrent use.
func NewVP8Encoder ¶
func NewVP8Encoder(libPath string) (*VP8Encoder, error)
NewVP8Encoder builds a VP8 encoder over libvpx, loaded from libPath or by its conventional names when libPath is empty. The codec itself is created with the first frame, at that frame's size.
func (*VP8Encoder) Encode ¶
Encode encodes one frame, presented at pts on the 90 kHz video clock, and returns the frame's compressed data. forceKeyframe makes it a keyframe. The codec is created again when the frame size changes.
func (*VP8Encoder) SetTargetBitrate ¶
func (e *VP8Encoder) SetTargetBitrate(bitrate int)
SetTargetBitrate changes the bitrate the encoder aims for, held between MinBitrate and MaxBitrate. It applies from the next frame.
func (*VP8Encoder) TargetBitrate ¶
func (e *VP8Encoder) TargetBitrate() int
TargetBitrate is the bitrate the encoder aims for, in bits per second.