Skip to content

Camera Streaming with go2rtc

go2rtc is a lightweight camera streaming application that can expose a printer camera through WebRTC. For printer monitoring, this can provide a lower-latency stream than a traditional MJPEG setup while still integrating cleanly with browser-based printer UIs.

This guide installs go2rtc on a Raspberry Pi OS based printer host, configures a USB camera stream named chamber, starts go2rtc automatically with systemd, and adds the stream to Mainsail and Fluidd.

By the end, you will have:

  • A go2rtc binary installed at /home/pi/go2rtc/go2rtc
  • A go2rtc.yaml configuration file defining a chamber camera stream
  • A go2rtc systemd service that starts on boot
  • A camera entry in Mainsail or Fluidd
  • A printer host running Raspberry Pi OS Bookworm or Trixie
  • SSH access to the printer host
  • A USB camera available as a Linux video device, usually /dev/video0
  • A recent Mainsail or Fluidd installation
  • Browser access to the printer host on the same local network

The example stream uses go2rtc’s FFmpeg source to read the USB camera and produce an H.264 WebRTC-compatible stream. Install FFmpeg before configuring go2rtc.

  1. Update the APT package index:

    Updating package indexes
    sudo apt update
  2. Install FFmpeg:

    Installing FFmpeg
    sudo apt install -y ffmpeg
  3. Verify that FFmpeg is available:

    Checking FFmpeg
    ffmpeg -version

    The command should print the installed FFmpeg version and build configuration.

Install the go2rtc binary in /home/pi/go2rtc. The commands below use the go2rtc_linux_arm64 release asset, which is the correct binary for 64-bit Raspberry Pi OS.

  1. Create the installation directory:

    Creating the go2rtc directory
    mkdir -p ~/go2rtc
    cd ~/go2rtc
  2. Download the latest go2rtc binary and save it as go2rtc:

    Downloading go2rtc
    wget -O go2rtc https://github.com/AlexxIT/go2rtc/releases/latest/download/go2rtc_linux_arm64
  3. Make the binary executable:

    Making go2rtc executable
    chmod a+x go2rtc
  4. Verify the binary exists and is executable:

    Checking the go2rtc binary
    ls -l /home/pi/go2rtc/go2rtc

    The permissions should include executable bits, such as -rwxr-xr-x.

Before writing the go2rtc stream configuration, identify the Linux video device for your camera and confirm one supported capture mode.

  1. List video devices:

    Listing video devices
    ls -l /dev/video*

    A single USB camera is often /dev/video0, but the number can vary.

  2. Install the V4L2 utilities:

    Installing V4L2 utilities
    sudo apt install -y v4l-utils
  3. Map video devices to physical cameras:

    Listing V4L2 devices
    v4l2-ctl --list-devices

    Use this output to choose the correct video= path for go2rtc.yaml. If multiple cameras are connected, /dev/video0 can change after reboot or after reconnecting USB devices. Stable multi-camera naming with persistent device paths or udev rules is outside the scope of this guide.

  4. List the selected camera’s supported formats and resolutions:

    Listing camera modes
    ffmpeg -f v4l2 -list_formats all -i /dev/video0

    If your camera is not /dev/video0, replace /dev/video0 with the device path from the previous step. Use one reported format and resolution for input_format and video_size in go2rtc.yaml.

Create /home/pi/go2rtc/go2rtc.yaml with a stream named chamber.

  1. Open the configuration file:

    Creating go2rtc.yaml
    nano /home/pi/go2rtc/go2rtc.yaml
  2. Add the following configuration:

    go2rtc.yaml
    api:
    listen: ":1984"
    origin: "*"
    ffmpeg:
    bin: "ffmpeg"
    log:
    format: "color"
    level: "info"
    output: "stdout"
    time: "UNIXMS"
    rtsp:
    listen: ":8554"
    default_query: "video&audio"
    srtp:
    listen: ":8443"
    webrtc:
    listen: ":8555/tcp"
    streams:
    chamber: ffmpeg:device?video=/dev/video0&input_format=yuyv422&video_size=1280x720#video=h264#hardware

The chamber stream reads /dev/video0 as a V4L2 camera, requests yuyv422 input at 1280x720, and asks FFmpeg/go2rtc to produce H.264 video. The chamber stream name is used later in go2rtc, Mainsail, and Fluidd.

