How can I pause FFmpeg RTP stream recording?

2 weeks ago 19
ARTICLE AD BOX

For One-to-Many streaming using mediasoup in Node.js, recording one stream using FFmpeg works but I need to pause the recording after the user closes the browser, until they reconnect. I want to have one continuos recording of the multiple streams. When the user disconnects, FFmpeg stops because of a timeout. I have tried increasing timeouts but nothing helps.

Code for recording which I need to change:

export class FFmpeg { private _recordInfo: RecordInfo; private _process: ChildProcessWithoutNullStreams | undefined; private _observer: EventEmitter; constructor(recordInfo: RecordInfo) { this._recordInfo = recordInfo; this._process = undefined; this._observer = new EventEmitter(); this._createProcess(); } private _createProcess() { const sdpString = createSdpText(this._recordInfo); const sdpStream = convertStringToStream(sdpString); this._process = child_process.spawn("ffmpeg", this._commandArgs); sdpStream.pipe(this._process.stdin); } public kill () { if (!this._process) return; this._process.kill('SIGINT'); } private get _commandArgs() { let filePath = `${RECORDINGS_FOLDER}/${this._recordInfo.folderName}/playlist`; let commandArgs = [ "-loglevel", "warning", "-protocol_whitelist", "pipe,udp,rtp", "-fflags", "+genpts+discardcorrupt+igndts+nobuffer", "-flags", "low_delay", "-analyzeduration", "0", "-probesize", "32", "-rw_timeout", "0", "-timeout", "0", "-max_delay", "0", "-f", "sdp", "-i", "pipe:0", "-r", "30", "-map", "0:v:0", "-c:v", "libx264", "-preset", "ultrafast", "-tune", "zerolatency", "-b:v", "1500k", "-level:v", "4.1", "-pix_fmt", "yuv420p", "-g", "30", ]; commandArgs = commandArgs.concat([ "-movflags", "+frag_keyframe+empty_moov", "-f", "hls", "-hls_time", "4", "-hls_list_size", "0", "-hls_flags", "independent_segments", `${filePath}.m3u8` ]); return commandArgs; } };

This code is used from another JavaScript file which creates mediasoup's PlainTransport and Consumer to send RTP packets to 127.0.0.1:<port> where FFmpeg is running.

Read Entire Article