video

package
v0.0.0-...-3c84d77 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package video provides YUV video frame format definitions, frame filling, and format conversion utilities shared across the switchframe pipeline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Downconvert422_10to420

func Downconvert422_10to420(src []byte, dst []byte, width, height int) error

Downconvert422_10to420 converts a YUV422P10LE frame to YUV420P 8-bit. This performs:

  1. Bit-depth demotion: 10-bit to 8-bit ((val + 2) >> 2, rounded)
  2. Chroma downsample: 4:2:2 to 4:2:0 (average pairs of vertical rows)

src must be at least w*h*4 bytes (YUV422P10LE). dst must be at least w*h*3/2 bytes (YUV420P 8-bit). Width and height must both be even and positive.

func FillBlack

func FillBlack(buf []byte, f Format, w, h int)

FillBlack fills buf with BT.709 limited-range black for the given format. 8-bit: Y=16, Cb=Cr=128. 10-bit: Y=64, Cb=Cr=512. buf must be at least f.FrameSize(w, h) bytes.

func FillFrame

func FillFrame(buf []byte, f Format, w, h, y, cb, cr int)

FillFrame fills buf with uniform Y, Cb, Cr sample values for the given format. For 8-bit formats, values are stored as bytes. For 10-bit formats, values are stored as little-endian uint16. Width and height must be positive and even. buf must be at least f.FrameSize(w, h) bytes.

func IsNominalPTSDelta

func IsNominalPTSDelta(delta int64) bool

IsNominalPTSDelta reports whether a 90 kHz PTS delta matches a standard video frame duration. Integer rates (24/25/30/50/60 fps) are matched exactly. NTSC rational rates (23.976, 29.97, 59.94 fps) are matched with a +1 tick tolerance to accommodate Bresenham-distributed remainder from the 90000 × den / num division.

Intended for diagnostic inter-frame delta checks in the engine pipeline: a true result means "this is what we expect at one of the broadcast frame rates we support"; a false result means the caller should log or count an anomaly (dropped frame, two-frame gap, non-monotonic PTS, etc.).

func NewBlackFrame

func NewBlackFrame(f Format, w, h int) []byte

NewBlackFrame allocates and returns a new frame filled with BT.709 limited-range black for the given format and dimensions.

func NewFrame

func NewFrame(f Format, w, h, y, cb, cr int) []byte

NewFrame allocates and returns a new frame filled with uniform Y, Cb, Cr values.

func Upconvert420to422_10

func Upconvert420to422_10(src []byte, dst []byte, width, height int) error

Upconvert420to422_10 converts a YUV420P 8-bit frame to YUV422P10LE. This performs:

  1. Bit-depth promotion: 8-bit to 10-bit (val * 4, i.e. val << 2)
  2. Chroma upsample: 4:2:0 to 4:2:2 (vertical interpolation of chroma rows)

src must be at least w*h*3/2 bytes (YUV420P 8-bit). dst must be at least w*h*4 bytes (YUV422P10LE). Width and height must both be even and positive.

The multiplication by 4 maps limited-range values correctly: 16->64 (black), 235->940 (white), 128->512 (neutral chroma).

func ValidateConvertParams

func ValidateConvertParams(width, height int) error

ValidateConvertParams checks common preconditions for format conversion.

func YUV420FrameSize

func YUV420FrameSize(w, h int) int

YUV420FrameSize returns the byte size of a YUV420P 8-bit frame (w*h*3/2). Convenience function for the common case — equivalent to YUV420_8bit.FrameSize(w, h).

func YUV422_10bitFrameSize

func YUV422_10bitFrameSize(w, h int) int

YUV422_10bitFrameSize returns the byte size of a YUV422P10LE frame (w*h*4). Convenience function for the 10-bit case — equivalent to YUV422_10bit.FrameSize(w, h).

Types

type Format

type Format int

Format defines the pixel format and bit depth for YUV video frames.

const (
	// YUV420_8bit is planar YUV 4:2:0 at 8 bits per sample (standard broadcast).
	// Frame size: w*h*3/2. Layout: Y (w*h) + Cb (w/2 * h/2) + Cr (w/2 * h/2).
	YUV420_8bit Format = iota
	// YUV422_10bit is planar YUV 4:2:2 at 10 bits per sample (professional broadcast).
	// Frame size: w*h*4. Layout: Y (w*h*2) + Cb (w/2 * h * 2) + Cr (w/2 * h * 2).
	YUV422_10bit
)

func (Format) BlackY

func (f Format) BlackY() int

BlackY returns the black level for the Y (luma) channel. BT.709 limited range: 16 for 8-bit, 64 for 10-bit.

func (Format) BytesPerSample

func (f Format) BytesPerSample() int

BytesPerSample returns the number of bytes per luma/chroma sample.

func (Format) CbOffset

func (f Format) CbOffset(w, h int) int

CbOffset returns the byte offset of the Cb plane in a planar frame.

func (Format) ChromaHeight

func (f Format) ChromaHeight(h int) int

ChromaHeight returns the chroma plane height. For 4:2:0 this is half the luma height; for 4:2:2 it equals luma height.

func (Format) ChromaPlaneSize

func (f Format) ChromaPlaneSize(w, h int) int

ChromaPlaneSize returns the size of one chroma plane (Cb or Cr) in bytes.

func (Format) ChromaWidth

func (f Format) ChromaWidth(w int) int

ChromaWidth returns the chroma plane width (half luma width for both 420 and 422).

func (Format) CrOffset

func (f Format) CrOffset(w, h int) int

CrOffset returns the byte offset of the Cr plane in a planar frame.

func (Format) FrameSize

func (f Format) FrameSize(w, h int) int

FrameSize returns the total frame size in bytes (Y + Cb + Cr).

func (Format) MaxSampleValue

func (f Format) MaxSampleValue() int

MaxSampleValue returns the maximum representable sample value. 255 for 8-bit, 1023 for 10-bit.

func (Format) NeutralChroma

func (f Format) NeutralChroma() int

NeutralChroma returns the neutral (zero-color) value for Cb/Cr channels. 128 for 8-bit, 512 for 10-bit.

func (Format) String

func (f Format) String() string

String returns the FFmpeg-style pixel format name.

func (Format) WhiteY

func (f Format) WhiteY() int

WhiteY returns the white level for the Y (luma) channel. BT.709 limited range: 235 for 8-bit, 940 for 10-bit.

func (Format) YPlaneSize

func (f Format) YPlaneSize(w, h int) int

YPlaneSize returns the Y plane size in bytes.

Jump to

Keyboard shortcuts

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