{"record":{"id":"abd595af8f6d512b","repo":"AlexxIT/go2rtc","slug":"v4l2-invalid-input-format","errorCode":null,"errorMessage":"v4l2: invalid input_format","messagePattern":"v4l2: invalid input_format","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/v4l2/producer.go","lineNumber":74,"sourceCode":"\t\tpixFmt = device.V4L2_PIX_FMT_YUYV\n\tcase \"nv12\":\n\t\tif codec.FmtpLine == \"\" {\n\t\t\treturn nil, errors.New(\"v4l2: invalid video_size\")\n\t\t}\n\t\tcodec.Name = core.CodecRAW\n\t\tcodec.FmtpLine += \";colorspace=420mpeg2\" // maybe 420jpeg\n\t\tpixFmt = device.V4L2_PIX_FMT_NV12\n\tcase \"mjpeg\":\n\t\tcodec.Name = core.CodecJPEG\n\t\tpixFmt = device.V4L2_PIX_FMT_MJPEG\n\tcase \"h264\":\n\t\tcodec.Name = core.CodecH264\n\t\tpixFmt = device.V4L2_PIX_FMT_H264\n\tcase \"hevc\":\n\t\tcodec.Name = core.CodecH265\n\t\tpixFmt = device.V4L2_PIX_FMT_HEVC\n\tdefault:\n\t\treturn nil, errors.New(\"v4l2: invalid input_format\")\n\t}\n\n\tif err = dev.SetFormat(width, height, pixFmt); err != nil {\n\t\treturn nil, err\n\t}\n\n\tif fps := core.Atoi(query.Get(\"framerate\")); fps > 0 {\n\t\tif err = dev.SetParam(uint32(fps)); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\tmedias := []*core.Media{\n\t\t{\n\t\t\tKind:      core.KindVideo,\n\t\t\tDirection: core.DirectionRecvonly,\n\t\t\tCodecs:    []*core.Codec{codec},\n\t\t},","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/v4l2/producer.go#L56-L92","documentation":"pkg/v4l2.Open opens a V4L2 (Video4Linux2) capture device and maps the user-supplied input_format string to a codec and pixel format. The string must be one of the supported values (e.g. h264, hevc; other cases handled above the snippet); any other value hits the default branch and the producer refuses to start. This is a fail-fast config validation so the device is not opened with an unknown format.","triggerScenarios":"Calling pkg/v4l2 Open (directly or via handlePipe, do, handleTCP, apiStream in server entry points) with an input_format field that is not one of the recognized codec strings (empty string, 'h265', 'H264', 'mpeg4', etc.).","commonSituations":"Typo or wrong casing in a config file's input_format; using a codec name from another tool's vocabulary (e.g. 'h265' instead of 'hevc'); leaving the field empty when copying a v4l2 source config.","solutions":["Set input_format to one of the exact supported strings — for H.265 use 'hevc', not 'h265'","Check the library source (pkg/v4l2/producer.go switch) for the full list of accepted input_format values","Verify the device actually supports the chosen codec before retrying (this error is about the string, not the device)"],"exampleFix":"// before\nproducer, err := v4l2.Open(device, width, height, \"h265\")\n// after\nproducer, err := v4l2.Open(device, width, height, \"hevc\")","handlingStrategy":"validation","validationCode":"validFormats := map[string]bool{\"h264\": true, \"hevc\": true}\nif !validFormats[inputFormat] {\n    return fmt.Errorf(\"unsupported input_format %q; use one of h264, hevc\", inputFormat)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep input_format strings lowercase and copy them from library docs/source switch","Validate all source config fields at startup before touching the device"],"tags":["v4l2","config","video","invalid-input-format"],"backgroundTag":"invalid-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"}