Skip to content
Beam Docs
Media

Quickstart: Broadcast

A livestream from OBS or ffmpeg to many viewers over LL-HLS: a session, a stream key, ingest URLs, the player and recordings.

A broadcast takes one stream from an encoder and delivers it to any number of viewers over low-latency HLS through Beam's CDN of Worker edges. Ingest, transcoding into a ladder of renditions, packaging and delivery all run on Workers; latency is 2 to 4 seconds. Transcoding uses a GPU, unless the session asks for the source ladder.


1. Create the session and a stream key

beam media session create --project mprj_... --profile broadcast --name "Launch" --record
beam media stream-key create msn_...

stream-key create prints the key once (bsk_…), the session's ingest URLs and ready-to-run commands. With the API:

curl -X POST "$BEAM_CORE_URL/v1/media/sessions/msn_.../stream-keys" \
  -H "Authorization: Bearer $BEAM_API_KEY" -H "Content-Type: application/json" -d '{"label": "studio"}'
{
  "id": "msk_0123456789abcdefghijklmnop",
  "session_id": "msn_...",
  "status": "active",
  "ingest": {
    "whip_url": "https://<ingest host>/v1/ingest/msn_.../whip",
    "rtmp_server_url": "rtmp://<ingest host>:1935/live",
    "rtmps_server_url": "rtmps://<ingest host>:1936/live",
    "srt_url": "srt://<ingest host>:9000?streamid=#!::r=msn_...,m=publish,s=bsk_..."
  },
  "key": "bsk_...",
  "label": "studio", "created_at": "…", "revoked_at": null, "last_used_at": null
}

The ingest host belongs to the session, not to a Worker: if the ingest Worker is replaced, the same URLs keep working. Keep the key secret: anyone holding it can publish. POST …/stream-keys/{id}/rotate replaces it and refuses the old one at once.


2. Stream

OBS: Settings › Stream › Service WHIP, Server = whip_url, Bearer Token = the key. Or Service Custom, Server = rtmp_server_url, Stream Key = the key. Set the keyframe interval to 2 seconds.

ffmpeg (a test pattern; replace the two -f lavfi inputs with -re -i input.mp4):

ffmpeg -re -f lavfi -i testsrc2=size=1280x720:rate=30 -f lavfi -i sine=frequency=440:sample_rate=48000 \
  -c:v libx264 -preset veryfast -tune zerolatency -g 60 -keyint_min 60 -sc_threshold 0 -b:v 4500k \
  -c:a aac -b:a 128k -ar 48000 -f flv "rtmp://<ingest host>:1935/live/bsk_..."

Over SRT, use -f mpegts and the srt_url. Ingest accepts H.264, H.265 and AV1 video. Beam transcodes it into the session's ladder; the default is 1080p60, 720p60, 480p30 and 360p30 H.264 with AAC audio and 2-second GOPs. Pass --ladder ladder.json (API: ladder) to choose your own renditions, or --ladder source to skip transcoding (below).

Watch the nodes come up:

beam media session topology msn_... --watch

3. The player

Viewers need a subscribe token (from your backend, see Media Tokens) and the SDK's player:

import { Player } from "@beam-network/web-sdk/player";
import Hls from "hls.js"; // optional peer dependency of the player

const { token, directoryUrl } = await fetch("/api/live/token", { method: "POST" }).then((r) => r.json());
const player = await Player.load(token, {
  directoryUrl, // BEAM_MEDIA_DIRECTORY_URL of your environment
  video: document.querySelector("video")!,
  hls: Hls,
});
player.on("state.changed", ({ state }) => console.log(state)); // loading, playing, buffering, …
player.on("rendition.changed", ({ renditionId }) => console.log(renditionId));
player.on("error", (error) => console.error(error.mediaCode));

The player:

  • asks the directory for the nearest edges and fails over between them without user action;
  • checks every segment against the packager's signed hash manifest, so an edge cannot alter the stream (a mismatch is fetched again from another edge);
  • sends quality beacons (stalls, latency, bitrate) that Beam uses to verify delivery.

Any HLS player can also play a public broadcast: join the directory with transport: "hls" and open the first edge's URL with ?token=<token> appended (see join). Such a player skips the hash checks.


Source only broadcasts (no GPU)

A broadcast can skip transcoding: with the source ladder Beam copies your encoder's H.264 video as is, as one rendition source, and converts only the audio to AAC on the CPU. No GPU is needed anywhere, so the stream can run on any Worker with the transcode role. Viewers get your encoder's quality and nothing lower (no adaptive bitrate), so send a bitrate your audience can receive. Everything else stays the same: the CDN, signed segments, the player, protected mode and recordings.

