improve matching go2rtc stream names with cameras

This commit is contained in:
Josh Hawkins 2025-10-20 10:16:45 -05:00
parent 4319118e94
commit c258894f97

View File

@ -152,36 +152,38 @@ export default function CameraEditForm({
})) }))
: defaultValues.ffmpeg.inputs; : defaultValues.ffmpeg.inputs;
// Load go2rtc streams for this camera
const go2rtcStreams = config.go2rtc?.streams || {}; const go2rtcStreams = config.go2rtc?.streams || {};
const cameraStreams: Record<string, string[]> = {}; const cameraStreams: Record<string, string[]> = {};
// Find streams that match this camera's name pattern // get candidate stream names for this camera. could be the camera's own name,
Object.entries(go2rtcStreams).forEach(([streamName, urls]) => { // any restream names referenced by this camera, or any keys under live --> streams
if (streamName.startsWith(cameraName) || streamName === cameraName) { const validNames = new Set<string>();
cameraStreams[streamName] = Array.isArray(urls) ? urls : [urls]; validNames.add(cameraName);
}
});
// Also deduce go2rtc streams from restream URLs in camera inputs // deduce go2rtc stream names from rtsp restream inputs
camera.ffmpeg?.inputs?.forEach((input, index) => { camera.ffmpeg?.inputs?.forEach((input) => {
// exclude any query strings or trailing slashes from the stream name
const restreamMatch = input.path.match( const restreamMatch = input.path.match(
/^rtsp:\/\/127\.0\.0\.1:8554\/(.+)$/, /^rtsp:\/\/127\.0\.0\.1:8554\/([^?#/]+)(?:[?#].*)?$/,
); );
if (restreamMatch) { if (restreamMatch) {
const streamName = restreamMatch[1]; const streamName = restreamMatch[1];
// Find the corresponding go2rtc stream validNames.add(streamName);
const go2rtcStream = Object.entries(go2rtcStreams).find( }
([name]) => });
name === streamName ||
name === `${cameraName}_${index + 1}` || // Include live --> streams keys
name === cameraName, const liveStreams = camera?.live?.streams;
); if (liveStreams) {
if (go2rtcStream) { Object.keys(liveStreams).forEach((key) => {
cameraStreams[go2rtcStream[0]] = Array.isArray(go2rtcStream[1]) validNames.add(key);
? go2rtcStream[1] });
: [go2rtcStream[1]]; }
}
// Map only go2rtc entries that match the collected names
Object.entries(go2rtcStreams).forEach(([name, urls]) => {
if (validNames.has(name)) {
cameraStreams[name] = Array.isArray(urls) ? urls : [urls];
} }
}); });