Skip to main content

Stream from your own encoder and embed the player

This guide takes a stream from creation to your own web page: you create a stream in your organisation, send video to it from OBS or ffmpeg, embed the nanoStream Player with the stream's playout name, and check the result in nanoStream Analytics. Unlike the Quickstart, the stream you create here is a permanent stream you can reuse every time you go live.

Before you start​

You needDetails
An accountA free account or your existing nanocosmos login. Create one in the Builder Hub; see Quickstart, Step 1.
A role that may create streamsnanoAdmin or nanoUser. nanoReadOnly can't create streams. See Organisation, users & roles.
An encoderOBS Studio, ffmpeg, vMix, Wirecast or a hardware encoder that sends RTMP
A web pageAny HTML page where you can paste an iframe or a script

Step 1: Create a stream​

Pick one of three ways. All three create the same kind of stream in your organisation.

Option A: Builder Hub​

  1. Sign in to the Builder Hub.
  2. On Home, click Create your stream (first stream) or New stream. You can also create one under Streams › New stream.
  3. The stream card on Home now shows the Stream name, RTMP server and Stream key, each with a Copy button.

For a guided version of the whole path (pick or create a stream, go live from your encoder, watch and replay), open Build › Stream › Go Live Workflow. It needs a free or production account.

Option B: nanoStream Dashboard​

  1. Sign in at dashboard.nanostream.cloud with the same email and password.
  2. Open dashboard.nanostream.cloud/stream/create.
  3. Optionally add Tags, Transcoding Profiles for Adaptive Bitrate Streaming, Live Processing, Live Captions or a Timecode.
  4. Click Create New Stream. The instructions page that opens shows the RTMP stream name and RTMP URL under Start the Ingest.

See nanoStream Dashboard for every option.

Option C: nanoStream REST API​

The nanoStream REST API is also called the bintu API; its hostnames and headers keep the bintu name. Create a stream with your organisation's API key:

BINTU_API_KEY=<YOUR_API_KEY>

curl --request POST \
--url https://bintu.nanostream.cloud/stream \
--header "x-bintu-apikey: $BINTU_API_KEY" \
--header "content-type: application/json" \
--data '{ "tags": ["my-first-stream"] }'

In the response, the ingest details are under ingest.rtmp (url and streamname), and the name for playback is under playout.h5live[0].rtmp.streamname. The API key belongs on your server, never in a web page. See APIs & SDKs overview and nanoStream REST API.

info

Ingest name vs playout name. A stream has a name for sending (the ingest stream name, also shown as stream key) and a name for playing (the playout stream name). They are often the same string, but not always. Always put the playout name into the player. The ready-made code snippets already use the right one. See Key concepts.

Step 2: Send video to the stream​

You need two values from Step 1: the RTMP URL (server) and the stream name (stream key). Copy them exactly; don't build the URL by hand. A stream with Adaptive Bitrate Streaming can have a different ingest host than a stream without it.

Recommended encoder settings: H.264 video, AAC audio, a keyframe every 2 seconds, no B-frames. Details per encoder are in RTMP ingest & encoder settings.

OBS Studio​

  1. Open Settings › Stream and set Service to Custom.
  2. Paste the RTMP URL into Server and the stream name into Stream Key.
  3. Under Settings › Output (Advanced mode), set Rate Control to CBR and Keyframe Interval to 2.
  4. Click Start Streaming.

ffmpeg​

Send a video file, looped in real time:

RTMP_URL="rtmp://bintu-stream.nanocosmos.de/live" # copy yours from Step 1
STREAM_NAME="XXXXX-YYYYY" # your ingest stream name

ffmpeg -re -i input.mp4 \
-c:v libx264 -preset veryfast -tune zerolatency -g 50 -b:v 1000k \
-c:a aac -b:a 128k \
-f flv "$RTMP_URL/$STREAM_NAME"

No video file at hand? Send a test pattern with a tone instead:

ffmpeg -re -f lavfi -i "testsrc=size=1280x720:rate=25" -f lavfi -i "sine=frequency=150" \
-c:v libx264 -preset veryfast -tune zerolatency -pix_fmt yuv420p -g 50 -b:v 1000k \
-c:a aac -b:a 128k \
-f flv "$RTMP_URL/$STREAM_NAME"

-g 50 sets a keyframe every 2 seconds at 25 fps. If you change the frame rate, change -g with it (for example -g 60 at 30 fps).

