Streaming Tips

How to build a sub-$300 standby encoder with raspberry pi and ffmpeg that autoswaps when your main PC drops

How to build a sub-$300 standby encoder with raspberry pi and ffmpeg that autoswaps when your main PC drops

When your main streaming PC crashes mid-broadcast the panic is real: chat floods, notifications light up and you can lose viewers (and trust) in minutes. I prefer planning for the inevitable. Over the years I've built lightweight standby encoders that kick in automatically when the main machine drops. You can build one for under $300 using a Raspberry Pi, ffmpeg, and a small amount of glue code. Below I walk through the hardware, the network/encoding trade-offs, and paste-ready scripts and systemd snippets so you can get a resilient backup live in a couple of hours.

Why a Raspberry Pi standby encoder?

A Pi-based standby encoder is inexpensive, low-power, and easy to maintain. It isn't meant to replace your production PC for high-quality multi-source broadcasts; it's there to buy time and keep an active presence while you recover. Benefits:

  • Cost-effective: all-in under $300.
  • Small and unobtrusive: can live in your rack or on a shelf.
  • Automatable: runs headless and can swap streams automatically via scripts.
  • Versatile: supports pre-recorded fallback content, simple overlays, or a low-bitrate proxy of your main stream.
  • What the system does

    The standby encoder runs ffmpeg and implements two main behaviors:

  • Pull-and-restream: when your main PC is broadcasting to a local RTMP endpoint or a direct stream URL, the Pi pulls that feed and republishes it to your CDN so viewers see no interruption.
  • Fallback loop: when the Pi detects the main feed is gone, it will switch to a local fallback video, animated loop, or a “we’ll be right back” scene with audio/music and overlays.
  • Failover is automatic. I use a small supervisor script that monitors the ffmpeg process and swaps inputs depending on reachability of the main stream, or whether the pulled stream fails with audio/video errors.

    Hardware and cost estimate

    ItemExampleEstimated cost (USD)
    Raspberry Pi 4 (4GB)Any 4GB Pi 4 board$60
    microSD card (32–128GB)SanDisk Ultra 64GB$10–15
    Power supply (USB-C 3A)Official Pi PSU$8–10
    Case + coolingFan/heatsink case$10–20
    Optional: USB capture deviceHDMI-to-USB capture (if you want local capture)$20–50
    Network (Ethernet recommended)Cat5e cable / switch$0–10

    Typical total: ~ $110–$175 without capture card. Even with a capture card you stay well under $300.

    Network & stream topology

    There are a few ways to wire this depending on where your main PC is sending:

  • Main PC streams to your CDN (Twitch/YouTube) and the Pi monitors that CDN stream URL and republishes to the same target. This is possible but often limited by CDN access and latency.
  • Main PC streams to a local RTMP server on your network (e.g., Nginx RTMP on a small NAS or the Pi itself). The Pi pulls from that local RTMP and pushes to CDN. This is my preferred topology because it gives reliable, low-latency access to the origin feed.
  • Main PC outputs HDMI and the Pi uses a capture card to ingest directly. This is useful if you want the Pi to be the immediate fallback with scene control, but requires a capture device and some local bitrate compromise.
  • My recommendation: set the main PC to publish to a small local RTMP endpoint (either on the Pi or another always-on device). The Pi’s ffmpeg can then pull rtmp://local-ip/live/key and push to rtmp://cdn/app/stream_key. If the local pull dies, the Pi swaps to a local file.

    ffmpeg patterns and commands

    Two useful ffmpeg commands: one to restream your main feed with minimal CPU usage (copy stream), another to play fallback content with re-encoding.

    Restream (low CPU if codecs are passthrough):

    ffmpeg -re -i rtmp://MAIN_PC_IP/live/streamkey -c copy -f flv rtmp://CDN/app/STREAMKEY

    Fallback loop (example: loop a 30-second mp4 with an audio bed):

    ffmpeg -stream_loop -1 -re -i /home/pi/fallback.mp4 -c:v libx264 -preset veryfast -b:v 2500k -maxrate 3000k -bufsize 6000k -c:a aac -b:a 128k -f flv rtmp://CDN/app/STREAMKEY

    Notes:

  • Use -re when playing files to simulate real-time input for CDN compatibility.
  • Tune bitrate (-b:v) to your CDN package and uplink capacity; 2.5–4 Mbps is a good compromise for 720p/30 or 1080p/30 if your uplink supports it.
  • Hardware acceleration on Pi 4 is limited for ffmpeg builds; you can use software libx264 with veryfast preset to balance CPU and quality. If you buy a Pi with more cooling, the Pi can handle moderate encoding without overheating.
  • Supervisor script (simple auto-swap)

    Below is a minimal bash supervisor. Drop it at /usr/local/bin/standby-supervisor and mark executable.

    #!/bin/bashMAIN_URL="rtmp://192.168.1.50/live/stream"CDN_URL="rtmp://live.twitch.tv/app/STREAMKEY"FALLBACK="/home/pi/fallback.mp4"LOG="/var/log/standby.log"while true; do echo "$(date) - Trying to pull main feed" >> $LOG ffmpeg -y -timeout 5000000 -re -i "$MAIN_URL" -c copy -f flv "$CDN_URL" RET=$? echo "$(date) - ffmpeg exited with $RET" >> $LOG echo "$(date) - Starting fallback loop" >> $LOG ffmpeg -stream_loop -1 -re -i "$FALLBACK" -c:v libx264 -preset veryfast -b:v 2500k -maxrate 3000k -bufsize 6000k -c:a aac -b:a 128k -f flv "$CDN_URL" echo "$(date) - Fallback ended, retrying main pull in 5s" >> $LOG sleep 5done

    What happens: the first ffmpeg attempts to pull main feed. If it stops (main PC crashed, or local RTMP disconnects), ffmpeg exits and the script starts a fallback loop. If the main feed returns and your local RTMP accepts it, the first ffmpeg will succeed on the next loop, swapping back automatically.

    Systemd service

    Create a systemd unit at /etc/systemd/system/standby.service to run at boot and restart on failure:

    [Unit]Description=Standby Encoder SupervisorAfter=network-online.target[Service]Type=simpleExecStart=/usr/local/bin/standby-supervisorRestart=alwaysRestartSec=5User=pi[Install]WantedBy=multi-user.target

    Enable and start with: systemctl enable --now standby.service

    Operational tips and gotchas

  • Keep a short GOP/keyframe interval: set your main encoder to 2–4 second keyframes so the Pi can align frames when restreaming. Inconsistent keyframe intervals cause glitches during handoff.
  • Monitor CPU and temperature: log top/htop and dmesg early to catch thermal throttling. Add a fan if load is high.
  • Test frequently: simulate main PC drops and watch the CDI switch. Use local test streams to ensure timing and overlays behave.
  • Overlay consistency: if you need branded overlay/scene parity, bake static overlays into your fallback file. Live dynamic overlays (like recent followers) require additional software that is heavier to run on Pi.
  • Security: secure the local RTMP endpoint with basic keys and keep the Pi behind your router firewall. Rotate keys just like you would for your main stream.
  • When this setup is not enough

    If you run multi-input productions (capture cards, multiple camera sources, NDI mixing), a Pi fallback won't match production quality. In those cases, consider a secondary Windows/Intel NUC-based encoder that can run OBS as a warm spare. But for many creators and small teams, the Pi approach provides immediate, inexpensive resilience that prevents total stream loss.

    If you want, I can tailor the supervisor to check health via ffprobe (to detect frozen frames or audio silence), add auto-upload of alerts to Discord/Slack when failover happens, or show a ready-to-copy guide that uses Nginx-RTMP as the local relay. Tell me which CDN you use and whether you want capture-input or file-loop fallback and I’ll provide the specific commands and configs.

    You should also check the following news:

    How to calibrate color profiles across two webcams and a capture card so face tones match on multi‑camera streams
    Streaming Tips

    How to calibrate color profiles across two webcams and a capture card so face tones match on multi‑camera streams

    I’m often asked how I get near-identical skin tones across multiple cameras — especially when...

    Jun 13 Read more...
    The exact restream.io routing test that predicts chat and donation consistency across platforms
    Workflow Tools

    The exact restream.io routing test that predicts chat and donation consistency across platforms

    I run a lot of multi-platform streams. Over the last five years I’ve built repeatable tests to...

    May 14 Read more...