{"record":{"id":"52dcb2809b4204bd","repo":"AlexxIT/go2rtc","slug":"unsupported-iso-audio-codec","errorCode":null,"errorMessage":"unsupported iso audio: ${codec}","messagePattern":"unsupported iso audio: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/iso/codecs.go","lineNumber":65,"sourceCode":"\tm.EndAtom()\n\n\tm.EndAtom() // AVC1\n}\n\nfunc (m *Movie) WriteAudio(codec string, channels uint16, sampleRate uint32, conf []byte) {\n\tswitch codec {\n\tcase core.CodecAAC, core.CodecMP3:\n\t\tm.StartAtom(\"mp4a\") // supported in all players and browsers\n\tcase core.CodecFLAC:\n\t\tm.StartAtom(\"fLaC\") // supported in all players and browsers\n\tcase core.CodecOpus:\n\t\tm.StartAtom(\"Opus\") // supported in Chrome and Firefox\n\tcase core.CodecPCMU:\n\t\tm.StartAtom(\"ulaw\")\n\tcase core.CodecPCMA:\n\t\tm.StartAtom(\"alaw\")\n\tdefault:\n\t\tpanic(\"unsupported iso audio: \" + codec)\n\t}\n\n\tif channels == 0 {\n\t\tchannels = 1\n\t}\n\n\tm.Skip(6)\n\tm.WriteUint16(1)                    // data_reference_index\n\tm.Skip(2)                           // version\n\tm.Skip(2)                           // revision\n\tm.Skip(4)                           // vendor\n\tm.WriteUint16(channels)             // channel_count\n\tm.WriteUint16(16)                   // sample_size\n\tm.Skip(2)                           // compression id\n\tm.Skip(2)                           // reserved\n\tm.WriteFloat32(float64(sampleRate)) // sample_rate\n\n\tswitch codec {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/iso/codecs.go#L47-L83","documentation":"WriteAudio in the ISO BMFF (MP4) muxer panics when given an audio codec with no implemented sample entry. Supported entries include Opus, PCMU (ulaw), PCMA (alaw) and others handled by the switch; any unlisted core.Codec reaches the default branch and panics.","triggerScenarios":"Calling WriteAudio with a codec not covered by the switch (e.g. AAC variants not mapped, G.722, MP3) while muxing an audio track into MP4.","commonSituations":"Camera or SIP stream publishing an audio codec the muxer does not know; passing codec values straight through from an RTSP SDP without mapping; new codec added to core.Codec without updating pkg/iso.","solutions":["Transcode the audio to a supported codec (e.g. Opus, PCMU/PCMA) before muxing.","Guard the call: check the codec against the supported set and return an error instead of panicking.","Extend the switch in pkg/iso/codecs.go WriteAudio with the needed sample entry atom if the codec must be supported.","Wrap muxing with recover to translate the panic into an error for callers."],"exampleFix":"// before\nm.WriteAudio(trackID, core.CodecMP3, ...) // panics: unsupported iso audio: MP3\n// after\nswitch codec {\ncase core.CodecOpus, core.CodecPCMU, core.CodecPCMA:\n    m.WriteAudio(trackID, codec, ...)\ndefault:\n    return fmt.Errorf(\"mp4 muxer: unsupported audio codec %s\", codec)\n}","handlingStrategy":"validation","validationCode":"var supportedAudio = map[core.Codec]bool{core.CodecOpus: true, core.CodecPCMU: true, core.CodecPCMA: true}\nif !supportedAudio[codec] {\n    return fmt.Errorf(\"unsupported iso audio codec: %s\", codec)\n}\nm.WriteAudio(trackID, codec, w, timescale)","typeGuard":"func isSupportedISOAudio(c core.Codec) bool {\n    switch c {\n    case core.CodecOpus, core.CodecPCMU, core.CodecPCMA:\n        return true\n    }\n    return false\n}","tryCatchPattern":"func safeWriteAudio(m *iso.Muxer, args...) (err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"iso muxer panic: %v\", r)\n        }\n    }()\n    m.WriteAudio(args...)\n    return nil\n}","preventionTips":["Whitelist supported audio codecs before calling WriteAudio.","Transcode audio to Opus/PCMU/PCMA when the source uses another codec.","Keep pkg/iso codec switches in sync with core.Codec additions.","Recover panics at mux boundaries and surface them as errors."],"tags":["mp4","muxer","codec","panic","audio","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-16T04:17:20.429Z"}