Check that the stream is live​

  • Builder Hub: the stream card on Home shows a Live badge and the preview starts on its own.
  • Dashboard: the stream's state changes from created to live.
  • Test player: open https://demo.nanocosmos.de/nanoplayer/release/nanoplayer.html?group.id=XXXXX-YYYYY with your playout stream name.

If the encoder can't connect, see Troubleshooting.

Step 3: Embed the nanoStream Player​

The quickest way is to copy the ready-made snippet from the stream's Code Snippets tab in the nanoStream Dashboard; it is filled in with your playout name and settings. (Streams made with Instant Live Stream in the Builder Hub have their own Embed code under the player.) To write it yourself, use one of the two forms below.

iframe (quickest)​

Paste this where the player should appear and replace XXXXX-YYYYY with your playout stream name:

<iframe
src="https://demo.nanocosmos.de/nanoplayer/embed/2.0.0/nanoplayer.html?group.id=XXXXX-YYYYY"
frameborder="0"
allowfullscreen
width="1280"
height="720">
</iframe>

Keep allowfullscreen if your site supports fullscreen playback.

JavaScript (full control)​

Use the JavaScript player when you want to handle events, change streams or build your own UI:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My live stream</title>
<script src="https://demo.nanocosmos.de/nanoplayer/api/release/nanoplayer.5.min.js"></script>
</head>
<body>
<div id="playerDiv"></div>
<script>
var config = {
source: {
defaults: { service: 'bintu' },
entries: [
{ h5live: { rtmp: { streamname: 'XXXXX-YYYYY' } } } // your playout stream name
]
},
playback: {
autoplay: true,
automute: true,
muted: true,
faststart: true,
latencyControlMode: 'balancedadaptive'
},
events: {
onError: function (e) {
if (e.data.code === 2001 || e.data.code === 2002) console.warn('Stream not found or not live yet');
else console.error(e.data.message || e.data.code);
}
}
};

var player = new NanoPlayer('playerDiv');
player.setup(config).then(function () {
console.log('setup success');
}, function (error) {
console.error(error.message);
});
</script>
</body>
</html>

Browsers only autoplay muted video, which is why autoplay comes with automute and muted. The player picks MOQ (Media over QUIC) where it can and falls back to H5Live by itself.

If your stream…Change the source to
has Adaptive Bitrate Streaming (a stream group)source: { group: { id: '<STREAM_GROUP_ID>', startQuality: 'medium' } } - the player loads every quality of the group and switches between them
is in an organisation with secure playbackadd security: { jwtoken: '<YOUR_JWT>' } next to rtmp in the entry (or inside group). Create the token on your server; see Playback tokens.

Every option is in the Player configuration reference, and more ways to embed are in Embed the player on your website.

warning

Never put your API key in a web page. The player needs only the playout stream name (and a playback token if your organisation uses secure playback).

Step 4: Check it in nanoStream Analytics​

Open your page in a few browsers or devices and let it play for a few minutes. Then:

  1. In the Builder Hub, open Build › Analytics › View analytics. Signed in, the boards show your own account's data.
  2. Filter by your stream, and look at concurrent viewers, latency, startup time and buffering.
  3. Home in the Builder Hub also shows four key numbers: traffic this month, peak viewers, playback start success and latency.

Viewer numbers arrive a few minutes after they happen, so the last minutes fill in shortly.

The snippet above sends no player metrics. Startup time, buffering ratio, playtime and playback start success only appear when the player config has a metrics block with accountId and accountKey. You get these values from nanocosmos support or sales; the Dashboard doesn't show them. See Player configuration › metrics. Ingest monitoring works without it.

See the Analytics dashboard tour and Metrics explained.

What can go wrong​

SymptomLikely causeFix
Player stays on loading, or reports the stream isn't foundThe stream isn't live, or the player has the ingest name instead of the playout nameCheck the stream is live; use the playout name from the snippet or playout.h5live[0].rtmp.streamname
Player shows an error on a stream that plays in the hubYour organisation uses secure playbackAdd a valid playback token; see Playback tokens
Encoder is rejectedWrong stream name, or another encoder is already sending to itCopy the stream name again; stop the other encoder
ABR qualities never appearStream sent to the wrong ingest hostUse the exact RTMP URL shown for that stream
Stuttering, long startBitrate too high for the uplink, or keyframes too far apartLower the bitrate; keyframe every 2 seconds

More in Troubleshooting.

tip

Try it in the Builder Hub: the Go Live Workflow walks you through this whole path step by step, from stream to replay. See the Builder Hub guide. Start for Free

Next steps​