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 FileMp4OutputNode.close() 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

let input = await norsk.input.rtmpServer({ id: "rtmpInput", port: 5001 });
let output = await norsk.output.fileMp4({
  id: "localMp4Output",
  fragmentedFileName: "/tmp/norskOutput.fmp4",
  nonfragmentedFileName: "/tmp/norskOutput.mp4",
  onEnd: () => {
    console.log("Closing Norsk");
    norsk.close();
  },
});

output.subscribe([{ source: input, sourceSelector: selectAV }]);

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

// And close it to write out the non-fragmented file name set in config
// (will close norsk via onEnd callback above)
setTimeout(() => output.close(), 120000);

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

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/high'

Find Examples