Add publisher with Nodejs

I’m trying to implement something like a bot that would publish a Youtube video’s audio only for everyone in the session. Like a few discord bots (e.g.
I’m getting a stream from a Youtube link but I can’t create a new publisher on backend side. Would you know if there is any workaround I could use ?

Thank you !


Perhaps you can forward the audio stream to a RTSP server (IPCAM) and publish it to OpenVidu:

Not sure if it works only with an audio channel… but I guess it would be easy to create a blank video channel if needed.

Good luck,

Hello !

Thank you for your answer, that is indeed a solution that I tried with no success so far.
I’ll keep digging this way.

Thank you

I can give it a try later today if you’re using an open-source library (perhaps this one?) to grab the YouTube stream.

That’s exactly this one !
It would be really helpful thanks a lot.


I’ve modified the youtube-audio-stream module index.js file and got this code working*:

const ffmpeg = FFmpeg(); // removed the video parameter
process.nextTick(() => {
            const output = ffmpeg.input(video).inputOptions('-re')
                .outputOptions(['-f rtsp', '-rtsp_transport tcp'])
            ffmpeg.on('stderr', (line) => {
                .on('start', cmd => {
                }).on('end', function() {
                    console.log('Finished processing');

* comments:

  1. I’m using this RTSP server.

  2. When I say working I just mean that the streams are sent from ffmpeg and received in the RTSP server

ffmpeg output:

Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))

RTSP server output:

2021/06/14 20:51:53 I [1/0] [RTSP] [session 2561495439] is publishing to path 'mystream', 2 tracks with TCP

Hope this helps as a starting point, next you should filter just the audio track (perhaps it also needs some transcoding from aac), then you need to implement the OpenVidu logic to add it as a publisher.



Thank you very much, this is awesome ! I’ll have a look and I’ll keep you posted

Cheers !


I managed to make the RTSP server work and to read the stream from VLC but I’m getting an error when trying to publish the rtsp url on openVidu.

Here is the error I’m getting :

0:01:27.388749316    10 0x7fd72000a320 ERROR                default gstrtspconnection.c:960:gst_rtsp_connection_connect_with_response: failed to connect: Could not connect to localhost: Connection refused
0:01:27.388777106    10 0x7fd72000a320 ERROR                rtspsrc gstrtspsrc.c:4137:gst_rtsp_conninfo_connect:<source> Could not connect to server. (Generic error)
0:01:27.388902374    10 0x7fd7380086d0 INFO       KurentoWorkerPool WorkerPool.cpp:67:WorkerPool: Worker thread pool size: 6
0:01:27.390331594    10 0x7fd6f80052f0 DEBUG   KurentoWebSocketEventHandler WebSocketEventHandler.cpp:56:sendEvent: Sending event: {"jsonrpc":"2.0","method":"onEvent","params":{"value":{"data":{"description":"Invalid URI","errorCode":0,"source":"e1a128d8-6d90-403b-9b4d-49c1e7ae6fe5_kurento.MediaPipeline/4291a64a-818c-4eff-928b-1dd821f466e3_kurento.PlayerEndpoint","tags":[],"timestamp":"1623834476","timestampMillis":"1623834476518","type":"INVALID_URI"},"object":"e1a128d8-6d90-403b-9b4d-49c1e7ae6fe5_kurento.MediaPipeline/4291a64a-818c-4eff-928b-1dd821f466e3_kurento.PlayerEndpoint","type":"Error"}}}, sessionId: 76d4fc29-5663-4e28-9335-a5045fc3adf2

2021-06-16 09:07:56,521 DEBG 'kms' stdout output:
0:01:27.390787764    10 0x556af0c5f360 ERROR         playerendpoint kmsplayerendpoint.c:1338:process_bus_message:<kmsplayerendpoint0> Error code 7: 'Could not open resource for reading and writing.', element: source, parent: internalpipeline
0:01:27.390807125    10 0x556af0c5f360 ERROR         playerendpoint kmsplayerendpoint.c:1341:process_bus_message:<kmsplayerendpoint0> Debugging info: gstrtspsrc.c(6795): gst_rtspsrc_retrieve_sdp (): /GstPipeline:internalpipeline/GstURIDecodeBin:uridecodebin0/GstRTSPSrc:source:
Failed to connect. (Generic error)

I tested with another rtsp url that I found online a that worked perfectly. I also tried to deploy the server on a dedicated server and I’m getting the same error.

Cheers !

I’ve never tried with a local server. Seems that it upsets the Kurento pipeline creation.

You can try testing with the OpenVidu demo server and see if it works there to get a clue if it’s a configuration error on your side.