{"record":{"id":"5bfe9ad69c4fe420","repo":"pion/webrtc","slug":"no-codec-for-this-mimetype","errorCode":null,"errorMessage":"no codec for this MimeType","messagePattern":"no codec for this MimeType","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/ivfwriter/ivfwriter.go","lineNumber":23,"sourceCode":"package ivfwriter\n\nimport (\n\t\"encoding/binary\"\n\t\"errors\"\n\t\"io\"\n\t\"os\"\n\n\t\"github.com/pion/rtp\"\n\t\"github.com/pion/rtp/codecs\"\n\t\"github.com/pion/rtp/codecs/av1/obu\"\n)\n\nvar (\n\terrFileNotOpened        = errors.New(\"file not opened\")\n\terrInvalidNilPacket     = errors.New(\"invalid nil packet\")\n\terrCodecUnset           = errors.New(\"codec is unset\")\n\terrCodecAlreadySet      = errors.New(\"codec is already set\")\n\terrNoSuchCodec          = errors.New(\"no codec for this MimeType\")\n\terrInvalidMediaTimebase = errors.New(\"invalid media timebase\")\n)\n\ntype (\n\tcodec int\n\n\t// IVFWriter is used to take RTP packets and write them to an IVF on disk.\n\tIVFWriter struct {\n\t\tioWriter     io.Writer\n\t\tcount        uint64\n\t\tseenKeyFrame bool\n\n\t\tcodec codec\n\n\t\ttimebaseDenominator uint32\n\t\ttimebaseNumerator   uint32\n\t\tfirstFrameTimestamp uint32\n\t\tclockRate           uint64","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/ivfwriter/ivfwriter.go#L5-L41","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nw, err := ivfwriter.NewWith(buf, ivfwriter.WithCodec(\"video/H264\")) // errNoSuchCodec\n// after\nw, err := ivfwriter.NewWith(buf, ivfwriter.WithCodec(\"video/VP8\"))","handlingStrategy":"validation","validationCode":"var supported = map[string]bool{\"video/vp8\": true, \"video/vp9\": true, \"video/av1\": true}\nif !supported[strings.ToLower(mimeType)] {\n    return fmt.Errorf(\"unsupported IVF codec: %q\", mimeType)\n}","typeGuard":"func isIVFSupportedCodec(mt string) bool {\n    switch mt {\n    case \"video/vp8\", \"video/vp9\", \"video/av1\":\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["go","media","ivf","configuration"],"backgroundTag":"unsupported-codec","analyzedSha":"8c25dc09fa9e7c09aac4309ead88093d760432b0","analyzedAt":"2026-09-03T21:56:56.182Z","contentChangedAt":"2026-09-03T21:56:56.182Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}