AlexxIT/go2rtc · error

err.Error()

Error message

err.Error()

What it means

After the destination stream is found, inputFLV calls flv.Open(r.Body) to parse the incoming FLV data; any parse/IO error is echoed verbatim with HTTP 500. This means the request body was not a valid, readable FLV stream (bad header, truncated data, or empty body).

Solutions

  1. Ensure the client actually sends a valid FLV byte stream (starts with 'FLV' signature)
  2. Check the sender isn't closing the connection before the header/tags are written
  3. Verify no proxy/CDN is altering or truncating the body
  4. Inspect the returned error text — it names the exact parse/read failure

Example fix

// before
curl -X POST --data-binary file.mp4 'http://host/api/stream.flv?dst=cam'
// after
ffmpeg -i input -c copy -f flv - | curl -X POST --data-binary @- 'http://host/api/stream.flv?dst=cam'
Defensive patterns

Strategy: validation

Validate before calling

// verify the payload is FLV before sending
const head = new Uint8Array(await file.slice(0, 3).arrayBuffer());
if (String.fromCharCode(...head) !== 'FLV') throw new Error('not an FLV stream');

Type guard

function isFLV(buf) { return buf.length >= 9 && buf[0]===0x46 && buf[1]===0x4C && buf[2]===0x56; }

Try / catch

const res = await fetch(url, {method:'POST', body: flvBody});
if (!res.ok) { const msg = await res.text(); throw new Error(`flv.Open failed: ${msg}`); }

Prevention

When it happens

Trigger: POSTing a body to the FLV input endpoint whose bytes are not FLV (wrong container, gzip, empty body, connection closed mid-stream), so flv.Open fails while reading the FLV header/tags.

Common situations: A script pipes MP4/RTSP data instead of FLV; the sending client aborted early; a proxy stripped the body; wrong Content-Type assumption in custom integrations.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at internal/rtmp/rtmp.go:188

	h := w.Header()
	h.Set("Content-Type", "video/x-flv")

	_, _ = cons.WriteTo(w)

	stream.RemoveConsumer(cons)
}

func inputFLV(w http.ResponseWriter, r *http.Request) {
	dst := r.URL.Query().Get("dst")
	stream := streams.Get(dst)
	if stream == nil {
		http.Error(w, api.StreamNotFound, http.StatusNotFound)
		return
	}

	client, err := flv.Open(r.Body)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	stream.AddProducer(client)

	if err = client.Start(); err != nil && err != io.EOF {
		log.Warn().Err(err).Caller().Send()
	}

	stream.RemoveProducer(client)
}

View on GitHub (pinned to c245815e75)