Mario Hennenberger
HomeBlogPatent Pending

Code Whiskers FM

Overengineering Background music into an cat-guarded AI music radio station from an old iMac on the floor.

The plan was simple: organise my own background music, so i have something to play in future livestreams. A folder, a playlist, done. Ten minutes, maybe fifteen with coffee.

There was even a serious reason behind it: copyright. Play the wrong song on YouTube, or pretty much any other platform, and a bot decides what happens next. YouTube’s version is called Content ID. It can block your video, hand the ad money to somebody else, or interrupt your livestream while you are still talking. It does not care that the song was only playing quietly in the background, and “royalty free” music is no guarantee either: sometimes a track gets claimed anyway, and then it is on you to prove that you are allowed to use it.

So the idea was to use music that nobody else has a claim on, and let AI make it. A noble plan to stay out of copyright trouble, which has now turned into a plagiarism machine for AI-generated, non-copyright music. An AI that learned from everybody else’s songs makes new ones, so that i don’t get in trouble for using somebody else’s songs. Makes perfect sense, as long as you don’t think about it.

So naturally i now run a radio station. It has its own streaming software, its own YouTube channel and its own dedicated iMac that was sitting on the floor doing nothing since i replaced it with a newer one, now guarded by the Cat’s. Still have to figure out the actual tunes to play, but one step at the time 😉

Meet Code Whiskers FM. It streams my selection of AI-created songs to everyone, in the hope of some virtual fame for music i did not even play myself.
(nothing playing in the video above? Then a cat found out the shitty Lan cable does not lock in place. Try the live page.)

“Quick” Dev session: 23:11, “is this possible?”

It started with one question to Claude: this be done headless on a Linux box?
“just” take audio/video files, draw a visualisation and send the result to YouTube.

Of course it can, ffmpeg does all the heavy lifting. just spend the rest of the night adding about 1,300 lines of Python code to babysit ffmpeg, easy peasy, the resulting code is on GitHub, so you can overdo your own playlist too.

At 23:49 the first version was recording and streaming to a local test server. 38 minutes, including a plan, an S3 uploader and five visualisations. One of them used an ffmpeg filter that turned 3 seconds of audio into 1 hour and 36 minutes of video. Impressive, but not the kind of content i was going for.

Then we built the Docker image, and the disk of my dev machine was full. Not “getting full”. 0 bytes free. That box is a Celeron J1900, so it was already having a bad day.

The cloud, where money goes to die

The music went into a storage bucket in New York. From here in Thailand the upload approached dialup modem speeds, a 16 MB test file never made it. A new bucket in Singapore was 10 times faster, so at least it would finish in our lifetime.

Next stop: DigitalOcean App Platform (referral link). The first deploy crashed because i had not set any settings yet (expected). The next one got shot by the health check, because it ran as a web service and a radio has no website to check (less expected). After that i went shopping for hardware:

  • 1 dedicated CPU, 1 GB: 60 seconds behind.
  • 1 shared CPU, 2 GB: 110 seconds behind. Live, just not today’s live.
  • 2 shared CPUs, 4 GB: keeps up. YouTube says “excellent” and shows no video at all.
  • 2 CPUs, 8 GB: runs smoothly, at 8% memory and 80 USD a month.

80 dollars a month, for a channel with one subscriber. It is an old channel i recycled, so that one person did not even sign up for this. Whoever you are: sorry, and welcome to deep house.

And those 80 dollars may not even be the end of it. The music comes from S3 storage, so data is constantly moving, and traffic charges can make the bill bigger.

To be fair, finding all this out cost me almost nothing. The Droplets, which ran for about an hour each time i changed the hardware, came to $0.44. Testing the configurations on the DigitalOcean App Platform was another $1.89. That is $2.33 for the whole adventure, less than the coffee that went into it. This makes it a great place for developments like this: deployments are fast, easy and done in seconds, and you can try different sizes until the cost fits.