Before creating the systemd service, run go2rtc in the foreground so configuration errors are visible immediately.

  1. Start go2rtc manually:

    Starting go2rtc manually
    /home/pi/go2rtc/go2rtc -config /home/pi/go2rtc/go2rtc.yaml
  2. Open the go2rtc WebUI in a browser:

    go2rtc WebUI
    http://<printer-ip>:1984
  3. Select the chamber stream link.

The video should start after a short delay. Stop the foreground process with CTRL-C before continuing.

Common errors at this stage:

  • permission denied: the binary is not executable, or the camera device permissions are wrong.
  • no such file or directory: the binary path, config path, or camera path is wrong.
  • FFmpeg format errors: input_format or video_size is not supported by the camera.
  • Hardware encoder errors: remove #hardware from the stream line and test again.

Create a systemd service so go2rtc starts automatically when the printer host boots.

  1. Create the service file:

    Creating the go2rtc service
    nano /home/pi/go2rtc/go2rtc.service
  2. Add this unit:

    go2rtc.service
    [Unit]
    Description=go2rtc
    After=network.target
    [Service]
    Type=simple
    WorkingDirectory=/home/pi/go2rtc
    ExecStart=/home/pi/go2rtc/go2rtc -config /home/pi/go2rtc/go2rtc.yaml
    ExecReload=/bin/kill -HUP $MAINPID
    Restart=always
    RestartSec=5
    User=root
    Group=root
    Environment=PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
    [Install]
    WantedBy=multi-user.target
  1. Enable the service using the absolute service-file path:

    Enabling go2rtc
    sudo systemctl enable /home/pi/go2rtc/go2rtc.service
  2. Reload systemd and start go2rtc:

    Starting go2rtc
    sudo systemctl daemon-reload
    sudo systemctl start go2rtc
  3. Check the service state:

    Checking go2rtc service state
    sudo systemctl status go2rtc

To follow service logs while troubleshooting, run:

Following go2rtc logs
sudo journalctl -u go2rtc -f

Mainsail includes a WebRTC (go2rtc) webcam service for go2rtc streams.

  1. Open Mainsail in your browser.

  2. Go to Settings > Webcams.

  3. Add a new webcam entry.

  4. Configure the webcam with these values:

    • Name: Chamber
    • Service: WebRTC (go2rtc)
    • Stream URL: http://<printer-ip>:1984/stream.html?src=chamber&mode=webrtc
    • Aspect ratio: 16:9 for the sample 1280x720 stream
    • Rotation/flip: Set these to match your camera orientation

The src=chamber parameter must match the stream name in go2rtc.yaml.

Fluidd includes a native WebRTC (go2rtc) camera type.

  1. Open Fluidd in your browser.

  2. Go to Settings > Cameras.

  3. Add a new camera.

  4. Configure the camera with these values:

    • Name: Chamber
    • Type: WebRTC (go2rtc)
    • go2rtc URL: http://<printer-ip>:1984
    • Stream name/source: chamber
    • Aspect ratio: 16:9 for the sample 1280x720 stream
    • Rotation/flip: Set these to match your camera orientation

Fluidd field labels may vary by version. The required values are the go2rtc WebUI URL and the chamber stream name.

Use systemd to confirm whether go2rtc is running:

Checking go2rtc service state
sudo systemctl status go2rtc

If the service is not active, inspect the logs:

Following go2rtc logs
sudo journalctl -u go2rtc -f

List available video devices:

Listing video devices
ls -l /dev/video*

If your camera is not /dev/video0, update the video= parameter in go2rtc.yaml.

List supported camera modes:

Listing camera modes
ffmpeg -f v4l2 -list_formats all -i /dev/video0

If the configured input_format or video_size is not listed, update the stream line to use a supported mode.

Check for Another Process Using the Camera

Section titled “Check for Another Process Using the Camera”

Check whether another service already has the camera open:

Checking camera users
sudo fuser /dev/video0

If another process is listed, stop or reconfigure that service before starting go2rtc with the same device.

If go2rtc starts but the stream fails, or FFmpeg reports hardware encoder errors, remove #hardware from the stream line and restart go2rtc:

go2rtc.yaml
streams:
chamber: ffmpeg:device?video=/dev/video0&input_format=yuyv422&video_size=1280x720#video=h264

Then restart the service:

Restarting go2rtc
sudo systemctl restart go2rtc

Open the go2rtc WebUI directly:

go2rtc WebUI
http://<printer-ip>:1984

If the WebUI does not load, confirm the printer host IP address and check that your browser is on the same local network.