pion/webrtc · error

codec is unset

Error message

codec is unset

What it means

Sentinel error returned when the writer's internal codec state is unset so no IVF FOURCC can be selected. It fires in writeHeader (no FOURCC like "VP80"/"VP90"/"AV01" can be stamped into the 32-byte file header) and in WriteRTP's codec dispatch default branch. In normal use NewWith defaults to VP8, so this occurs only when the writer was constructed without going through NewWith or its state was left unset.

Source

Thrown at pkg/media/ivfwriter/ivfwriter.go:21

	// FOURCC
	switch i.codec {
	case codecVP8:
		copy(header[8:], "VP80")
	case codecVP9:
		copy(header[8:], "VP90")
	case codecAV1:
		copy(header[8:], "AV01")
	default:
		return errCodecUnset
	}

	binary.LittleEndian.PutUint16(header[12:], i.videoWidth)          // Width in pixels
	binary.LittleEndian.PutUint16(header[14:], i.videoHeight)         // Height in pixels
	binary.LittleEndian.PutUint32(header[16:], i.timebaseDenominator) // Framerate denominator
	binary.LittleEndian.PutUint32(header[20:], i.timebaseNumerator)   // Framerate numerator

View on GitHub (pinned to 8c25dc09fa)

Solutions

  1. Construct the writer with NewWith, which defaults the codec to VP8 when none was chosen
  2. Pass WithCodec(mimeTypeVP8|VP9|AV1) as an option to NewWith to select a codec explicitly
  3. If writing header manually, ensure i.codec is set before calling writeHeader
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/media/ivfwriter/ivfwriter.go:21 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pion/webrtc@8c25dc09fa (2026-09-03). Data as JSON: /api/errors/5cfe475b9e257ae9. Report an issue: GitHub.