node-webrtc-examples icon indicating copy to clipboard operation
node-webrtc-examples copied to clipboard

record-audio-video-stream example with RTMP

Open Serafo44 opened this issue 5 years ago • 5 comments
trafficstars

Hello !

I would like to modify the example record-audio-video-stream so that it sends the data to an RTMP page instead of recording the video in mp4. Is this possible with this example? I tried to modify the record path by putting my RTMP link in it and adding some output options but it doesn't work. Do you know how I could do it?

Thanks :D

Serafo44 avatar Jun 08 '20 07:06 Serafo44

Hey o/

I would like to send my webcam flux to an RTMP link just like Serafo44 When I click on start, it return me an ECONNRESET error, as I know, it's a socket error, but I really don't understand why it return me this error Any help ?

Malsoine avatar Jun 15 '20 09:06 Malsoine

it does work - you have to make certain you set the output type to flv, and pick the aac audio codec as an output.

stream.proc = ffmpeg()
	.addInput((new StreamInput(stream.video)).url)
	.addInputOptions([
		'-f', 'rawvideo',
		'-pix_fmt', 'yuv420p',
		'-s', stream.size,
		'-r', '30',
	])
	.addInput((new StreamInput(stream.audio)).url)
	.addInputOptions([
		'-f s16le',
		'-ar 48k',
		'-ac 1',
	])
	.on('start', () => {
		console.log('Start recording >> ', stream.recordPath)
	})
	.on('end', () => {
		stream.recordEnd = true;
		console.log('Stop recording >> ', stream.recordPath)
	})
	.size(VIDEO_OUTPUT_SIZE)
	.audioCodec('aac')
	.flvmeta()
	.format('flv')
	.output(stream.recordPath); // RTMP endpoint

card-b avatar Jul 29 '20 21:07 card-b

Yes, i find a way to do it ahah, but do you think it's possible to create a librarie that allow us to send the webcam flux of an external project to our server (Instead of capture it with client.js) ?

Serafo44 avatar Aug 03 '20 12:08 Serafo44

@card-b Does this work even when the incoming WEBRTC video size changes during the session? It's not uncommon that during a session, the video changes from e.g. 640x480 to 160x120. Would FFMPEG in this case automatically scale it back to your VIDEO_OUTPUT_SIZE param?

I logged the sizes when a new UID gets created, and notice the Start/Stop recording events. Unfortunately, the RTMP stream is constantly interrupted.

Would you have ideas on how to solve this?

new UID 1 new size= 320x240 Start recording >> rtmp://... new UID 2 new size= 480x360 Start recording >> rtmp://... Stop recording >> rtmp://... new UID 3 new size= 640x480 Start recording >> rtmp://... Stop recording >> rtmp://...

ldenoue avatar Sep 15 '20 17:09 ldenoue

well, You can force ffmpeg to maintain the output resolution, surely it isn't optimal but at least the RTMP could survive it.

ysle avatar Feb 10 '22 19:02 ysle