MediaSFU Blog

Go Live from OBS into Your App with WHIP, Then Reach Everyone with HLS

· Tutorial

A laptop running a live production with a camera beside it; a teal signal leaves the laptop and splits into a video call of four people and a row of phones, a TV and a tablet playing the same show.

You already produce your show in OBS: scenes, lower thirds, a second camera, a screen capture. With WHIP you can send that program straight into a MediaSFU room, so the people in the room see it as a live participant. Then you can turn the same stream into an HLS broadcast that plays on any phone, TV or browser, for as many viewers as you need.

This guide takes you from an empty project to a live show in four requests. No streaming server to install and no plugins: OBS Studio 30 and later speaks WHIP out of the box.

What you will build

Diagram: OBS Studio sends the show over WHIP into a MediaSFU room. From the room, hosts and guests watch over WebRTC, real-time players watch over WHEP, and large audiences on phones, TVs and laptops watch over HLS.

OBS sends one stream into the room. Hosts and guests see it live over WebRTC, players that need real time use WHEP, and everyone else watches the HLS broadcast.

By the end you will have:

  • a room your host and guests can join,
  • OBS publishing into that room over WHIP,
  • an HLS broadcast with a player you can drop into any page,
  • a clean way to end it all when the show is over.

Why WHIP

WHIP (WebRTC-HTTP Ingestion Protocol) is an open standard for sending WebRTC media with one HTTP request. For a live show it gives you three things:

What you getWhy it matters
Sub-second delivery into the roomHosts can react to the program feed as it happens, not seconds later.
One URL and one tokenOBS needs a server address and a bearer token. Nothing else to configure.
Built into OBS 30+Choose WHIP as the service in OBS settings. No plugins.

OBS sends H.264 video and Opus audio over WHIP, which is exactly what a WebRTC room expects, so nothing needs to be re-encoded on the way in.

Before you start

  • OBS Studio 30 or later (or any encoder that supports WHIP).
  • A MediaSFU API username and key. Get them at mediasfu.com/api-keys. Start with a sandbox key: sandbox rooms start with s, production rooms with p.
  • A server-side place to keep the key. Every request below runs on your server. Never put your API key in a browser or app.

Set two environment variables on your server:

export MEDIASFU_API_USERNAME="your-api-username"
export MEDIASFU_API_KEY="your-api-key"

Step 1: Create the room

curl -X POST https://mediasfu.com/v1/rooms/ \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $MEDIASFU_API_USERNAME:$MEDIASFU_API_KEY" \
  -d '{"action":"create","userName":"host","duration":60,"capacity":10,"eventType":"webinar"}'

