Documentation
¶
Overview ¶
Package video provides YUV video frame format definitions, frame filling, and format conversion utilities shared across the switchframe pipeline.
Index ¶
- func Downconvert422_10to420(src []byte, dst []byte, width, height int) error
- func FillBlack(buf []byte, f Format, w, h int)
- func FillFrame(buf []byte, f Format, w, h, y, cb, cr int)
- func IsNominalPTSDelta(delta int64) bool
- func NewBlackFrame(f Format, w, h int) []byte
- func NewFrame(f Format, w, h, y, cb, cr int) []byte
- func Upconvert420to422_10(src []byte, dst []byte, width, height int) error
- func ValidateConvertParams(width, height int) error
- func YUV420FrameSize(w, h int) int
- func YUV422_10bitFrameSize(w, h int) int
- type Format
- func (f Format) BlackY() int
- func (f Format) BytesPerSample() int
- func (f Format) CbOffset(w, h int) int
- func (f Format) ChromaHeight(h int) int
- func (f Format) ChromaPlaneSize(w, h int) int
- func (f Format) ChromaWidth(w int) int
- func (f Format) CrOffset(w, h int) int
- func (f Format) FrameSize(w, h int) int
- func (f Format) MaxSampleValue() int
- func (f Format) NeutralChroma() int
- func (f Format) String() string
- func (f Format) WhiteY() int
- func (f Format) YPlaneSize(w, h int) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Downconvert422_10to420 ¶
Downconvert422_10to420 converts a YUV422P10LE frame to YUV420P 8-bit. This performs:
- Bit-depth demotion: 10-bit to 8-bit ((val + 2) >> 2, rounded)
- 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 ¶
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 ¶
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 ¶
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 ¶
NewBlackFrame allocates and returns a new frame filled with BT.709 limited-range black for the given format and dimensions.
func Upconvert420to422_10 ¶
Upconvert420to422_10 converts a YUV420P 8-bit frame to YUV422P10LE. This performs:
- Bit-depth promotion: 8-bit to 10-bit (val * 4, i.e. val << 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 ¶
ValidateConvertParams checks common preconditions for format conversion.
func YUV420FrameSize ¶
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 ¶
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 ¶
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 ¶
BytesPerSample returns the number of bytes per luma/chroma sample.
func (Format) ChromaHeight ¶
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 ¶
ChromaPlaneSize returns the size of one chroma plane (Cb or Cr) in bytes.
func (Format) ChromaWidth ¶
ChromaWidth returns the chroma plane width (half luma width for both 420 and 422).
func (Format) MaxSampleValue ¶
MaxSampleValue returns the maximum representable sample value. 255 for 8-bit, 1023 for 10-bit.
func (Format) NeutralChroma ¶
NeutralChroma returns the neutral (zero-color) value for Cb/Cr channels. 128 for 8-bit, 512 for 10-bit.
func (Format) WhiteY ¶
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 ¶
YPlaneSize returns the Y plane size in bytes.