Five hours of “that’s the answer”

Everything worked, except for one tiny detail: the audio was distorted. On a radio. The one thing that has to be perfect.

What followed was a masterclass in being wrong with confidence, from both of us:

  1. The dev machine is too slow. We removed the background image and the sound was perfect. Case closed! It was not.
  2. Tiny gaps in the audio. A real flaw, so it got repaired. “The crackle on YouTube is fixed.” On to production! On DigitalOcean there was exactly one gap, at startup, and it was still distorted. The run that sounded perfect had 67 of them.
  3. YouTube’s latency setting. Later it was on Normal. Still distorted.
  4. Not enough CPU. “That’s the answer”, said Claude. Then a small Droplet sat at 40% CPU, at 480p, and sounded like trash. I got an apology for that one.
  5. The audio bitrate. We put “TEST A” and “TEST B” on screen, so i could hear 192k against 256k. Both were clean. Very helpful.
  6. Two servers fighting over one stream key. Plausible, never proven.

In the middle of this i delivered the most valuable clue of the night: “the distortions disappeared with the next song”. Claude went hunting for it. There was no next song. The file was a 70 minute mix, and what i heard was most likely the restart jumping back to the beginning. Great detective work, me.

The channel had no viewers, so nobody had to suffer through this. First time that ever counted as a feature.

At 6:17 in the morning the distortion came back, right after a restart. This time nobody touched anything. Claude recorded 45 seconds of what the server was really sending and compared it with the original files. They matched closely. It sounded broken, and on paper it was fine.

Digging further did turn up real problems.

Frozen downloads. If a song stopped loading from the bucket, ffmpeg waited for it. Forever. Now it gives up after 15 seconds, reconnects and continues where it stopped. The fix is one option, the comment explaining it is longer:

# also for files: a connection can freeze without closing, and ffmpeg would
# wait forever. After 15 s it fails and -reconnect resumes at the same byte.
cmd += ["-rw_timeout", "15000000"]

The fix that needed a fix. Remember the audio gap repair from point 2? It waited up to 250 ms for every 40 ms piece of sound. With no audio coming in, that slowed the whole stream down to 0.16x. We fixed the sound so well that it nearly stopped time. The scar is still in the code:

# Only wait at the start of a gap and while close to real time. Waiting for every
# chunk (250 ms for 40 ms of silence) would slow the whole stream to 0.16x.
grace = AUDIO_GRACE if not starved and time.monotonic() - due < 1 else 0

An empty hello. On every connection, YouTube first got an empty audio setup message and then the correct one. This is the best suspect we have, but the clean runs had it too:

# aac_seq_header_detect: without it ffmpeg first sends an EMPTY audio setup
# message and only then the real one, which the receiving server may trip over
"-f", "flv", "-flvflags", "no_duration_filesize+aac_seq_header_detect", self.s.stream_url]

We fixed all three, i had the music moved from the bucket onto the server, and the sound was perfect. A later run played for almost 90 minutes without a single glitch.

So what was it? No idea. We changed several things at once, the one thing you should never do when you want to know the answer. But i wanted music, not a PhD.

The shared CPU did not help either. In one five minute stretch, the host held back an average of 35% of the CPU time, with a peak of 79%, and the stream fell up to 37.5 seconds behind. That does not explain the constant distortion, but it did make me look around for a computer that does not have neighbours.

The server was on the floor the whole time

There is an old iMac here that nobody uses anymore. i7, 24 GB of memory, wired network, retired. The rented Droplet managed 720p at 0.75x speed. The iMac did 8.5x, with a heavier encoder preset and more frames per second. (not a perfectly fair test, but come on)

I had been renting computers by the minute while a much faster one was collecting cat hair.

