pion/webrtc · error

invalid media timebase

Error message

invalid media timebase

What it means

errInvalidMediaTimebase is returned when an IVF file header declares a zero timebase numerator or denominator. The timebase converts the header's timebase to presentation timestamps, so a zero value would cause division by zero and meaningless timestamps. The reader refuses to parse such files. It indicates a corrupt, truncated, or badly generated IVF file.

Source

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

import (
	"encoding/binary"
	"errors"
	"io"
	"os"

	"github.com/pion/rtp"
	"github.com/pion/rtp/codecs"
	"github.com/pion/rtp/codecs/av1/obu"
)

var (
	errFileNotOpened        = errors.New("file not opened")
	errInvalidNilPacket     = errors.New("invalid nil packet")
	errCodecUnset           = errors.New("codec is unset")
	errCodecAlreadySet      = errors.New("codec is already set")
	errNoSuchCodec          = errors.New("no codec for this MimeType")
	errInvalidMediaTimebase = errors.New("invalid media timebase")
)

type (
	codec int

	// IVFWriter is used to take RTP packets and write them to an IVF on disk.
	IVFWriter struct {
		ioWriter     io.Writer
		count        uint64
		seenKeyFrame bool

		codec codec

		timebaseDenominator uint32
		timebaseNumerator   uint32
		firstFrameTimestamp uint32
		clockRate           uint64
		videoWidth          uint16

View on GitHub (pinned to 8c25dc09fa)

Solutions

  1. Regenerate or fix the IVF file so the timebase numerator/denominator are non-zero (commonly 1/1000)
  2. Validate header fields before feeding the stream to the reader
  3. If you control the writing side, use ivfwriter to produce a spec-compliant header
  4. Check that the file/buffer was fully populated before parsing (truncated writes)
Defensive patterns

Strategy: validation

Validate before calling

var h ivfreader.IVFFileHeader
// after parsing the header yourself or from ParseNextHeader result:
if h.TimebaseNumerator == 0 || h.TimebaseDenominator == 0 {
    return errors.New("ivf header has zero timebase")
}

Type guard

func hasValidTimebase(h *ivfreader.IVFFileHeader) bool {
    return h != nil && h.TimebaseNumerator != 0 && h.TimebaseDenominator != 0
}

Try / catch

r, h, err := ivfreader.NewWith(f)
if err != nil {
    if errors.Is(err, ivfreader.ErrInvalidMediaTimebase) { // or the package-exported sentinel
        return fmt.Errorf("corrupt IVF file: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling ivfreader.NewWith / ParseNextHeader on an IVF stream whose 32-byte header has TimebaseNumerator == 0 or TimebaseDenominator == 0.

Common situations: Files produced by a broken encoder, hand-crafted test fixtures with zeroed header fields, files truncated before the timebase fields were filled, or buffers not yet fully read when the header is parsed.

Related errors


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