frame

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 4 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

View Source
var RGB24Model = color.ModelFunc(rgbModel)

RGB24Model is the color model for RGB24 images, converting any color to 24-bit RGB format.

Functions

This section is empty.

Types

type AudioFrame

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

AudioFrame is a decoded (or to-be-encoded) audio frame.

func NewAudioFrame

func NewAudioFrame(stream int) (*AudioFrame, error)

NewAudioFrame allocates an audio frame for the given stream.

func (*AudioFrame) AllocateBuffers

func (f *AudioFrame) AllocateBuffers() error

AllocateBuffers allocates sample/pixel data buffers for the frame based on its currently-set format fields (sample format, channel layout and number of samples for audio; width, height and pixel format for video).

func (*AudioFrame) Close

func (f *AudioFrame) Close() error

Close releases the frame's resources.

func (*AudioFrame) IncPts

func (f *AudioFrame) IncPts(v int64)

IncPts advances the frame's Pts by v.

func (*AudioFrame) MakeWritable

func (f *AudioFrame) MakeWritable() error

MakeWritable ensures the frame's data buffers are exclusively owned before mutating them in place. Needed before reusing the same Frame for a second call to Encoder.Encode, since the encoder may retain a reference to the buffer from the first call.

func (*AudioFrame) SetStream added in v1.9.3

func (f *AudioFrame) SetStream(stream int)

SetStream reassigns the stream this frame is tagged as belonging to - used when the stream numbering a frame was decoded with doesn't match the numbering an output needs it encoded under (e.g. task/encoder, which extracts a subset of an input's streams into a densely, zero-based renumbered output).

func (*AudioFrame) Stream

func (f *AudioFrame) Stream() int

type Frame

type Frame interface {
	Stream() int   // The stream this frame belongs to
	SetStream(int) // Reassign the stream this frame belongs to
	Close() error  // Release the frame's resources
}

Frame is the decoded (or to-be-encoded) output for a single stream. It is implemented by AudioFrame and VideoFrame (both backed by an AVFrame - the same underlying FFmpeg struct for either kind) and SubtitleFrame (backed by an AVSubtitle, which FFmpeg represents and codes completely separately from AVFrame, via its own legacy encode/decode API).

type ImageOpt added in v1.11.1

type ImageOpt func(*imageOpts) error

ImageOpt is an option for VideoFrame.Image

func WithImageSize added in v1.11.1

func WithImageSize(width, height int) ImageOpt

WithImageSize returns an image of the frame scaled to a size, with square pixels. Either can be zero, to keep the aspect ratio the frame is displayed with, and both zero is the size it's displayed at.

func WithSquarePixels added in v1.11.1

func WithSquarePixels() ImageOpt

WithSquarePixels returns an image of the frame at the size it's displayed, with its sample aspect ratio applied, so its pixels are square, as an anamorphic video's, such as a DVD's, aren't.

type RGB added in v1.11.1

type RGB struct {
	R, G, B uint8
}

RGB represents a 24-bit color consisting of red, green, and blue components. Each component is an 8-bit value, giving a total of 16,777,216 possible colors.

func (RGB) RGBA added in v1.11.1

func (c RGB) RGBA() (r, g, b, a uint32)

RGBA returns the alpha-premultiplied red, green, blue and alpha values for the RGB color. The alpha value is always fully opaque (0xFFFF). The red, green, and blue values are returned in the range [0, 0xFFFF].

type RGB24 added in v1.11.1

type RGB24 struct {
	// Pix holds the image's pixels, in RGB order. The pixel at (x, y)
	// starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*3].
	Pix []uint8
	// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
	Stride int
	// Rect is the image's bounds.
	Rect image.Rectangle
}

RGB24 represents an in-memory image with 24-bit RGB color. Each pixel is stored as three consecutive bytes in RGB order. This format is commonly used for uncompressed image data from video frames.

func NewRGB24 added in v1.11.1

func NewRGB24(r image.Rectangle) *RGB24

NewRGB24 returns a new RGB24 image with the given bounds. The image's pixels are initialized to zero (black).

func (*RGB24) At added in v1.11.1

func (p *RGB24) At(x, y int) color.Color

At returns the color of the pixel at (x, y). At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid. At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right pixel.

func (*RGB24) Bounds added in v1.11.1

func (p *RGB24) Bounds() image.Rectangle

Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).

func (*RGB24) ColorModel added in v1.11.1

func (p *RGB24) ColorModel() color.Model

