Schedule-Driven Live Streaming for Indoor Soccer Venues
A Google Sheet now decides when every venue camera goes live on YouTube: an Apps Script endpoint plans the games, and a Raspberry Pi at the venue starts and stops each stream by itself.
The problem
A company that live-streams indoor soccer games had one Raspberry Pi per venue running a hardcoded weekly timetable, so every rainout, reschedule or new game meant someone editing a device by hand. Their real schedule lived in a Google Sheet that the equipment could not see, and from 19 August the games were being recorded but nobody could find them on YouTube.
How I built it
I kept the client's existing setup and added three small pieces beside it: an Apps Script endpoint that turns the schedule sheet into dated stream windows, a Pi poller that reads it every minute and writes the schedule file the venue's scheduler already uses (validated before every write, with a cached copy for outages), and one systemd unit per camera per stream slot so a problem on one field cannot take the other off air. Each game is given one of two YouTube stream slots, A or B, once, and that choice is stored against its game id so back to back games overlap cleanly. Before designing anything I ran ffprobe on the live cameras, found them already sending 16:9 H.264, and dropped the planned re-encode and capacity test, so the Pi only copies the video through (3 minutes 28 seconds of CPU for a 47 minute game, about 7% of one core of four). Planning was written down first: a scope sheet separating what each milestone buys, a decision log of 19 entries, and a one-Pi go/no-go with measured settings. Health reporting, multi-venue config rows and a runbook came last, and the client's manual schedule page stays as the override.
What got hard
- From 19 August the cameras ran every game and the video reached YouTube, yet nobody could watch any of it: at least 24 games measured at zero views, and 31 recordings by 31 August.
I opened every August broadcast and every Pi session rather than trust status labels. The Pi was pushing to a stream key no listing was bound to, and once that was corrected, an audit run from the client's account showed 78 of 78 listings bound to the opposite A/B slot from the sheet. I wrote down the rule YouTube follows when a push arrives (the earliest unspent listing on that stream takes it, even days ahead), used it to predict a night before it happened, and moved the Pi onto the slot the listings already used. In the week after, 14 measured games drew over 750 views.
- The venue's scheduler only understood weekdays ('every Monday 6:48 to 8:25'), never dates, so nothing ever expired. On 17 October a box was set to stream an empty pitch that Thursday because the sheet had no games left and the old file stayed in place.
The endpoint now serves real dated windows from the sheet and the poller rewrites the weekly file from them. I cleared the leftover window with backups and read-backs, then built a permanent fix in the poller for the empty-sheet case, installed on the box on 22 October.
- On 8 October a venue box came back from a restart with its clock about two hours behind, so the scheduler believed two games were live, pushed about 18 seconds to both streams once the network returned, and used up two upcoming game listings.
I rebuilt the sequence from the Pi's journal and the YouTube listings, then made the scheduler wait for the system clock to sync before any camera can start (with a five minute fail-open so a dead internet link cannot block games forever) and kept the journal across restarts. I tested it on the real box: the scheduler started 34.1 seconds after sync in the normal case and 302.5 seconds after the timeout with time sync blocked, and the next game night recorded 3 of 3.
- The client wanted every game on air from five minutes before kickoff to five minutes after the end, which makes back to back games on one field overlap. One YouTube stream carries one broadcast at a time, and a slot rule recomputed on every run would flip booked games onto the wrong stream whenever a row was inserted or rescheduled.
I gave each field two stream slots with one unit per camera per slot, and a single planner that assigns a slot to a game once and stores it against the game id, so a game keeps the slot it was first given. The real test was a game night with both fields running overlapping windows: on 28 September all 7 games were live on their own slot for about 65 minutes each, covering the padded window.
- The schedule endpoint passed every local test, then returned every date one day early the first time it ran inside Apps Script, because the script project's default timezone differed from the sheet's.
Running it in the real environment is what exposed it, since the local test harness never crossed a timezone. I fixed the date handling so it cannot drift whatever timezone the project is set to, and wrote a test that deliberately sets the script's zone ahead of the sheet's and fails if the old code comes back.
The result
All three milestones are delivered: on the go-live night, 9 November, all 7 games ran start to finish on both fields (about 65 minutes each), and 37 of 37 games across eight earlier checked nights from 15 October to 5 November were fully recorded. The client also has the source code, a six chapter runbook and a status tab with email alerts for a quiet Pi or a stream that is due and not live (alerts tested on a copy of the project).
The ← and → keys turn the page too.