# Interactive DJ Live Streaming: Hybrid WebRTC and RTMP

> A 2020 lockdown startup: a DJ's live broadcast over RTMP, with a VJ mixing in guests' WebRTC video calls from home. Piloted live from an empty bar.

**In short:** in the 2020 lockdowns DJs streamed their sets, and fans watched them alone at home. To fix that, I built a startup proof of concept: guests turn their cameras on, and a VJ puts the best of them on air next to the DJ.

Video calls over WebRTC were instant but warped the music, broadcasts over RTMP sounded right but lagged, so the design that worked used both. More challenges and lessons below.

<div class="fact-table">

| Project | DJVID, interactive DJ live streaming for remote parties |
| --- | --- |
| **Years** | 2020, April to July |
| **My role** | Came up with the startup idea and led the R&D team |
| **Team** | Solution architect, lead software engineer for web and mobile, DevOps engineer, two frontend engineers, R&D engineer, product designer, streaming advisor, an organiser and a DJ |
| **Stage** | Piloted proof of concept |
| **Tech** | WebRTC, RTMP, HLS, OBS, Mux, Twilio Video, Red5 Pro, Jitsi, React, React Native, Firebase, nginx, YouTube Live, Vimeo |
| **Outcome** | Failed: the market lasted only as long as the lockdowns |

</div>

## Why

In spring 2020 nightlife stopped. I missed going out, and my DJ friends missed playing. Back then I ran dvhb, a startup R&D studio that designed, built and launched startups for clients and for itself ([more of them here](/projects/founder?src=ai-md)), and DJVID was one of its own ideas. Every DJ moved online, and some live streams were spectacular, like David Guetta's set from a Miami rooftop.

