pion/webrtc · error
no codec for this MimeType
Error message
no codec for this MimeType
What it means
errNoSuchCodec is returned by ivfwriter.NewWith when the WithCodec option receives a MimeType that the IVF writer does not support. The writer only knows how to map a small set of media types (VP8, VP9, AV1) to its internal codec enum, and any other value (including empty string) hits the default branch. It signals misconfiguration of the writer, not a runtime data problem.
Source
Thrown at pkg/media/ivfwriter/ivfwriter.go:23
package ivfwriter
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 uint64View on GitHub (pinned to 8c25dc09fa)
Solutions
- Pass a supported MimeType to WithCodec: 'video/vp8', 'video/vp9', or 'video/av1'
- Check the string for typos, extra spaces, or parameters; compare against the constants the writer's switch matches
- If codec support is unknown at runtime, validate the MimeType against a whitelist before constructing the writer
- Upgrade the library if you need a newer codec the switch does not cover yet
Example fix
// before
w, err := ivfwriter.NewWith(buf, ivfwriter.WithCodec("video/H264")) // errNoSuchCodec
// after
w, err := ivfwriter.NewWith(buf, ivfwriter.WithCodec("video/VP8")) Defensive patterns
Strategy: validation
Validate before calling
var supported = map[string]bool{"video/vp8": true, "video/vp9": true, "video/av1": true}
if !supported[strings.ToLower(mimeType)] {
return fmt.Errorf("unsupported IVF codec: %q", mimeType)
} Type guard
func isIVFSupportedCodec(mt string) bool {
switch mt {
case "video/vp8", "video/vp9", "video/av1":
return true
}
return false
} Prevention
- Always pass an explicit, non-empty MimeType to WithCodec
- Whitelist codecs before constructing the writer
- Use the same constant strings as the SDP/media layer to avoid case/spacing drift
- Add a unit test constructing the writer with each codec you ship
When it happens
Trigger: Calling ivfwriter.NewWith(w, ivfwriter.WithCodec(...)) with an empty string, an unsupported MimeType (e.g. 'video/h264', 'video/ VP8' with wrong case), or a misspelled type, so the switch over MimeType falls to default and returns errNoSuchCodec.
Common situations: Copy-pasting an SDP mime string including parameters, passing an audio codec (e.g. Opus) to a video-only IVF writer, forgetting WithCodec so an empty codec is probed, or using a codec added in a newer spec than the library supports.
Related errors
- stream is nil
- incomplete frame header
- incomplete frame data
- incomplete file header
- IVF signature mismatch
AI-assisted analysis of pion/webrtc@8c25dc09fa (2026-09-03).
Data as JSON: /api/errors/5bfe9ad69c4fe420.
Report an issue: GitHub.