AlexxIT/go2rtc · error

v4l2: invalid input_format

Error message

v4l2: invalid input_format

What it means

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.

Solutions

  1. Set input_format to one of the exact supported strings — for H.265 use 'hevc', not 'h265'
  2. Check the library source (pkg/v4l2/producer.go switch) for the full list of accepted input_format values
  3. Verify the device actually supports the chosen codec before retrying (this error is about the string, not the device)

Example fix

// before
producer, err := v4l2.Open(device, width, height, "h265")
// after
producer, err := v4l2.Open(device, width, height, "hevc")
Defensive patterns

Strategy: validation

Validate before calling

validFormats := map[string]bool{"h264": true, "hevc": true}
if !validFormats[inputFormat] {
    return fmt.Errorf("unsupported input_format %q; use one of h264, hevc", inputFormat)
}

Prevention

When it happens

Trigger: 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.).

Common situations: 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.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/abd595af8f6d512b. Report an issue: GitHub.

Appendix: source

Thrown at pkg/v4l2/producer.go:74

		pixFmt = device.V4L2_PIX_FMT_YUYV
	case "nv12":
		if codec.FmtpLine == "" {
			return nil, errors.New("v4l2: invalid video_size")
		}
		codec.Name = core.CodecRAW
		codec.FmtpLine += ";colorspace=420mpeg2" // maybe 420jpeg
		pixFmt = device.V4L2_PIX_FMT_NV12
	case "mjpeg":
		codec.Name = core.CodecJPEG
		pixFmt = device.V4L2_PIX_FMT_MJPEG
	case "h264":
		codec.Name = core.CodecH264
		pixFmt = device.V4L2_PIX_FMT_H264
	case "hevc":
		codec.Name = core.CodecH265
		pixFmt = device.V4L2_PIX_FMT_HEVC
	default:
		return nil, errors.New("v4l2: invalid input_format")
	}

	if err = dev.SetFormat(width, height, pixFmt); err != nil {
		return nil, err
	}

	if fps := core.Atoi(query.Get("framerate")); fps > 0 {
		if err = dev.SetParam(uint32(fps)); err != nil {
			return nil, err
		}
	}

	medias := []*core.Media{
		{
			Kind:      core.KindVideo,
			Direction: core.DirectionRecvonly,
			Codecs:    []*core.Codec{codec},
		},

View on GitHub (pinned to c245815e75)