Documentation
¶
Index ¶
- Variables
- type AudioFrame
- type Frame
- type ImageOpt
- type RGB
- type RGB24
- type SubtitleFrame
- type VideoFrame
- func (f *VideoFrame) AllocateBuffers() error
- func (f *VideoFrame) Close() error
- func (f *VideoFrame) DisplaySize() (int, int)
- func (f *VideoFrame) FromImage(src image.Image) error
- func (f *VideoFrame) Image(opt ...ImageOpt) (image.Image, error)
- func (f *VideoFrame) IncPts(v int64)
- func (f *VideoFrame) MakeWritable() error
- func (f *VideoFrame) SetStream(stream int)
- func (f *VideoFrame) Stream() int
Constants ¶
This section is empty.
Variables ¶
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) 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).
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
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.
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
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
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
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
ColorModel returns the RGB color model.
func (*RGB24) PixOffset ¶ added in v1.11.1
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
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) 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).