Of course it was not plug and play. Homebrew no longer has ready-made ffmpeg packages for this Intel Mac, and building one version would have dragged in 92 other packages. The first standalone ffmpeg could not draw text. The second one could, but Claude Code’s own permission check refused to copy it. The reason: “Undermining Oversight”. For copying ffmpeg. To a computer on my floor. I said yes, use that one, and then it worked.

Then it was my turn:

  • I updated the code, restarted, and complained that nothing had changed. Twice. The new setting was never in my config file.
  • I cancelled the music copy twice, and one song ended up as a 14 MB piece of a 40 MB file.
  • I started the service on the iMac and got “started”, but no data on YouTube. It was still paused from testing. That one was Claude, so i am counting it as a draw.
  • YouTube suggested a lower video bitrate, so i cut it in half. It changed absolutely nothing. Turns out a picture that does not move is easy to compress. Who knew.

The text on screen uses the free Google font Iceland. It has no bold version, so the bold title is the normal one with an outline. Fake bold, for AI music, on a recycled channel. At least we are consistent.

What it does now

  • It plays a folder. Files starting with a number go first, the rest is shuffled again on every round. I can add or remove songs while it runs, and it notices on the next round.
  • It shows what is playing. The song title comes from the file, or from the file name without the track number. The text is centred, so it also survives YouTube’s portrait view.
  • It keeps going. If a song fails, it sends silence until the next one is ready. If YouTube drops the connection, it reconnects by itself.
  • It also records. The stream can be saved to files and uploaded to S3, with or without YouTube.
  • It has a remote control. No web interface, no app, no account. Just a small script over SSH:

./ctl.sh next      # this song is terrible
./ctl.sh pause     # off air
./ctl.sh resume    # back on air
./ctl.sh status    # what is playing, and is it still alive

The complete playlist logic, the thing i originally wanted, ends in four lines. They shuffle the songs without a number, avoid playing the same one twice in a row, and put the numbered ones first:

random.shuffle(rest)
if not numbered and len(rest) > 1 and rest[0] == last:
rest.append(rest.pop(0))
return [t for _, _, t in sorted(numbered)] + rest

Hiding the track numbers took far more thought than that:

# Track numbers at the start of a file name. Numbers that are probably part of the name
# stay: "7 Rings", "7-Eleven", "24K Magic", "3.14 Pi", "808 State", "2026-11-28 Mix".

It knows 7-Eleven, and it still turns “99 Luftballons” into “Luftballons”. Nena would like a word. (a title tag in the file fixes it)

The whole chain is pretty boring, which is exactly what you want:

music folder
-> decoder (one ffmpeg per song)
-> Python (keeps real time, fills gaps with silence)
-> encoder (one ffmpeg: waveform, text, video, audio)
-> YouTube and/or files

Get linuxstreamer on GitHub

Cat-proof, in theory

The iMac lives on the floor, so a cat or a power cut can take the station off air at any time. It has to come back without me.

So i rebooted it and left it at the login screen. The service started 35 seconds after boot, with nobody logged in. The first connection to YouTube failed because the network was not awake yet, two seconds later it tried again, and the radio was back. I know people who need longer in the morning.

Pulling the plug for real is still untested. I am sure the cats have it on their schedule. I made a snapshot of the Droplet before destroying it, so plan B is only a few clicks away.

The final score

From the first question at 23:11 to the reboot test just before 10 in the morning:

  • about 120 messages from me, about 200 from Claude, and nearly 300 actions
  • 23 commits
  • 4 places to run it: the dev machine, DigitalOcean App Platform, a Droplet and the floor
  • 1 audio problem, gone, cause unknown
  • 0 livestreams using the background music

And for most of that morning, the title on screen said “LoFi” while a lot of the files were deep house. Marketing is clearly my strong side.

Was it worth it? I wanted a playlist and got a radio station, so technically i am ahead. Come over to Code Whiskers FM, put it on while you code, and subscribe if you like it. A second subscriber would be 100% growth, and i could finally put that on a slide.

Leave a comment

Your email address will not be published. Required fields are marked *