{"record":{"id":"b79f69dc0e3af502","repo":"AlexxIT/go2rtc","slug":"v4l2-invalid-video-size","errorCode":null,"errorMessage":"v4l2: invalid video_size","messagePattern":"v4l2: invalid video_size","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/v4l2/producer.go","lineNumber":52,"sourceCode":"\t}\n\n\tcodec := &core.Codec{\n\t\tClockRate:   90000,\n\t\tPayloadType: core.PayloadTypeRAW,\n\t}\n\n\tvar width, height, pixFmt uint32\n\n\tif wh := strings.Split(query.Get(\"video_size\"), \"x\"); len(wh) == 2 {\n\t\tcodec.FmtpLine = \"width=\" + wh[0] + \";height=\" + wh[1]\n\t\twidth = uint32(core.Atoi(wh[0]))\n\t\theight = uint32(core.Atoi(wh[1]))\n\t}\n\n\tswitch query.Get(\"input_format\") {\n\tcase \"yuyv422\":\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=422\"\n\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\":","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/v4l2/producer.go#L34-L70","documentation":"v4l2.Open throws \"v4l2: invalid video_size\" when the caller requests the yuyv422 input_format but codec.FmtpLine is empty — meaning no usable video size was negotiated for the V4L2 device, so raw 422 capture cannot be configured. The library cannot proceed without a size/fmt line and fails the Open call. Callers hit this in handlePipe, do, handleTCP and apiStream.","triggerScenarios":"Opening a v4l2 producer with ?input_format=yuyv422 while the camera's format enumeration left codec.FmtpLine empty (device reported no supported frame size/format, or the video_size query was missing/invalid).","commonSituations":"URL missing video_size parameter; webcam not supporting YUYV at the requested resolution; camera busy or detached so format probing returned nothing; wrong /dev/video node (metadata node instead of capture).","solutions":["Add an explicit video_size query parameter supported by the camera (check with v4l2-ctl --list-formats-ext).","Verify input_format=yuyv422 is actually supported by the device; switch to a supported format (e.g. mjpeg) if not.","Point the producer at the correct capture /dev/videoN node (not a metadata node).","Confirm the camera is plugged in and not held by another process (fuser /dev/video0)."],"exampleFix":"// before\n producer.Open(\"/dev/video0?input_format=yuyv422\")\n// after\n producer.Open(\"/dev/video0?input_format=yuyv422&video_size=640x480&framerate=30\")","handlingStrategy":"validation","validationCode":"// before Open: confirm the device supports the format+size\n// $ v4l2-ctl -d /dev/video0 --list-formats-ext\n// ensure URL includes a supported size:\nif !strings.Contains(url, \"video_size=\") && strings.Contains(url, \"input_format=yuyv422\") {\n    return errors.New(\"raw yuyv422 requires explicit video_size\")\n}","typeGuard":null,"tryCatchPattern":"p, err := v4l2.Open(url)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid video_size\") {\n        return fmt.Errorf(\"camera %s: unsupported format/size, run v4l2-ctl --list-formats-ext: %w\", dev, err)\n    }\n    return err\n}","preventionTips":["Always pass an explicit video_size the camera supports","Check supported formats with v4l2-ctl --list-formats-ext","Use the capture /dev/video node, not a metadata node","Verify the device is present and not busy before opening"],"tags":["v4l2","video","configuration"],"backgroundTag":"invalid-argument-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"}