NorskOutput.fileMp4() method

Output MP4 files to disk, both fragmented and non-fragmented.

The fragmented output is required.

The optional non-fragmented filename will be written when calling and will be fully written by the time NodeSettings.onClose is called. This sets up a temp file to store the frame data by appending the extension .tmp.

A non-fragmented MP4 file can be written on request with FileMp4OutputNode.writeFile(), which uses the frame data store if FileMp4OutputSettings.nonfragmentedFileName was given or reads back the fragmented mp4 if there is no non-fragmented file.

Signature:

fileMp4(settings: FileMp4OutputSettings): Promise<FileMp4OutputNode>;

Parameters

Parameter Type Description

settings

FileMp4OutputSettings

Configuration for the MP4 output.

Returns:

Example [05_rtmp_to_localmp4.ts]

Receive an RTMP stream and save it to disk as both mp4 and fmp4

const input = await norsk.input.rtmpServer({ id: "rtmpInput" });
const output = await norsk.output.fileMp4({
  id: "localMp4Output",
  fragmentedFileName: "/mnt/output/norskOutput.fmp4",
  nonfragmentedFileName: "/mnt/output/norskOutput.mp4",
  onClose: async () => {
    console.log("Closing Norsk");
    await norsk.close();
  },
});

output.subscribe([{ source: input, sourceSelector: selectAV }], requireAV);
console.log(`Recording to mp4 for ${durationMs / 1000} seconds`);

// We can write non-fragmented snapshots periodically
let i = 0;
setInterval(() => {
  const fileRoot = "/mnt/output/norskOutput";
  output.writeFile(`${fileRoot}${i += 1}.mp4`)
}, 5000
);

// And close it to write out the non-fragmented file name set in config
// (will close norsk via onClose callback above)
setTimeout(() => { console.log("Timer expired, closing output"); void output.close(); }, durationMs);

Run the following command to generate example input at url rtmp://127.0.0.1:1935/norsk/high:

ffmpeg -v error -re -stream_loop -1 -i data/InkDrop.ts  -vcodec copy -codec copy -f flv 'rtmp://127.0.0.1:1935/norsk/high'

Find Examples