node-webrtc / node-webrtc-examples

MediaStream and RTCDataChannel examples using node-webrtc
508 stars 161 forks source link

record-audio-video-stream example with RTMP #24

Open Serafo44 opened 4 years ago

Serafo44 commented 4 years ago

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

Malsoine commented 4 years ago

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 ?

card-b commented 4 years ago

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
Serafo44 commented 4 years ago

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) ?

ldenoue commented 3 years ago

@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://...

ysle commented 2 years ago

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