Skip to content

Conversation

seydx
Copy link
Contributor

@seydx seydx commented Jun 3, 2025

This PR adds a preload feature that allows streams to be initialized at go2rtc startup, which is particularly useful for cameras with slow startup times.

Changes

  • New preload package: Implements a consumer that keeps streams active without requiring active viewers
  • Configuration support: Added preload section to YAML config for specifying streams to preload
  • Stream integration: Extended streams package to support preload consumers with query parameters
  • API endpoints: Added REST API for dynamic preload management

Usage

Configure streams to preload in go2rtc.yaml:

preload:
  camera1:                                     # default: video&audio = ANY
  camera2: "video"                             # preload only video track
  camera3: "video=h264#audio=opus"             # initialize transcoding pipeline

streams:
  camera1: 
    - rtsp://192.168.1.100/stream
  camera2: 
    - rtsp://192.168.1.101/stream  
  camera3: 
    - rtsp://192.168.1.102/h265stream
    - ffmpeg:camera3#video=h264#audio=opus#hardware

API Endpoints

Dynamic preload management via REST API:

# Add/update preload for a stream
PUT /api/preloads?src=camera3&video=h264&audio=opus

# Remove preload from a stream  
DELETE /api/preloads?src=camera3

Benefits

  • Eliminates cold start delays when accessing streams
  • Maintains active connections to prevent camera timeouts
  • Supports codec filtering and audio configuration
  • Dynamic control via REST API for runtime management

The preload consumer acts as a permanent viewer that keeps the stream pipeline active while consuming minimal resources.

Closes/Addresses/Resolves: #1444 #605 #1344 #530

@gtxaspec
Copy link

gtxaspec commented Jun 3, 2025

yes! thank you!

@AlexxIT AlexxIT self-assigned this Jun 3, 2025
@AlexxIT
Copy link
Owner

AlexxIT commented Jun 3, 2025

@gtxaspec Looks like you've been waiting a long time for this.

@gtxaspec
Copy link

gtxaspec commented Jun 3, 2025

@gtxaspec Looks like you've been waiting a long time for this.

I wait patiently =D

@InstigatorX
Copy link

Yes, please merge this. Would help load times in frigate for live view.

@felipecrs
Copy link
Contributor

felipecrs commented Jul 10, 2025

Yes, please merge this. Would help load times in frigate for live view.

Are you sure? Frigate already maintains a connection to the stream active during all the time, unless the camera is deactivated.

@InstigatorX
Copy link

InstigatorX commented Jul 10, 2025 via email

@felipecrs
Copy link
Contributor

felipecrs commented Jul 10, 2025

It only maintains if it's being requested. Otherwise, it terminates. This is the default behavior and in the README. This PR makes it a configurable option. So you can take it or leave it depending on need.

Where did you take this from? That's not how Frigate works. Frigate maintains a 24/7 stream with the camera even if all features like motion, detection, and recording are disabled.

@felipecrs
Copy link
Contributor

That's one of the first issues I ever opened in Frigate:

And it was decided that it will not be addressed/changed.

@InstigatorX
Copy link

InstigatorX commented Jul 11, 2025 via email

@felipecrs
Copy link
Contributor

felipecrs commented Jul 11, 2025

I am not questioning your support for this PR. I couldn't be more in favor of this PR: I was the one who asked for it.

I am questioning your reasoning because you said Would help load times in frigate for live view.

@felipecrs
Copy link
Contributor

felipecrs commented Jul 11, 2025

I just want to set your expectations right. If you expect this PR to improve loading times for live view in Frigate: it won't.

@InstigatorX
Copy link

InstigatorX commented Jul 11, 2025 via email

@felipecrs
Copy link
Contributor

Got it. You're absolutely right. Thanks for explaining, and sorry about the confusion.

@hprombex
Copy link

hprombex commented Aug 4, 2025

Nice! Tested and working very well :)

@kieslinger
Copy link

Same here! Using this to preload a mjpeg stream to my loxone bell. Before it takes up to 10 sec to connect. Now it's almost instantly. Hope to see it in the next release.

@AlexxIT
Copy link
Owner

AlexxIT commented Aug 7, 2025

I hope so too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants