Claude: Korrekturen nach WebRecherche

This commit is contained in:
chk
2026-06-04 15:48:32 +02:00
parent 306aacac80
commit f67a811f9f
2 changed files with 55 additions and 15 deletions

View File

@@ -105,15 +105,10 @@ function createSnapshotRouter(go2rtcUrl) {
const jpeg = await captureOneFrame(cfg.device, cfg.hiresSize);
console.log(`[snapshot][${id}] Frame captured (${jpeg.length} bytes)`);
// 3. go2rtc-Stream wiederherstellen
const putRes = await fetch(
`${go2rtcUrl}/api/streams?src=${encodeURIComponent(id)}`,
{
method: 'PUT',
headers: { 'Content-Type': 'text/plain' },
body: cfg.streamUrl,
}
);
// 3. go2rtc-Stream wiederherstellen.
// go2rtc-API: PUT /api/streams?name=<stream>&src=<quelle-url-encoded>
// Quelle steht im `src`-Query-Param (URL-encoded), NICHT im Body.
const putRes = await fetch(buildPutUrl(go2rtcUrl, id, cfg.streamUrl), { method: 'PUT' });
console.log(`[snapshot][${id}] go2rtc PUT stream → HTTP ${putRes.status}`);
res.set({
@@ -131,11 +126,7 @@ function createSnapshotRouter(go2rtcUrl) {
// Stream auf jeden Fall wiederherstellen, auch im Fehlerfall
try {
await fetch(`${go2rtcUrl}/api/streams?src=${encodeURIComponent(id)}`, {
method: 'PUT',
headers: { 'Content-Type': 'text/plain' },
body: cfg.streamUrl,
});
await fetch(buildPutUrl(go2rtcUrl, id, cfg.streamUrl), { method: 'PUT' });
console.log(`[snapshot][${id}] Stream nach Fehler wiederhergestellt`);
} catch (restoreErr) {
console.error(`[snapshot][${id}] Stream-Wiederherstellung fehlgeschlagen:`, restoreErr.message);
@@ -158,6 +149,16 @@ function sleep(ms) {
return new Promise(r => setTimeout(r, ms));
}
// go2rtc-API zum (Wieder-)Anlegen eines Streams:
// PUT /api/streams?name=<stream-name>&src=<quelle-uri-url-encoded>
// Beide Werte als Query-Param. `src` ist die QUELLE (nicht der Name) — go2rtc
// liest sie NICHT aus dem Body.
function buildPutUrl(go2rtcUrl, name, streamUrl) {
return `${go2rtcUrl}/api/streams`
+ `?name=${encodeURIComponent(name)}`
+ `&src=${encodeURIComponent(streamUrl)}`;
}
// Startet FFmpeg, liest genau einen MJPEG-Frame aus stdout, gibt ihn als Buffer zurück.
function captureOneFrame(device, size, timeoutMs = 8000) {
return new Promise((resolve, reject) => {
@@ -166,8 +167,12 @@ function captureOneFrame(device, size, timeoutMs = 8000) {
'-f', 'v4l2',
'-input_format', 'mjpeg',
'-video_size', size,
'-framerate', '10', // niedrige FPS → schnellerer erster Frame
'-framerate', '15',
'-i', device,
// Erste ~15 Frames verwerfen: die USB-Kamera liefert direkt nach dem Öffnen
// noch unbelichtete (schwarze) Frames Auto-Belichtung/Weissabgleich brauchen
// einen Moment. Ohne das kommt das "1KB leer/schwarz"-Bild.
'-vf', 'select=gte(n\\,15)',
'-frames:v', '1',
'-q:v', '1', // beste JPEG-Qualität
'-f', 'mjpeg',