NorskOutput.cmafMaster() method

Produces a master (hls and/or dash) manifest for a collection of media streams

This can optionally be served via the Norsk web server or be pushed to other locations - see CMAFDestinationSettings

Signature:

cmafMaster(settings: CmafMasterOutputSettings): Promise<CmafMasterOutputNode>;

Parameters

Parameter Type Description

settings

CmafMasterOutputSettings

Configuration for the CMAF Master Manifest

Returns:

Example [03_rtmp_to_hls.ts]

Package an inbound RTMP stream into LL-HLS

export async function main() {
  const norsk = await Norsk.connect();

  let input = await norsk.input.rtmpServer({ id: "rtmpInput", port: 5001 });
  let destinations: CMAFDestinationSettings[] = [{ type: "local", retentionPeriodSeconds: 10 }]

  let audioOutput = await norsk.output.cmafAudio({ id: "audio", destinations, ...segmentSettings });
  let videoOutput = await norsk.output.cmafVideo({ id: "video", destinations, ...segmentSettings });
  let masterOutput = await norsk.output.cmafMaster({ id: "master", playlistName: "master", destinations });

  audioOutput.subscribe([{ source: input, sourceSelector: selectAudio }]);
  videoOutput.subscribe([{ source: input, sourceSelector: selectVideo }]);
  masterOutput.subscribe([{ source: input, sourceSelector: selectAV }]);

  console.log(`Master playlist: ${masterOutput.playlistUrl}`);
  audioOutput.url().then(logMediaPlaylist("audio"));
  videoOutput.url().then(logMediaPlaylist("video"));
}

const segmentSettings = {
  partDurationSeconds: 1.0,
  segmentDurationSeconds: 4.0,
};

function logMediaPlaylist(name: string): (url: string) => void {
  return (
    url => { console.log(`${name} playlistUrl: ${url}`); }
  );
}

Run the following command to generate example input at url rtmp://127.0.0.1:5001/norsk/default:

ffmpeg -v error -re -f lavfi -i "sine=frequency=220:sample_rate=48000" -loop 1 -i data/test-src-still.png -vf drawtext=fontfile=Arial.ttf:text="%{frame_num}":start_number=1:x=980:y=330:fontcolor=black:fontsize=40:box=1:boxcolor=white:boxborderw=5,scale=1280:720 -vcodec h264 -b:v 150000 -b:a 20000 -aspect 1280:720 -x264opts "keyint=25:min-keyint=25:no-scenecut:bframes=0" -bluray-compat true -tune stillimage -preset fast -pix_fmt yuv420p -acodec aac -metadata language=en -f flv 'rtmp://127.0.0.1:5001/norsk/default'

Example [04_srt_to_hls.ts]

Package an SRT stream into LL-HLS

export async function main() {
  const norsk = await Norsk.connect();

  let input = await norsk.input.srt(srtInputSettings);
  let destinations: CMAFDestinationSettings[] = [{ type: "local", retentionPeriodSeconds: 10 }]

  let audioOutput = await norsk.output.cmafAudio({ id: "audio", destinations, ...segmentSettings });
  let videoOutput = await norsk.output.cmafVideo({ id: "video", destinations, ...segmentSettings });
  let masterOutput = await norsk.output.cmafMaster({ id: "master", playlistName: "master", destinations });

  let streamMetadataOverride = await norsk.processor.transform.streamMetadataOverride({
    id: "setBitrate",
    video: { bitrate: 150_000 },
    audio: { bitrate: 20_000 },
  });
  streamMetadataOverride.subscribe([
    { source: input, sourceSelector: selectAV },
  ]);

  audioOutput.subscribe([{ source: streamMetadataOverride, sourceSelector: selectAudio }]);
  videoOutput.subscribe([{ source: streamMetadataOverride, sourceSelector: selectVideo }]);
  masterOutput.subscribe([{ source: streamMetadataOverride, sourceSelector: selectAV }]);

  console.log(`Master playlist: ${masterOutput.playlistUrl}`);
  audioOutput.url().then(logMediaPlaylist("audio"));
  videoOutput.url().then(logMediaPlaylist("video"));
}

const segmentSettings = {
  partDurationSeconds: 1.0,
  segmentDurationSeconds: 4.0,
};

const srtInputSettings: SrtInputSettings = {
  id: "srtInput",
  ip: "127.0.0.1",
  port: 5001,
  mode: "listener",
  sourceName: "camera1",
};

function logMediaPlaylist(name: string): (url: string) => void {
  return (
    url => { console.log(`${name} playlistUrl: ${url}`); }
  );
}

Run the following command to generate example input at url srt://127.0.0.1:5001:

ffmpeg -v error -re -f lavfi -i "sine=frequency=220:sample_rate=48000" -loop 1 -i data/test-src-still.png -vf drawtext=fontfile=Arial.ttf:text="%{frame_num}":start_number=1:x=980:y=330:fontcolor=black:fontsize=40:box=1:boxcolor=white:boxborderw=5,scale=1280:720 -vcodec h264 -b:v 150000 -b:a 20000 -aspect 1280:720 -x264opts "keyint=25:min-keyint=25:no-scenecut:bframes=0" -bluray-compat true -tune stillimage -preset fast -pix_fmt yuv420p -acodec aac -metadata language=en -f mpegts -flush_packets 0 'srt://127.0.0.1:5001'

Find Examples