{"record":{"id":"35864e6b392f9ff7","repo":"AlexxIT/go2rtc","slug":"mp4-unsupported-codec","errorCode":null,"errorMessage":"mp4: unsupported codec: ","messagePattern":"mp4: unsupported codec: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/mp4/consumer.go","lineNumber":156,"sourceCode":"\t\tcase core.CodecOpus, core.CodecMP3: // no changes\n\t\tcase core.CodecPCMA, core.CodecPCMU, core.CodecPCM, core.CodecPCML:\n\t\t\tcodec.Name = core.CodecFLAC\n\t\t\tif codec.Channels == 2 {\n\t\t\t\t// hacky way for support two channels audio\n\t\t\t\tcodec.Channels = 1\n\t\t\t\tcodec.ClockRate *= 2\n\t\t\t}\n\t\t\thandler.Handler = pcm.FLACEncoder(track.Codec.Name, codec.ClockRate, handler.Handler)\n\n\t\tdefault:\n\t\t\thandler.Handler = nil\n\t\t}\n\t}\n\n\tif handler.Handler == nil {\n\t\ts := \"mp4: unsupported codec: \" + track.Codec.String()\n\t\tprintln(s)\n\t\treturn errors.New(s)\n\t}\n\n\tc.muxer.AddTrack(codec)\n\n\thandler.HandleRTP(track)\n\tc.Senders = append(c.Senders, handler)\n\n\treturn nil\n}\n\nfunc (c *Consumer) WriteTo(wr io.Writer) (int64, error) {\n\tif len(c.Senders) == 1 && c.Senders[0].Codec.IsAudio() {\n\t\tc.start = true\n\t}\n\n\tinit, err := c.muxer.GetInit()\n\tif err != nil {\n\t\treturn 0, err","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/mp4/consumer.go#L138-L174","documentation":"When consuming an MP4 (muxing incoming tracks into the container), MP4Consumer.AddTrack looks up a registered handler for the track's codec (which supplies both the RTP depacketizer and the muxer sample entry). If track.Codec.Name has no matching handler, handler.Handler stays nil and the function returns this error naming the unsupported codec string.","triggerScenarios":"Calling mp4.NewConsumer and then AddTrack with a track whose codec is not in the supported set (e.g. H.265 with an exotic profile, AV1, VP9, Opus variants, or a codec string the muxer has no box writer for) — or a misnamed codec coming from a source producer.","commonSituations":"Recording streams from cameras emitting codecs like H.265+ or MJPEG into MP4; browser streams with codecs (AV1/VP9) not mapped in the muxer; older go2rtc version lacking support for a newly added codec; case/name mismatch between producer codec name and the consumer's handler registry.","solutions":["Transcode to a supported codec before recording, e.g. `ffmpeg ... -c:v libx264 -c:a aac`, since H.264+AAC/PCMA/PCMU have well-supported MP4 handlers.","Upgrade go2rtc to the latest release — MP4 codec support (H.265, Opus, etc.) grows over time.","Check the exact codec name of the incoming track (log track.Codec.String()) and confirm it matches a supported handler; fix producers that set non-standard codec names.","Use a different consumer/record format (e.g. MPEG-TS or MKV via ffmpeg) that supports the codec if MP4 muxing is not mandatory."],"exampleFix":"// before: recording an unsupported codec name directly\ncons := mp4.NewConsumer()\ncons.AddTrack(track) // track.Codec = MJPEG -> error\n\n// after: force a supported codec via stream transcoding\nstream.PutQuery(\"video\", \"h264\")\nstream.PutQuery(\"audio\", \"aac\")\ncons.AddTrack(track) // track.Codec = h264","handlingStrategy":"try-catch","validationCode":"var mp4SupportedCodecs = map[string]bool{\"h264\": true, \"aac\": true, \"pcma\": true, \"pcmu\": true, \"h265\": true, \"opus\": true}\nfunc mp4TrackSupported(track core.Track) bool {\n\treturn mp4SupportedCodecs[strings.ToLower(track.Codec.Name)]\n}","typeGuard":null,"tryCatchPattern":"cons := mp4.NewConsumer()\nif err := cons.AddTrack(track); err != nil && strings.Contains(err.Error(), \"mp4: unsupported codec\") {\n\tlog.Warnf(\"%s; starting ffmpeg transcode to h264/aac for recording\", err)\n\trecorder = startFFmpegRecorder(source) // fallback path\n}","preventionTips":["Log track.Codec.String() and compare against the consumer's supported handler list before adding","Pin/upgrade go2rtc version so MP4 codec support matches your camera output","Configure the source to deliver H.264 + AAC (or another well-supported pair) when recording to MP4","Fall back to a container that supports the codec (MPEG-TS/MKV) when MP4 muxing fails"],"tags":["mp4","muxer","codec","recording","unsupported-codec"],"backgroundTag":"unsupported-enum-value","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}