NorskTransform.streamMetadataOverride() method

Override bitrate and language metadata on streams.

Audio and video bitrate metadata is required for playlists for the NorskOutput.cmafMultiVariant() node. It is automatically configured for some sources (like RTMP) and in cases where re-encoding is done, but is unset for other sources (like SRT).

Signature:

streamMetadataOverride(settings: StreamMetadataOverrideSettings): Promise<StreamMetadataOverrideNode>;

Parameters

Parameter Type Description

settings

StreamMetadataOverrideSettings

Bitrate and language metadata plus general node settings.

Returns:

Example [10_bitrate_estimator.ts]

Measure bitrate and set this estimate in the stream metadata

// SRT inputs do not have bitrate information, which is required for HLS
// multi variant playlists.
//
// AAC audio does not need a transcode in this setting, and without a
// transcode (implicit or explicit), there is no bitrate information added.
const srtAacInput = await norsk.input.srt(srtSettings);

// So we sample the stream for 10 seconds to estimate its bitrate and add this
// bitrate to the stream's metadata before subscribing the multi variant playlist to
// the stream.
let streamStarted = false;
const streamStatistics = await norsk.processor.control.streamStatistics({
  id: "inputStreamStatistics",
  statsSampling: {
    // 1s for visualiser updates
    // 5s for console updates
    // 10s for stream bitrate estimation
    sampleIntervalsSeconds: [1, 5, 10],
  },
  onStreamStatistics: async stats => {
    const { audio, video } = stats;
    if (stats.sampleSizeSeconds === 10) {
      if (streamStarted) return;
      streamStarted = true;
      console.log(`+ audio: ${(audio.bitrate / 1000).toFixed(1)}kbps`)
      console.log(`+ video: ${(video.bitrate / 1000).toFixed(1)}kbps`);

      // Use NorskTransform.streamMetadataOverride to add bitrate information
      // to the video and audio streams
      streamMetadataOverride.updateConfig({
        video: {
          bitrate: video.bitrate,
        },
        audio: {
          bitrate: audio.bitrate,
        }
      });

      // And subscribe the multi variant playlist, now that the stream has bitrate
      // metadata
      // multiVariantOutput.subscribe([
      //   { source: streamMetadataOverride, sourceSelector: selectPlaylist },
      // ]);
    } else if (stats.sampleSizeSeconds === 5 && streamStarted) {
      console.log(`  audio: ${(audio.bitrate / 1000).toFixed(1)}kbps`)
      console.log(`  video: ${(video.bitrate / 1000).toFixed(1)}kbps`);
    }
  },
});
streamStatistics.subscribe([
  { source: srtAacInput, sourceSelector: selectAV },
]);

const streamMetadataOverride = await norsk.processor.transform.streamMetadataOverride({
  id: "setBitrate",
});
streamMetadataOverride.subscribe([
  { source: srtAacInput, sourceSelector: selectAV },
]);

Run the following command to generate example input at url srt://127.0.0.1:5001?pkt_size=1316:

ffmpeg -v error -re -stream_loop -1 -i data/InkDrop.ts  -vcodec copy -codec copy -f mpegts -flush_packets 0 'srt://127.0.0.1:5001?pkt_size=1316'

Find Examples