Norsk Media Examples

If you followed the TL;DR, you’ve already run one, but Norsk Media comes with a host of examples, some of which do quite complex media manipulation. None of the examples are lengthy or hard to understand and they should give you a good sense of how to go about building your own media solutions with Norsk.

New examples will be added as Norsk evolves so there should always be a demonstration of whatever capability you are interested in. It’s also worth checking out the other repos in the same github account as it also contains some more fully featured libraries and applications.

There is an extensive Readme that goes into more detail, but it is worth a quick note to say that as well as the source code, the examples come with various Docker Compose files. Norsk Media itself is packaged as a Docker Container - and some familiarity with Docker is assumed.

In addition to running the Norsk container, you need to be able to run your Norsk application and also provide it with appropriate sources.

We want to remove as many environmental factors as possible as you start your journey with Norsk - so the examples come with a fully containerized development and runtime environment courtesy of a collection of Docker Compose files and associated run-example script. When you use run-example to start an example app, the associated code is compiled, Norsk is started, the example is started and any input sources needed by the example are launched, so that you should be able to jump straight into viewing the outputs and explore what Norsk is up to via its visualiser.

The Docker Compose files are just there to help you hit the ground running. Don’t take them as any sort of mandated way you should write and compile your code.

There are various flavours of Docker Compose files the run-example script will generate, including Docker Networking, Host Networking and even files that include an example of how Norsk operates seamlessly with log / telemetry environments. Again, the tools and dashboards provided are just examples of one possible setup. Norsk adopts tools such as fluentbit and standards such as OpenTelemetry, precisely as they should make it easy to integrate Norsk into your existing monitoring systems.

Typical Code Structure

One thing to bear in mind as you browse the examples is that most Norsk media applications have a similar shape.

Norsk media provides various methods to create media nodes (the building blocks of a Norsk application). These methods are categorized into input, output, duplex (things that can be both an input and output) and processor (things that manipulate or control your media).

Norsk Media applications tend to set up one or more inputs, optionally apply various transformations and controls to them (with processors) and then publish the resultant streams using one or more outputs. If you look for the pattern as you browse the code it should make your journey easier…​

let input1 = await norsk.input.someInput();
let input2 = await norsk.input.someOtherInput();
...
let processor1 = await norsk.processor.transform.someTransform();
let processor2 = await norsk.processor.transform.someOtherTransform();
...
let output1 = await norsk.output.someOutput();
let output2 = await norsk.output.someOtherOutput();

As the examples get more sophisticated they start to hook some of the callbacks available in the SDK and then make changes to some of the transformations in the workflow in response to those callbacks.

One great example of this is rtmp_mosaic which uses callbacks from the input RTMP server that are triggered when RTMP connections start and stop. In response to these events the code updates the processors to construct a mosaic of all the currently active sources - dynamically resizing / tiling them in response. We think you’ll be surprised how straightforward it all is, for such an advanced capability.

So dive right in and start creating your own amazing live viewer experiences!