Documentation
¶
Overview ¶
Package frame provides video and audio frame types for media processing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AudioFormat ¶
type AudioFormat int
AudioFormat represents the audio sample format.
const ( // AudioFormatS16 is signed 16-bit little-endian samples. AudioFormatS16 AudioFormat = iota // AudioFormatF32 is 32-bit float samples. AudioFormatF32 )
func (AudioFormat) String ¶
func (f AudioFormat) String() string
String returns the string representation of the audio format.
type AudioFrame ¶
type AudioFrame struct {
// SampleRate is the audio sample rate in Hz.
SampleRate int
// Channels is the number of audio channels.
Channels int
// Format is the sample format.
Format AudioFormat
// Samples contains the audio samples.
// For S16 format: interleaved int16 samples as []byte
// For F32 format: interleaved float32 samples as []byte
Samples []byte
// NumSamples is the number of samples per channel.
NumSamples int
// Timestamp is the presentation timestamp.
Timestamp time.Duration
// PTS is the RTP timestamp.
PTS uint32
// contains filtered or unexported fields
}
AudioFrame represents decoded audio samples.
func NewAudioFrameF32 ¶
func NewAudioFrameF32(sampleRate, channels, numSamples int) *AudioFrame
NewAudioFrameF32 creates a new audio frame with F32 format.
func NewAudioFrameFromS16 ¶
func NewAudioFrameFromS16(samples []int16, sampleRate, channels int) *AudioFrame
NewAudioFrameFromS16 creates an audio frame from existing S16 samples. The samples slice is expected to be interleaved (L, R, L, R, ...) for stereo. numSamples should be samples per channel, so total slice length = numSamples * channels.
func NewAudioFrameS16 ¶
func NewAudioFrameS16(sampleRate, channels, numSamples int) *AudioFrame
NewAudioFrameS16 creates a new audio frame with S16 format.
func (*AudioFrame) Clone ¶
func (f *AudioFrame) Clone() *AudioFrame
Clone creates a deep copy of the frame.
func (*AudioFrame) Duration ¶
func (f *AudioFrame) Duration() time.Duration
Duration returns the duration of the audio in this frame.
func (*AudioFrame) Release ¶
func (f *AudioFrame) Release()
Release returns the frame to its pool for reuse.
func (*AudioFrame) SamplesF32 ¶
func (f *AudioFrame) SamplesF32() []float32
SamplesF32 returns the samples as float32 slice. Only valid for AudioFormatF32 frames.
func (*AudioFrame) SamplesS16 ¶
func (f *AudioFrame) SamplesS16() []int16
SamplesS16 returns the samples as int16 slice. Only valid for AudioFormatS16 frames.
type AudioFramePool ¶
type AudioFramePool struct {
// contains filtered or unexported fields
}
AudioFramePool manages reusable audio frames to reduce allocations.
func NewAudioFramePool ¶
func NewAudioFramePool(sampleRate, channels, numSamples int, format AudioFormat, poolSize int) *AudioFramePool
NewAudioFramePool creates a pool for audio frames.
func (*AudioFramePool) Get ¶
func (p *AudioFramePool) Get() *AudioFrame
Get returns a frame from the pool or allocates a new one.
func (*AudioFramePool) Put ¶
func (p *AudioFramePool) Put(f *AudioFrame)
Put returns a frame to the pool.
type PixelFormat ¶
type PixelFormat int
PixelFormat represents the pixel format of a video frame.
const ( // PixelFormatI420 is the standard YUV 4:2:0 planar format. // Y plane followed by U plane followed by V plane. // Most commonly used format for video encoding. PixelFormatI420 PixelFormat = iota // PixelFormatNV12 is YUV 4:2:0 semi-planar format. // Y plane followed by interleaved UV plane. // Common on hardware encoders (VideoToolbox, VAAPI). PixelFormatNV12 // PixelFormatNV21 is YUV 4:2:0 semi-planar format. // Y plane followed by interleaved VU plane. // Common on Android cameras. PixelFormatNV21 // PixelFormatRGBA is 32-bit RGBA format. PixelFormatRGBA // PixelFormatBGRA is 32-bit BGRA format. PixelFormatBGRA )
func (PixelFormat) String ¶
func (f PixelFormat) String() string
String returns the string representation of the pixel format.
type VideoFrame ¶
type VideoFrame struct {
// Width of the frame in pixels.
Width int
// Height of the frame in pixels.
Height int
// Format specifies the pixel format.
Format PixelFormat
// Data contains the pixel data.
// For I420: [Y, U, V] planes
// For NV12/NV21: [Y, UV] planes
// For RGBA/BGRA: single plane
Data [][]byte
// Stride is the number of bytes per row for each plane.
Stride []int
// Timestamp is the presentation timestamp.
Timestamp time.Duration
// PTS is the RTP timestamp (90kHz clock for video).
PTS uint32
// IsKeyframe indicates if this is an I-frame.
IsKeyframe bool
// contains filtered or unexported fields
}
VideoFrame represents a decoded video frame.
func NewI420Frame ¶
func NewI420Frame(width, height int) *VideoFrame
NewI420Frame creates a new I420 video frame with allocated buffers.
func NewNV12Frame ¶
func NewNV12Frame(width, height int) *VideoFrame
NewNV12Frame creates a new NV12 video frame with allocated buffers.
func (*VideoFrame) Clone ¶
func (f *VideoFrame) Clone() *VideoFrame
Clone creates a deep copy of the frame.
func (*VideoFrame) Release ¶
func (f *VideoFrame) Release()
Release returns the frame to its pool for reuse. After calling Release, the frame must not be used.
func (*VideoFrame) UPlane ¶
func (f *VideoFrame) UPlane() []byte
UPlane returns the U plane data for I420 format. Returns nil for other formats.
func (*VideoFrame) UVPlane ¶
func (f *VideoFrame) UVPlane() []byte
UVPlane returns the interleaved UV plane for NV12/NV21 formats. Returns nil for other formats.
func (*VideoFrame) VPlane ¶
func (f *VideoFrame) VPlane() []byte
VPlane returns the V plane data for I420 format. Returns nil for other formats.
func (*VideoFrame) YPlane ¶
func (f *VideoFrame) YPlane() []byte
YPlane returns the Y plane data for YUV formats. Returns nil for non-YUV formats.
type VideoFramePool ¶
type VideoFramePool struct {
// contains filtered or unexported fields
}
VideoFramePool manages reusable video frames to reduce allocations.
func NewVideoFramePool ¶
func NewVideoFramePool(width, height int, format PixelFormat, poolSize int) *VideoFramePool
NewVideoFramePool creates a pool for video frames of a specific size and format.
func (*VideoFramePool) Get ¶
func (p *VideoFramePool) Get() *VideoFrame
Get returns a frame from the pool or allocates a new one.
func (*VideoFramePool) Put ¶
func (p *VideoFramePool) Put(f *VideoFrame)
Put returns a frame to the pool.