AlexxIT/go2rtc · error

multipart: no content length

Error message

multipart: no content length

What it means

Each part of an MJPEG multipart stream carries a MIME part header block; go2rtc requires the Content-Length header to know how many bytes of JPEG data to read for the frame. If the header is absent or empty, frame framing is impossible, so Next returns this error instead of guessing boundaries.

Solutions

  1. Use a camera/server firmware or configuration that includes Content-Length in each multipart part header.
  2. Place go2rtc behind a transcoding step (e.g. restream through ffmpeg) if the source cannot be fixed: `ffmpeg -i http://cam -c copy -f mpjpeg -`.
  3. Check whether an HTTP proxy or CDN is stripping part headers and bypass it.
  4. Open/track an upstream issue with the vendor; this format cannot be parsed without part lengths.
Defensive patterns

Strategy: validation

Validate before calling

// Probe the stream and confirm part headers carry Content-Length
rd := bufio.NewReader(resp.Body)
line, _ := rd.ReadString('\n')
if !strings.Contains(strings.ToLower(line), "content-length") {
    return errors.New("source multipart parts lack Content-Length; unsupported source")
}

Try / catch

if err := producer.Start(); err != nil {
    if strings.Contains(err.Error(), "no content length") {
        return fmt.Errorf("camera sends multipart parts without Content-Length; remux via ffmpeg or update firmware: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: mpjpeg Producer.Next reads a part whose header set has no Content-Length value (header.Get("Content-Length") == "").

Common situations: Cameras or streaming servers that emit multipart parts without Content-Length (chunked or delimiter-only framing); custom streaming middlewares; misconfigured camera firmware that omits part headers.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at pkg/mpjpeg/multipart.go:46

		// Foscam G2 has a awful implementation of MJPEG
		// https://github.com/AlexxIT/go2rtc/issues/1258
		if b, _ := rd.Peek(2); string(b) == "--" {
			continue
		}

		break
	}

	tp := textproto.NewReader(rd)
	header, err := tp.ReadMIMEHeader()
	if err != nil {
		return nil, nil, err
	}

	s := header.Get("Content-Length")
	if s == "" {
		return nil, nil, errors.New("multipart: no content length")
	}

	size, err := strconv.Atoi(s)
	if err != nil {
		return nil, nil, err
	}

	buf := make([]byte, size)
	if _, err = io.ReadFull(rd, buf); err != nil {
		return nil, nil, err
	}

	return http.Header(header), buf, nil
}

View on GitHub (pinned to c245815e75)