{"record":{"id":"0c1f6ae5af8b5e0c","repo":"AlexxIT/go2rtc","slug":"unsupported-iso-video-codec","errorCode":null,"errorMessage":"unsupported iso video: ${codec}","messagePattern":"unsupported iso video: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/iso/codecs.go","lineNumber":16,"sourceCode":"package iso\n\nimport (\n\t\"github.com/AlexxIT/go2rtc/pkg/core\"\n\t\"github.com/AlexxIT/go2rtc/pkg/pcm\"\n)\n\nfunc (m *Movie) WriteVideo(codec string, width, height uint16, conf []byte) {\n\t// https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html\n\tswitch codec {\n\tcase core.CodecH264:\n\t\tm.StartAtom(\"avc1\")\n\tcase core.CodecH265:\n\t\tm.StartAtom(\"hev1\")\n\tdefault:\n\t\tpanic(\"unsupported iso video: \" + codec)\n\t}\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.Skip(4)             // temporal quality\n\tm.Skip(4)             // spatial quality\n\tm.WriteUint16(width)  // width\n\tm.WriteUint16(height) // height\n\tm.WriteFloat32(72)    // horizontal resolution\n\tm.WriteFloat32(72)    // vertical resolution\n\tm.Skip(4)             // reserved\n\tm.WriteUint16(1)      // frame count\n\tm.Skip(32)            // compressor name\n\tm.WriteUint16(24)     // depth\n\tm.WriteUint16(0xFFFF) // color table id (-1)\n","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/iso/codecs.go#L1-L34","documentation":"WriteVideo in the ISO BMFF (MP4) muxer panics when asked to write a video sample entry for a codec it does not support. Only H264 (avc1) and H265 (hev1) sample entries are implemented; any other core.Codec value hits the default branch and panics.","triggerScenarios":"Calling WriteVideo with a codec argument other than core.CodecH264 or core.CodecH265 (e.g. H263, MJPEG, VP9) while building an MP4/ISOBMFF track.","commonSituations":"Feeding a camera stream that publishes a non-H264/H265 codec into the MP4 muxer; upstream remuxing logic that passes the source codec through unvalidated; adding a new codec to core without extending pkg/iso.","solutions":["Transcode or repack the stream to H264/H265 before feeding WriteVideo.","Add a pre-call guard that checks the codec and rejects unsupported values gracefully instead of reaching the panic.","If the codec should be supported, extend the switch in pkg/iso/codecs.go with the appropriate sample entry atom.","Recover from the panic at a muxer boundary and convert it to a returned error."],"exampleFix":"// before\nm.WriteVideo(trackID, core.CodecVP9, ...) // panics: unsupported iso video: VP9\n// after\nswitch codec {\ncase core.CodecH264, core.CodecH265:\n    m.WriteVideo(trackID, codec, ...)\ndefault:\n    return fmt.Errorf(\"mp4 muxer supports only H264/H265 video, got %s\", codec)\n}","handlingStrategy":"validation","validationCode":"var supportedVideo = map[core.Codec]bool{core.CodecH264: true, core.CodecH265: true}\nif !supportedVideo[codec] {\n    return fmt.Errorf(\"unsupported iso video codec: %s\", codec)\n}\nm.WriteVideo(trackID, codec, w, timescale)","typeGuard":"func isSupportedISOVideo(c core.Codec) bool {\n    return c == core.CodecH264 || c == core.CodecH265\n}","tryCatchPattern":"// Go: convert panic to error at the muxer boundary\nfunc safeWriteVideo(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.WriteVideo(args...)\n    return nil\n}","preventionTips":["Validate codec against the supported set before muxing.","Transcode non-H264/H265 sources upstream.","When adding codecs to core.Codec, audit pkg/iso switches.","Guard public muxer methods with recover in service code."],"tags":["mp4","muxer","codec","panic","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"}