The response includes roomName (the room's ID, which the streaming routes call meetingID) and publicURL. Open publicURL to enter as the host. The room is now live and ready for the stream.

export MEETING_ID="s9x2k7mp4q81"   # the roomName from the response

Step 2: Create a WHIP ingest session

Ask MediaSFU for a place to send the stream:

curl -X POST "https://mediasfu.com/v1/meetings/$MEETING_ID/external-sessions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $MEDIASFU_API_USERNAME:$MEDIASFU_API_KEY" \
  -d '{"displayName":"Studio camera","ingest":{"protocol":"whip","tracks":["audio","video"]}}'

You get back everything OBS needs:

{
  "success": true,
  "sessionID": "ems_…",
  "state": "…",
  "ingest": {
    "protocol": "whip",
    "tracks": ["audio", "video"],
    "url": "https://…",
    "token": "…",
    "expiresAt": "…"
  }
}

Keep sessionID: you will use it to check the stream, start the broadcast and end it later. The token is short-lived, so start streaming before expiresAt.

Step 3: Point OBS at the session

  1. In OBS, open Settings → Stream.
  2. Set Service to WHIP.
  3. Paste ingest.url into Server.
  4. Paste ingest.token into Bearer Token.
  5. Click OK, then Start Streaming.

Put the token in the Bearer Token field. It doesn't go in the URL.

A tip for later: if you plan to broadcast with HLS, set a keyframe every 2 seconds in Settings → Output. HLS can then cut segments cleanly, and viewers join faster.

Step 4: Check that it is live

curl "https://mediasfu.com/v1/meetings/$MEETING_ID/external-sessions/$SESSION_ID" \
  -H "Authorization: Bearer $MEDIASFU_API_USERNAME:$MEDIASFU_API_KEY"

When state is active and your tracks are listed, look at the room: the stream is there as a participant called "Studio camera". Your hosts can talk over it, bring guests on stage and run the show from the room.

Step 5: Reach everyone with HLS

The room is built for people who take part. For everyone who only watches, start an HLS broadcast from the same stream:

curl -X POST "https://mediasfu.com/v1/meetings/$MEETING_ID/broadcasts" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $MEDIASFU_API_USERNAME:$MEDIASFU_API_KEY" \
  -d "{\"sourceSessionID\":\"$SESSION_ID\"}"

The response gives you broadcastID, the renditions viewers can get (the source quality and the lower ones), and three kinds of playback address:

FieldWhat it is
playbackUrlThe address viewers should use. It may be served from a CDN.
playbackUrlsMore addresses to try, in order.
originPlaybackUrlThe same stream straight from the media server. Keep it as the last fallback.

Wait until the broadcast reports that it is active, then hand the addresses to your page from your server. They carry a short-lived token, so fetch fresh ones when they expire.

Step 6: Play it on any page

Diagram: how the player picks an address. It tries playbackUrl (the CDN) first, then the playbackUrls in order, then originPlaybackUrl on the media server, moving on each time one fails. A 401 or 403 stops it.

hls.js plays HLS in most browsers, and iOS Safari plays it natively. This player tries each address in order and moves on when one fails. On a 401 or 403 it stops, because a refused token will be refused everywhere:

<video id="live" controls playsinline muted autoplay></video>
<script src="https://cdn.jsdelivr.net/npm/hls.js@1"></script>
<script>
  // From your server, in this order: playbackUrl, then playbackUrls, then originPlaybackUrl.
  const urls = ['PLAYBACK_URL', 'ORIGIN_PLAYBACK_URL'];
  const video = document.getElementById('live');
  let index = 0;
  let hls = null;

  function play() {
    const url = urls[index];
    if (window.Hls && Hls.isSupported()) {
      if (hls) hls.destroy();
      hls = new Hls();
      hls.on(Hls.Events.MANIFEST_PARSED, () => video.play().catch(() => {}));
      hls.on(Hls.Events.ERROR, (_event, data) => {
        if (!data.fatal) return;
        const status = data.response && data.response.code;
        if (status === 401 || status === 403) return; // refused: don't try elsewhere
        if (++index < urls.length) play();
      });
      hls.loadSource(url);
      hls.attachMedia(video);
    } else {
      video.src = url; // iOS Safari plays HLS natively
      video.onerror = () => { if (++index < urls.length) play(); };
    }
  }
  play();
</script>

Using the MediaSFU web SDK? getHlsPlaybackCandidates(broadcast) builds the same list for you, and attachPlayback({ source, fallbackSources }) plays it with the same rules, in SDK versions that include them.

Put it together on your server

Here is the whole flow as one Node.js (18+) script you can adapt. It starts the stream and the broadcast for a room, and returns what OBS and your player need:

const BASE = 'https://mediasfu.com';
const AUTH = `Bearer ${process.env.MEDIASFU_API_USERNAME}:${process.env.MEDIASFU_API_KEY}`;

async function call(method, path, body) {
  const res = await fetch(`${BASE}${path}`, {
    method,
    headers: { 'Content-Type': 'application/json', Authorization: AUTH },
    body: body ? JSON.stringify(body) : undefined,
  });
  const data = await res.json();
  if (!data.success) throw new Error(`${path}: ${data.code || res.status} ${data.error || ''}`);
  return data;
}

const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

// 1. Give OBS somewhere to send the stream.
async function startIngest(meetingID) {
  const s = await call('POST', `/v1/meetings/${meetingID}/external-sessions`, {
    displayName: 'Studio camera',
    ingest: { protocol: 'whip', tracks: ['audio', 'video'] },
  });
  return { sessionID: s.sessionID, obsServer: s.ingest.url, obsBearerToken: s.ingest.token };
}

// 2. Once OBS is live, start the HLS broadcast.
async function startBroadcast(meetingID, sessionID) {
  for (let i = 0; i < 30; i++) {
    const s = await call('GET', `/v1/meetings/${meetingID}/external-sessions/${sessionID}`);
    if (s.state === 'active') break;
    await sleep(2000);
  }
  const b = await call('POST', `/v1/meetings/${meetingID}/broadcasts`, { sourceSessionID: sessionID });
  const urls = [b.playbackUrl, ...(b.playbackUrls || []), b.originPlaybackUrl].filter(Boolean);
  return { broadcastID: b.broadcastID, renditions: b.renditions, urls };
}

// 3. When the show ends: broadcast first, then the ingest session.
async function endShow(meetingID, sessionID, broadcastID) {
  await call('DELETE', `/v1/meetings/${meetingID}/broadcasts/${broadcastID}`, { reason: 'event_finished' });
  await call('DELETE', `/v1/meetings/${meetingID}/external-sessions/${sessionID}`, { reason: 'event_finished' });
}

module.exports = { startIngest, startBroadcast, endShow };

Show obsServer and obsBearerToken only to the person running OBS (an operator page behind your own sign-in), and serve urls to your viewers' player.

HLS or WHEP: which one for your viewers?

HLSWHEP
DelayA few seconds behind the roomReal time, no delay
Best forBig audiences who only watchViewers who react, bid, vote or join the conversation
Plays inAny phone, TV or browserWebRTC players and the MediaSFU SDKs
ScalePut a CDN in front for public audiencesMediaSFU serves 500K+ real-time viewers

Many shows use both: real-time for the people who take part, HLS for everyone else. See WHEP playback for the real-time path.

End the show cleanly

Stop streaming in OBS, then delete the broadcast and the ingest session, in that order:

curl -X DELETE "https://mediasfu.com/v1/meetings/$MEETING_ID/broadcasts/$BROADCAST_ID" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $MEDIASFU_API_USERNAME:$MEDIASFU_API_KEY" \
  -d '{"reason":"event_finished"}'

curl -X DELETE "https://mediasfu.com/v1/meetings/$MEETING_ID/external-sessions/$SESSION_ID" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $MEDIASFU_API_USERNAME:$MEDIASFU_API_KEY" \
  -d '{"reason":"event_finished"}'

If something goes wrong

What you seeLikely causeFix
OBS reports an authorization errorThe token expired, or it was pasted into the URLCreate a new session and paste the token into Bearer Token
A request is declinedThe room has ended, or streaming isn't on for your account yetCheck the room is running. If streaming isn't available, contact support@mediasfu.com
The session never becomes activeOBS hasn't connected yetConfirm OBS shows it is live, then check the session again
The broadcast is declinedThe source has no video yetWait for the session to be active with a video track

Good to know

  • RTMP: OBS 30+ publishes over WHIP, so you don't need RTMP. If your workflow needs RTMP, RTMPS or SRT, contact support@mediasfu.com.
  • Quality: MediaSFU produces the source quality and the lower ones. It never upscales, so send the quality you want viewers to get.
  • Segments: broadcasts use complete CMAF segments rather than partial-segment Low-Latency HLS. When viewers must react in real time, use WHEP.
  • Recordings: if you record the room, recordings are kept for 72 hours and then deleted, so download or deliver them to your own storage within that window.

Next steps

Have a question about your setup? Ask on the MediaSFU forum or reach us at support@mediasfu.com.