question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to push relay to facebook and youtube with dynamic relay url

See original GitHub issue

First of all, thanks for your incredible job.

I have created a live server where each user has your own live url like this:

/live/9p5oPcRzI

and to work with facebook and youtube rtmp I had to modify node-media-server on node_relay_server.js to remove “stream” on “conf.ouPath”:

it it works pretty well to stream to youtube and facebook at same time

onPostPublish(id, streamPath, args) {
    if (!this.config.relay.tasks) {
    return;
    }
    console.log("AKI", streamPath);
    let regRes = /\/(.*)\/(.*)/gi.exec(streamPath);
    let [app, stream] = _.slice(regRes, 1);
    console.log(stream);
    let i = this.config.relay.tasks.length;
    while (i--) {
      let conf = this.config.relay.tasks[i];
      let isPush = conf.mode === 'push';
      if (isPush && app === conf.app) {
      let hasApp = conf.edge.match(/rtmp:\/\/([^\/]+)\/([^\/]+)/);
      conf.ffmpeg = this.config.relay.ffmpeg;
      conf.inPath = `rtmp://127.0.0.1:${this.config.rtmp.port}${streamPath}`;
      conf.ouPath = hasApp ? `${conf.edge}` : `${conf.edge}`;
      let session = new NodeRelaySession(conf);
      session.id = id;
      session.on('end', (id) => {
        this.dynamicSessions.delete(id);
      });
      this.dynamicSessions.set(id, session);
      session.run();
      Logger.log('[Relay dynamic push] start', id, conf.inPath, ' to ', conf.ouPath);
      }
    }

  }

and in my project config

		relay: {
			ffmpeg: '/usr/bin/ffmpeg',
			tasks: [
				{
					app: 'live',
					mode: 'push',
					edge: 'rtmp://a.rtmp.youtube.com/live2/keyyoutube',
				},
				{
					app: 'live',
					mode: 'push',
					edge: 'rtmps://rtmp-pc.facebook.com:443/rtmp/keyface',
				}
			]
		},

but it is too said because all users will relay to the same url.

but what I want is each user having your own rtmp list and for instance those live:

/live/9p5oPcRzI

relay to:

rtmp://a.rtmp.youtube.com/live2/firstuserkeyyoutube
rtmps://rtmp-pc.facebook.com:443/rtmp/firstuserkeyface

and to another live:

/live/1p3oPdRas

relay to:

rtmp://a.rtmp.youtube.com/live2/seconduserkeyyoutube
rtmps://rtmp-pc.facebook.com:443/rtmp/seconduserkeyface

Without need restart the server when user add new one

How can I pass those parameters from de user?

I’m almost sure that I can use it:

nms.on('postPublish', async (id, StreamPath, args) => {

to get from my database the user’s relay

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:30 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
NickGrant89commented, Oct 13, 2019

@kkrishnan90 - I have done some more testing and i would like to say a big thank you for your update on this. I tested this from my https server with valid certificates and for sure it worked, dynamically sending to FB live and Youtube. When doing the POST call, your arguments that you mentioned above are not correct.

When running this call i received a response of BAD REQUEST URL: http://<server-ip>:<server-port>/api/relay/push HTTP METHOD: POST JSON REQUEST BODY: { app : 'live', mode : 'push', vc : 'libx264', ac : 'aac', edge : 'rtmp://127.0.0.1:1987/rtmp/<fb-stream-key>', appendName : false }

I changed the values as you can see below and the response comes back “OK”. “mode” to “name” , name being the steam key. “edge” to “url”, url being the place you want to push the stream.

URL: http://<server-ip>:<server-port>/api/relay/push HTTP METHOD: POST JSON REQUEST BODY: { app : 'live', name : 'push', vc : 'libx264', ac : 'aac', url : 'rtmp://127.0.0.1:1987/rtmp/<fb-stream-key>', appendName : false }

I would love to know a bit more about how this works and how you achieved this 😃.

1reaction
hthetiotcommented, Jun 11, 2020

Thank you @kkrishnan90 I’m not the maintainer @illuspas should review https://github.com/illuspas/Node-Media-Server/pull/361

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building and Deploying Relay with Facebook - YouTube
This talk will explore the Relay framework in depth: why the team built it, the guiding principles behind the design, and an overview...
Read more >
How does Youtube/Facebook live stream from web ...
Using web socket: using web browser to encode the video (using mediarecorder api) and push the encoded video to the server to be...
Read more >
Create a YouTube live stream with an encoder
Learn how to set up a YouTube live stream using an encoder. ... To start streaming, enter your YouTube Live server URL and...
Read more >
Streaming Live to YouTube and Facebook using ...
Make sure you take a copy of the RTMP stream URL which you will use in your Raspberry Pi. Press the 'Preview' button...
Read more >
How To Set Up a Video Streaming Server using Nginx ...
YouTube uses URLs like rtmp://a.rtmp.youtube.com/live2 . Other streaming providers that can consume RTMP streams should behave similarly. Now ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found