ColorModel returns the RGB color model.

func (*RGB24) PixOffset added in v1.11.1

func (p *RGB24) PixOffset(x, y int) int

PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).

func (*RGB24) RGBAt added in v1.11.1

func (p *RGB24) RGBAt(x, y int) RGB

RGBAt returns the RGB color of the pixel at (x, y). If the point is outside the image bounds, RGBAt returns zero RGB.

func (*RGB24) Set added in v1.11.1

func (p *RGB24) Set(x, y int, c color.Color)

Set sets the pixel at (x, y) to the given color. If the point is outside the image bounds, Set is a no-op.

type SubtitleFrame

type SubtitleFrame struct {
	*ff.AVSubtitle
	// contains filtered or unexported fields
}

SubtitleFrame is a decoded (or to-be-encoded) subtitle.

func NewSubtitleFrame

func NewSubtitleFrame(stream int, sub *ff.AVSubtitle) *SubtitleFrame

NewSubtitleFrame wraps an already-populated AVSubtitle - either decoded by Decoder, or built by the caller for Encoder.Encode - for the given stream.

func (*SubtitleFrame) Close

func (f *SubtitleFrame) Close() error

Close releases the subtitle's resources.

func (*SubtitleFrame) SetStream added in v1.9.3

func (f *SubtitleFrame) SetStream(stream int)

SetStream reassigns the stream this frame is tagged as belonging to - see mediaFrame.SetStream.

func (*SubtitleFrame) Stream

func (f *SubtitleFrame) Stream() int

type VideoFrame

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

VideoFrame is a decoded (or to-be-encoded) video frame.

func NewVideoFrame

func NewVideoFrame(stream int) (*VideoFrame, error)

NewVideoFrame allocates a video frame for the given stream.

func (*VideoFrame) AllocateBuffers

func (f *VideoFrame) AllocateBuffers() error

AllocateBuffers allocates sample/pixel data buffers for the frame based on its currently-set format fields (sample format, channel layout and number of samples for audio; width, height and pixel format for video).

func (*VideoFrame) Close

func (f *VideoFrame) Close() error

Close releases the frame's resources.

func (*VideoFrame) DisplaySize added in v1.11.1

func (f *VideoFrame) DisplaySize() (int, int)

DisplaySize returns the size the frame is displayed at, with square pixels: its size with its sample aspect ratio (the width of a pixel divided by its height) applied to its width. An unknown or invalid ratio is square.

func (*VideoFrame) FromImage added in v1.11.1

func (f *VideoFrame) FromImage(src image.Image) error

FromImage copies an image into the frame, reallocating it if the pixel format or size is different, and keeping its timebase and pts. The image is one of *image.NRGBA or *image.RGBA (to RGBA, whose premultiplied alpha is converted), *image.Gray (to GRAY8), *RGB24 (to RGB24), or *image.YCbCr with any subsample ratio except 4:1:0 (to planar YUV).

func (*VideoFrame) Image added in v1.11.1

func (f *VideoFrame) Image(opt ...ImageOpt) (image.Image, error)

Image returns an image of the frame. Without options, it shares the frame's pixels, so it's only valid until the frame is closed or reused. With WithSquarePixels or WithImageSize, it's a copy, scaled so its pixels are square. The pixel format is one of RGBA, GRAY8, RGB24, or a planar YUV format (YUV411P, YUV420P, YUV422P, YUV440P or YUV444P); convert other formats first, such as with a writer.Resampler. An RGBA frame is an *image.NRGBA, as FFmpeg's alpha isn't premultiplied.

func (*VideoFrame) IncPts

func (f *VideoFrame) IncPts(v int64)

IncPts advances the frame's Pts by v.

func (*VideoFrame) MakeWritable

func (f *VideoFrame) MakeWritable() error

MakeWritable ensures the frame's data buffers are exclusively owned before mutating them in place. Needed before reusing the same Frame for a second call to Encoder.Encode, since the encoder may retain a reference to the buffer from the first call.

func (*VideoFrame) SetStream added in v1.9.3

func (f *VideoFrame) SetStream(stream int)

SetStream reassigns the stream this frame is tagged as belonging to - used when the stream numbering a frame was decoded with doesn't match the numbering an output needs it encoded under (e.g. task/encoder, which extracts a subset of an input's streams into a densely, zero-based renumbered output).

func (*VideoFrame) Stream

func (f *VideoFrame) Stream() int

Jump to

Keyboard shortcuts

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