beam media session create --project mprj_... --profile broadcast --ladder source

With the API, "ladder": "source" in the create-session body (broadcast only; stages and calls refuse it). The SDKs take the same option: createSession({ delivery_profile: "broadcast", ladder: "source" }) in Node, Ladder: media.SourceLadderRequest() in Go. The session shows the ladder object in force (up to 1920×1080 and 60 fps, 8 Mbit/s peak, keyframes every 2 s; see Sessions for other caps). A room broadcast channel chooses it in Studio: Output › Transcode ladder › Source only (no GPU).

What your encoder must send, checked by the ingest node:

RuleDefault source ladder
Video codecH.264 only (never HEVC or AV1), profile Constrained Baseline, Main or High, 8-bit 4:2:0, level 5.2 or lower
Frame sizeat most 1920×1080, either orientation (1080×1920 fits too)
Frame rateat most 60 fps
Keyframesan IDR at least every 2 s; a fixed 2 s interval without scene-cut keyframes keeps every segment at 2 s. B-frames are allowed
Bitrateat most 8 Mbit/s (a stream above 16 Mbit/s over 10 s is closed)
Tracksa video track is required; audio is optional, any codec

A WHIP offer without H.264 in an accepted profile is refused with 415 codec_not_allowed. Any other stream that breaks a rule (RTMP, RTMPS, SRT, or a WHIP stream that later goes over the limits or stops sending keyframes) is closed, and your backend gets the ingest.disconnected webhook with reason source_incompatible. The stream key stays valid: fix the encoder settings and reconnect.

OBS, RTMP or SRT: Settings › Output › Output Mode Advanced; Encoder x264 or a hardware H.264 encoder (NVENC H.264, Apple VT H.264, QuickSync H.264); Rate Control CBR, Bitrate 6000 Kbps (at most 8000); Keyframe Interval 2 s; Profile high (or main). Video › Output resolution at most 1920×1080, FPS at most 60. Advanced › Video › Color Format NV12 (I444 or P010 make the encoder send High 4:4:4 or 10-bit H.264, which is refused). Any audio encoder. Stream: Server = rtmp_server_url, Stream Key = the key.

OBS, WHIP (OBS 30 or later): Service WHIP, Server = whip_url, Bearer Token = the key; H.264 encoder with Keyframe Interval 1 or 2 s and Color Format NV12. OBS sends Opus audio over WHIP; Beam converts it to AAC.

ffmpeg, encoding (-g = frame rate × 2 for 2-second keyframes):

ffmpeg -re -i input.mp4 \
  -c:v libx264 -profile:v high -pix_fmt yuv420p -preset veryfast -b:v 6M -maxrate 6M -bufsize 12M \
  -r 60 -g 120 -keyint_min 120 -sc_threshold 0 \
  -c:a aac -b:a 128k -ar 48000 -f flv "rtmp://<ingest host>:1935/live/bsk_..."

Over SRT, -f mpegts "<srt_url>" (the URL holds the key). A file that is already H.264 4:2:0 within the caps above (profile, level, size, frame rate, bitrate) with keyframes at most 2 s apart can go without re-encoding: ffmpeg -re -i input.mp4 -c:v copy -c:a aac -f flv "rtmp://…/bsk_...".

Billing: transcode rendition minutes count encoded renditions only. The copied video is not encoded, so a source broadcast bills one rendition (its audio) instead of five for the default ladder.


Protected broadcasts

--protection protected encrypts segments (CMAF cbcs) so edges and caches carry ciphertext only. The SDK fetches the content keys with the viewer's token from POST /v1/media/content-keys (EME ClearKey), or from your own backend serving the same contract; your backend reads the keys with GET /v1/media/sessions/{id}/content-keys. Safari and native Apple players cannot play protected broadcasts yet: the directory answers them 409 protected_unsupported. Protected mode is not end-to-end encryption: the transcoder sees the source.


Recordings

A session created with --record keeps a recording in Worker storage. List it once the stream has ended:

beam media recording list msn_...

A recording plays like a broadcast: mint a token whose session is the recording id (mrec_…) and Player.load with it. Its manifests are the ones the live packager signed, so playback is verified the same way. recording.ready and recording.failed webhooks tell your backend when it can offer it.

Decentralized distributed bandwidth infrastructure.

On this page