[David Guetta | United at Home - Fundraising Live from Miami](https://www.youtube.com/watch?v=Vr2FLgmWCJA)

*David Guetta live from Miami, April 18, 2020: a fundraising set streamed from a rooftop.*

But a DJ set is more than the music, whether it's in a club, a bar or at a pre-party. It's the people around you: dancing together, running into friends, talking, the energy of the room. On a stream you are completely alone. Friends of mine threw an online party with a great location, lights and a camera crew. It looked stunning, but all you could do was watch, so I never went to the next one. A chat window is not a crowd. The sound was poor too: Instagram Live, where many DJs played, caps audio at 128 kbit/s.

![Frame of a live DJ broadcast: DJ Aver with blue hair at his decks in an empty bar](https://saalse.com/_astro/dj-live-broadcast-empty-bar.DU9webvh_Z26SlyV.webp)

*DJ Aver at the decks, streaming from an empty bar at our pilot, June 2020.*

One night I was watching my mate DJ Aver play requests on Instagram, and wrote to him afterwards:

> **Misha shouted “everybody together!” A club would roar. Here nobody roars. We'll make everyone roar.**
>
> — Me, to the DJ, April 2020

So the question was: what if the people partying at home became part of the stream?

## The idea

![Whiteboard sketch titled DJVID-19 with arrows between the DJ, a camera, HD audio, a laptop with OBS, a server, the partygoers' mobile app, a VJ app with a grid of guests and watchers in front of a TV](https://saalse.com/_astro/dj-streaming-whiteboard-architecture-sketch.lz7iGeMC_cYCeD.webp)

*My first sketch of the scheme on the whiteboard, April 2020.*

- **The DJ broadcasts.** The set, with good HD sound, from an empty club or from home.
- **Guests join.** On their phones, cameras on if they like. It's always their choice.
- **A VJ picks.** Who goes on air next to the DJ.

Think of a DJ party crossed with Chatroulette: random people partying at home pop up on air next to the DJ. Viewers on a laptop or a TV see a party, not one person behind the decks. The VJ picks whoever is having the most fun, with good light, a good frame and a steady connection.

![Mockup of the VJ dashboard: all guest cameras on the left, the guests on air in the middle and the on-air preview with the DJ and three guests on the right](https://saalse.com/_astro/vj-dashboard-mockup.YvFrRDz2_1qeSlG.webp)

*The VJ's dashboard: one click puts a guest on air.*

### How many people fit on one screen

To make watching rich, I wanted the picture on air to keep changing through the set, so the app needed several interactive layouts. Each had to work on every screen and camera: a laptop, a phone in portrait, a phone in landscape.

That gave the app a set of problems to solve: a queue of people waiting to go on air, a layout that falls back to however many are streaming, and a 5-4-3-2-1 countdown before anyone goes live. If someone's phone went to sleep, the next in line took the slot, so the screen never turned black.

- DJ only
- DJ and one guest
- Three guests on the side
- Three guests below

Most partygoers would join from their phones, so our designer worked through small screens, front and rear cameras, and how people hold a phone.

At first I asked everyone to hold the phone in landscape. That was a mistake: people hold a phone in portrait, especially while they dance with it. We redesigned the app around portrait, with the DJ's picture framed to fit both ways.

## A weekend that took eleven weeks

The plan was a quick experiment over one weekend (vibe coding didn't exist yet). Every easy route failed in its own way:

1. **Zoom**, April 5 (Poor sound, no VJ controls): I tried it with friends the first night. Zoom squeezes the sound, and the host of a video conference can't choose what viewers see.
2. **OBS and Mux** (40 s delay): OBS mixed the stream and Mux, a video streaming service, sent it out. The music reached a phone at home 40 seconds late, and the dancing came back later still.
3. **Red5 Pro** (Two weeks, no result): Our own video server, picked over Wowza, couldn't show the DJ and a guest in one window on a phone.
4. **Twilio Video** (Music wobbled): Picked over TokBox and Jitsi. Our own little Zoom worked in two weeks, then the beat started to drift.
5. **The hybrid** (Worked): The DJ broadcasts to YouTube or Vimeo and guests send video only through Twilio.
6. **The pilot**, June 20 (One evening): A live set from an empty bar, with a real crowd at home.

The solution was to stop asking one technology to do two jobs:

- **Broadcast over RTMP.** YouTube Live, Instagram Live and the like. Seconds of delay, the same for every viewer, and high-quality audio.
- **Video calls over WebRTC.** Zoom, FaceTime and the like. Under a second of delay, so people can talk, but the audio is tuned for voices.

The DJ broadcasts from OBS to YouTube or Vimeo, like most DJs did in 2020, with full sound quality. Around that broadcast we built a separate video room where guests send only their video, no sound. On a weak connection WebRTC lowers a guest's video quality to keep up, but it never touches the music. The details are [under the hood](#under-the-hood-delay-codecs-and-architecture), at the end of the page.

### Getting the DJ on air

The DJ's side was a challenge of its own: broadcasting had to be easy for a DJ, not an engineer, and carry the sound straight from the mixer. We tried two setups:

1. **Plan A: a phone** (No line-in): The DJ's mixer can feed an iPhone over a cable, but the Vimeo app only hears its own microphone.
2. **Plan B: a laptop** (Worked): Sound from the DJ mixer through a sound card into OBS, an iPhone as the camera. In 2020 encoding Full HD was heavy for a laptop: a 2016 MacBook Pro dropped frames. The broadcast also needs about 7 Mbit/s of upload.

### You can't test a party alone

The hardest part wasn't the code. A party can't be designed or tested by one person at a desk. The minimum test session:

- **3 people, 3 roles.** A DJ, a VJ and a guest, swapping roles every round so each of us had been all three.
- **4 devices, 4 accounts.** A laptop as the DJ, a screen as the VJ and two phones as guests, each signed in to its own account, on its own connection.
- **1 call on the side.** Nobody can tell from their own screen what the others see.
- **Recordings, not logs.** Collecting logs from every device to analyse the delay was a job in itself. It was faster to film a stopwatch next to the screens and compare the recordings. With no DJ around, iTunes through a virtual audio cable played the music.

## The pilot

On Saturday, June 20, at 11 pm, DJ Aver streamed a one-hour set from an empty bar. He had invited a closed group of about 30 fans to join the live broadcast from home.

![Seven-second clip from the pilot night in the bar: the DJ waves, then the camera pans over the decks and the ring light with the phone that films him to two laptops running the broadcast](https://saalse.com/_astro/dj-pilot-night-clip-poster.CvqK1uiG_1LWG3y.webp)

*Behind the broadcast. Turn the sound on to hear the bar.*

![A guest's phone on djvid.club: the DJ's live broadcast from the bar at the top, and the guest's own camera below](https://saalse.com/_astro/guest-phone-view-dj-live-stream.CthmTFEG_b4NQt.webp)

*What a guest saw.*

Analytics showed 24 online at the peak, and five guests got into the video room that streams their dancing back. The stream hung once and had to be restarted, and video from phones on mobile data was choppy. In our team chat that night:

**Team chat** (during the pilot):

> Why does the guests' video look like it's from a Nokia 3310?
>
> The sound is nice, though
>
> Random faces really liven it up
>
> The channel needs warming up

The biggest surprise came at the door. The invitations went out in Instagram stories and messengers, and people opened the link right there, in the app's built-in browser, where the stream couldn't run at all. They decided the whole thing was broken:

**Guests' browsers at the pilot, % of visits**

- Safari: 59
- Chrome: 17.9
- Safari inside another app: nothing worked: 17.1
- Firefox: 4
- Android WebView: 2

*Shares read off the site analytics chart. Firefox and Android WebView are approximate.*

So at least 17% of visitors never saw a thing. Even in a proper browser, the sound didn't always start on its own, and two guests on the same evening had opposite experiences:

**Guest #1** (during the pilot):

> Where to next?
>
> **Us:** Tap the top right
>
> **Us:** to turn the sound on
>
> There's sound
>
> But everything freezes

**Guest #2** (during the pilot):

> **Us:** We're restarting it now
>
> **Us:** Come back a bit later, please
>
> Okay 👌
>
> Everything works perfectly

That's what a proof of concept was for: one evening showed problems no amount of design would have found.

## What the guests said

After the set, we surveyed everyone who came and counted every comment:

**Comments after the pilot, by topic**

- The app didn't work or glitched: 6
- Stream delay: 4
- No sound (it had to be switched on): 4
- Loved it: 4
- Wants a chat: 3
- Poor quality of guests' video: 3

*Plus one mention each: masks and effects, donations, a way to reach the DJ, seeing more people, a portrait layout, the camera's orientation, the rear camera, good sound and the party atmosphere.*

- **What hurt.** Glitches, from connecting to finding the sound: nobody knew it had to be switched on, or how. Their camera streams lagged and looked poor.
- **What they loved.** The idea of the party itself. They wanted more: a chat, masks, more people on screen at once, donations and a way to reach the DJ.

Their messages:

**Guest #3** (after the pilot):

> I loved the idea that you can drop in on your favourite DJs and party together wherever you are.
>
> But on my iPhone I saw myself and one other window, and it didn't feel like a party where everyone's together. People pop up now and then, they're shy and don't quite know what to do 😄
>
> If you could see everyone, it would feel much more relaxed.

**Guest #4** (after the pilot):

> Sound's great, by the way
>
> **Us:** Something works then :)
>
> What these streams lack most
>
> is talking to the viewers
>
> Add a chat. Then it'll be great
>
> Everyone loves being read
>
> **Us:** Yes, it's in the plans :)

**Guest #5** (after the pilot):

> Everything looks great! My camera won't connect, but I guess that's expected for now.
>
> The biggest risk, I think, is the sound dropping out for a second for whatever reason, server load and so on. Get the tech right, deliver a perfect stream, and it should be great!

**Guest #5** (the next day):

> It'd be fun to have a chat and to look into other people's windows if you want. Like a building where you can peek through someone's window and check how their party's going))
>
> And some effects, like masks, so everyone has more fun.

**Guest #6** (after the pilot):

> Everything was really pleasant. There were tiny video lags, which wouldn't have mattered if I'd just been enjoying it.
>
> As for how viewers could add to the stream: it'd be great to have a way to talk back to the DJ.

**Guest #7** (after the pilot):

> The guests' video quality is very poor, it keeps freezing. Maybe it's their internet.
>
> And let guests use the rear camera, not just the selfie one.

Our own wish list: a view of everyone who was dancing, voting for who goes on air, so the crowd chooses and not only the VJ, and an app that plays the party on speakers or a TV.

And one partygoer put the whole evening in capitals:

> **TALK TO THE CROWD. NOBODY CARES ABOUT THE MUSIC.**
>
> — A guest, after the pilot

## What I learned

- **Find out early whether it dances.** However well we designed the concept, the real room broke the idea in ways I couldn't foresee. We spent weeks on sound, and the crowd wanted conversation.
- **Getting in is part of the product.** The best stream is worthless if the link opens where it can't play.
- **Real-time video is a set of trade-offs.** My deep dive into the sub-second world: broadcast and call protocols, audio and video codecs, jitter buffers, bitrates, and what each optimisation costs. Sound, sync and delay pull against each other, so you choose what each part is best at and test it with people, not on a whiteboard.

## From dance floors to drilling rigs

The deep dive into video streaming paid off a couple of months later, when I started a [real-time computer vision proof of concept on a working drilling rig](/computer-vision-ai/drilling-rig-monitoring?src=ai-md), where CCTV streams had to be read on the spot. Knowing how a video stream gets from a camera to a screen, where delay comes from and what technology can and can't fix made the architecture decisions much faster. The same experience went into later work, such as a [sub-second system that reads live screen streams](/computer-vision-ai/real-time-game-tracking?src=ai-md).

## Where it got to

After the pilot we packed the web app into a cross-platform mobile app, to test the technology for a commercial project. By early July client work had taken over and the clubs were reopening. I had hoped remote parties would keep a niche audience once the clubs reopened, but demand lasted only as long as the lockdowns, so I stopped.

## Under the hood: delay, codecs and architecture

### Why latency was the first wall

The first prototype mixed the DJ's video and sound in OBS with a browser window showing the stream of the guest the VJ had picked, and sent it through Mux, a hosted streaming service. The music reached a phone about 40 seconds late, because it used broadcast protocols:

- **RTMP in, HLS out:** the server cuts the stream into segments several seconds long, and every player buffers a few of them before it starts. Picture and sound stay smooth for every viewer, and the delay adds up to tens of seconds.
- **WebRTC** sends media over UDP and doesn't wait for late packets: it conceals or drops them and lowers the bitrate instead. Delay stays under a second, and quality is the first thing to give.

Guests dancing to the DJ and coming back on air needed the sub-second world, so WebRTC. That ruled out mixing in OBS: in 2020 it had no WebRTC output, and nothing it could send played in a browser with sub-second delay.

![Bar chart of delays. Guests' video in the Twilio room arrives in under 1 second over WebRTC. Over broadcast, two guests' players drift 1 to 2 seconds apart, the DJ's stream through the Vimeo app takes about 30 seconds, and the first prototype through a streaming service took about 40 seconds](https://saalse.com/_astro/delay-video-call-vs-broadcast.DmyuGF59_1vEr3r.webp)

### Red5 Pro, then Twilio

We started with our own WebRTC media server, Red5 Pro (we had also looked at Wowza). Within two days a phone streamed to a browser with less than a second of delay. Then progress stalled. The case that mattered was three phones at once: the first streams, the second plays the first and streams itself, the third plays both. Our first guest app was in React Native, and Red5's SDK for it kept failing on iOS with encoding errors, refused connections and black screens, while in the browser only Safari showed the video. The bottleneck was the mobile SDK, not the server. After two weeks a technical council decided to switch rather than keep tuning.

We looked at TokBox and at running Jitsi ourselves, and picked Twilio Video, a hosted service, after the CTO of an online tutoring platform showed us how far they had customised it. The VJ's control came down to subscriptions: everyone streams into one room, but each role receives only some of the tracks. The VJ receives every guest's video, and everyone else receives only the DJ and the guests on air. The delay stayed under a second.

### Why the music wobbled

The first audio was thin for a simple reason: our app's settings capped it at 12 kbit/s. We raised it to 256 kbit/s, and the music still sped up and slowed down slightly. We ruled causes out one by one:

- **The route:** a Twilio region closer to us, Frankfurt instead of the US, made the lags rarer but didn't stop them. Peer-to-peer, without Twilio's media server, lagged too.
- **Bandwidth and codecs:** cutting the audio bitrate to 128 kbit/s, turning video off and forcing the VP8 or H.264 video codec didn't fix it.
- **Our side:** we ruled out the virtual audio cable and the DJ's mixer. Comparing a direct cable with Twilio showed something else: panning the balance moved the sound over the cable but not through Twilio, so the stream arrived in mono.
- **Other apps:** music looped through Zoom, Skype, Jitsi and Google Meet wobbled in all of them, FaceTime the least.

The lags tracked packet loss, not network jitter. When packets go missing, WebRTC's jitter buffer covers the gap and stretches or squeezes the audio to keep the delay low. Nobody notices it in a voice, but in music every beat drifts. Of WebRTC's codecs only Opus suits music at all, and these apps tune it for speech.

![Diagram of beats: evenly spaced beats as the DJ played them, and the same beats after a video-call jitter buffer, with some gaps stretched and others squeezed](https://saalse.com/_astro/webrtc-jitter-buffer-music-wobble.7LVew2-Y_mC3UY.webp)

### The hybrid

![Architecture diagram with two paths: the DJ's decks and camera go into OBS, then over RTMP at 256 kbit/s stereo to Vimeo and over HLS to every guest's screen. Guests' cameras send video only over WebRTC to a Twilio room, where the VJ picks up to three guests to show on air over the DJ's picture](https://saalse.com/_astro/hybrid-webrtc-rtmp-architecture.7COoAVFe_qQfva.webp)

- **The DJ streams over RTMP from OBS:** no wobble, 256 kbit/s audio and any platform. First YouTube Live, then Vimeo, to get rid of YouTube's player controls on a small screen. As a player, Vimeo was the best of what we tried.
- **Guests join a Twilio video room around that stream,** video only, with audio turned off on every guest track. Their video can degrade without spoiling the music.
- **Everyone sees the DJ with a similar delay,** which mattered more than a short delay. On YouTube the players drifted apart by up to 30 seconds between devices, which made testing hard. On Vimeo the spread came down to 1 to 2 seconds. Mobile browsers don't autoplay video with sound, so guests had to tap to unmute.
- **One room holds 50 participants:** the DJ, the VJ, a restreamer and up to 47 guests who stream. The plan was for everyone else to watch a cheap restream, on the site, YouTube or Instagram, and join the room only to go on air.

### What I'd do today

- **Align, don't chase delay.** Each guest hears the DJ with a different delay and their video comes back later still, so even with WebRTC a guest on air dances off the beat. The fix is a common timeline: the guest's app stamps every camera frame with the DJ stream position it was playing, and the server composes the broadcast a few seconds behind, placing each guest on the beat they danced to. Viewers never notice a few seconds of broadcast delay. It needs your own player with timestamps, not an embedded YouTube or Vimeo player.
- **Tune WebRTC for music where you need it:** stereo Opus at a high bitrate, voice processing off, a larger jitter buffer.
- **Use what exists now:** OBS can publish over WebRTC (WHIP) since version 30, and open-source media servers such as LiveKit compose a room into one stream and restream it over RTMP or HLS. In 2020 this was research. Today, with off-the-shelf media servers and AI coding agents, a working prototype takes days.
- **Test like it's live.** AI agents speed up the code, not the testing. Real-time video still needs [several people on real phones](#you-can-t-test-a-party-alone), real mobile networks and in-app browsers, plus simulated clients to fill the room and emulated networks with packet loss and jitter. Plan that time from the start.

## Working with live video or real-time computer vision?

**[Alex Samson](https://saalse.com/?src=ai-md)**, R&D consultant, computer vision AI. If you need computer vision that reads camera or screen streams in real time, or a live video product tested before you build it, I can help you prove it with a quick proof of concept.

👉 [Plan your proof of concept](/contacts/companies/poc-mvp?src=ai-md)

## Search

Page index: https://saalse.com/llms.txt. Add .md to any page URL for its Markdown.

This site has a search endpoint: https://context7.com/api/v2/ask?siteKey=ask_fae2f8fd691c85cb6b685274&query=<URL-encoded question>. It returns documentation that answers the question, with a source link for each part. No API key is needed. If nothing matches, it says so.
