illuspas / Node-Media-Server

A Node.js implementation of RTMP/HTTP-FLV/WS-FLV/HLS/DASH/MP4 Media Server
https://www.npmjs.com/package/node-media-server
MIT License
5.9k stars 1.51k forks source link

Restrem to multi rtmp servers #230

Open slawomir0211 opened 4 years ago

slawomir0211 commented 4 years ago

I would like to stream to multi servers e.g. YouTube and Facebook

I would like to push rtmp://localhost/live/mystream to rtmp://a.rtmp.youtube.com/live2/YOUTUBE_STREAMKEY and rtmp://live-api-s.facebook.com:80/rtmp/FACEBOOK_STREAMKEY YOUTUBE_STREAMKEY and FACEBOOK_STREAMKEY isn't the same key.

How should config look like?

Config like this don't work:

relay: {
  ffmpeg: '/usr/bin/ffmpeg',
  tasks: [
    {
      app: 'live',
      mode: 'push',
      edge: 'rtmp://a.rtmp.youtube.com/live2/YOUTUBE_STREAMKEY/,
    },
    {
      app: 'live',
      mode: 'push',
      edge: 'rtmp://live-api-s.facebook.com:80/rtmp/FACEBOOK_STREAMKEY',
    }
  ]
 }

App try to push to rtmp://a.rtmp.youtube.com/live2/YOUTUBE_STREAMKEY/mystream and rtmp://live-api-s.facebook.com:80/rtmp/FACEBOOK_STREAMKEY/mystream

cpanel10x commented 4 years ago

Can you post log? I use that config and it's ok, restream to both facebook and youtube. But i need a fix for / problem append at end stream https://github.com/illuspas/Node-Media-Server/issues/196#issuecomment-514450040

slawomir0211 commented 4 years ago

Logs:

7/27/2019 14:42:15 17412 [INFO] Node Media Server v2.1.2
7/27/2019 14:42:15 17412 [INFO] Node Media Rtmp Server started on port: 1935
7/27/2019 14:42:15 17412 [INFO] Node Media Http Server started on port: 8000
7/27/2019 14:42:15 17412 [INFO] Node Media WebSocket Server started on port: 8000
7/27/2019 14:42:16 17412 [INFO] Node Media Relay Server started
7/27/2019 14:42:58 17412 [INFO] [rtmp connect] id=HUVSI3Z4 ip=::ffff:192.168.144.144 app=live args={"app":"live","type":"nonprivate","flashVer":"FMLE/3.0 (compatible; FMSc/1.0)","swfUrl":"rtmp://192.168.144.168/live","tcUrl":"rtmp://192.168.144.168/live"}
7/27/2019 14:42:58 17412 [INFO] [rtmp publish] New stream. id=HUVSI3Z4 streamPath=/live/mystream streamId=1
7/27/2019 14:42:58 17412 [INFO] [Relay dynamic push] start HUVSI3Z4 rtmp://127.0.0.1:1935/live/mystream  to  rtmp://live-api-s.facebook.com:80/rtmp/FACEBOOK_STREAMKEY/mystream
7/27/2019 14:42:58 17412 [INFO] [Relay dynamic push] start HUVSI3Z4 rtmp://127.0.0.1:1935/live/mystream  to  rtmp://a.rtmp.youtube.com/live2/YOUTUBE_STREAMKEY/mystream
7/27/2019 14:42:59 17412 [INFO] [rtmp connect] id=E04VKSNO ip=::ffff:127.0.0.1 app=live args={"app":"live","flashVer":"LNX 9,0,124,2","tcUrl":"rtmp://127.0.0.1:1935/live","fpad":false,"capabilities":15,"audioCodecs":4071,"videoCodecs":252,"videoFunction":1}
7/27/2019 14:42:59 17412 [INFO] [rtmp connect] id=KZLGN8TF ip=::ffff:127.0.0.1 app=live args={"app":"live","flashVer":"LNX 9,0,124,2","tcUrl":"rtmp://127.0.0.1:1935/live","fpad":false,"capabilities":15,"audioCodecs":4071,"videoCodecs":252,"videoFunction":1}
7/27/2019 14:42:59 17412 [INFO] [rtmp play] Join stream. id=E04VKSNO streamPath=/live/mystream  streamId=1 
7/27/2019 14:42:59 17412 [INFO] [rtmp play] Join stream. id=KZLGN8TF streamPath=/live/mystream  streamId=1 
7/27/2019 14:42:59 17412 [INFO] [rtmp publish] Handle audio. id=HUVSI3Z4 streamPath=/live/mystream sound_format=10 sound_type=2 sound_size=1 sound_rate=3 codec_name=AAC 44100 2ch
7/27/2019 14:42:59 17412 [INFO] [rtmp publish] Handle video. id=HUVSI3Z4 streamPath=/live/mystream frame_type=1 codec_id=7 codec_name=H264 1280x720
7/27/2019 14:43:00 17412 [INFO] [rtmp play] Close stream. id=KZLGN8TF streamPath=/live/mystream streamId=1
7/27/2019 14:43:00 17412 [INFO] [rtmp disconnect] id=KZLGN8TF
7/27/2019 14:43:00 17412 [INFO] [Relay end] id= HUVSI3Z4
7/27/2019 14:43:00 17412 [INFO] [rtmp play] Close stream. id=E04VKSNO streamPath=/live/mystream streamId=1
7/27/2019 14:43:00 17412 [INFO] [rtmp disconnect] id=E04VKSNO
7/27/2019 14:43:01 17412 [INFO] [Relay end] id= HUVSI3Z4
7/27/2019 14:43:26 17412 [INFO] [rtmp publish] Close stream. id=HUVSI3Z4 streamPath=/live/mystream streamId=1
7/27/2019 14:43:26 17412 [INFO] [rtmp disconnect] id=HUVSI3Z4

app.js

const NodeMediaServer = require('node-media-server');

const config = {
  rtmp: {
    port: 1935,
    chunk_size: 60000,
    gop_cache: true,
    ping: 30,
    ping_timeout: 60
  },
  http: {
    port: 8000,
    allow_origin: '*'
  },
 relay: {
  ffmpeg: '/usr/bin/ffmpeg',
  tasks: [
    {
      app: 'live',
      mode: 'push',
      edge: 'rtmp://a.rtmp.youtube.com/live2/YOUTUBE_STREAMKEY',
    },
    {
      app: 'live',
      mode: 'push',
      edge: 'rtmp://live-api-s.facebook.com:80/rtmp/FACEBOOK_STREAMKEY',
    }
  ]
 }
};

var nms = new NodeMediaServer(config)
nms.run()

I changed YOUTUBE_STREAMKEY and FACEBOOK_STREAMKEY to orginal keys, but above logs and confs were modified to prevent show orginal keys.

cpanel10x commented 4 years ago

Logs:

7/27/2019 14:42:15 17412 [INFO] Node Media Server v2.1.2
7/27/2019 14:42:15 17412 [INFO] Node Media Rtmp Server started on port: 1935
7/27/2019 14:42:15 17412 [INFO] Node Media Http Server started on port: 8000
7/27/2019 14:42:15 17412 [INFO] Node Media WebSocket Server started on port: 8000
7/27/2019 14:42:16 17412 [INFO] Node Media Relay Server started
7/27/2019 14:42:58 17412 [INFO] [rtmp connect] id=HUVSI3Z4 ip=::ffff:192.168.144.144 app=live args={"app":"live","type":"nonprivate","flashVer":"FMLE/3.0 (compatible; FMSc/1.0)","swfUrl":"rtmp://192.168.144.168/live","tcUrl":"rtmp://192.168.144.168/live"}
7/27/2019 14:42:58 17412 [INFO] [rtmp publish] New stream. id=HUVSI3Z4 streamPath=/live/mystream streamId=1
7/27/2019 14:42:58 17412 [INFO] [Relay dynamic push] start HUVSI3Z4 rtmp://127.0.0.1:1935/live/mystream  to  rtmp://live-api-s.facebook.com:80/rtmp/FACEBOOK_STREAMKEY/mystream
7/27/2019 14:42:58 17412 [INFO] [Relay dynamic push] start HUVSI3Z4 rtmp://127.0.0.1:1935/live/mystream  to  rtmp://a.rtmp.youtube.com/live2/YOUTUBE_STREAMKEY/mystream
7/27/2019 14:42:59 17412 [INFO] [rtmp connect] id=E04VKSNO ip=::ffff:127.0.0.1 app=live args={"app":"live","flashVer":"LNX 9,0,124,2","tcUrl":"rtmp://127.0.0.1:1935/live","fpad":false,"capabilities":15,"audioCodecs":4071,"videoCodecs":252,"videoFunction":1}
7/27/2019 14:42:59 17412 [INFO] [rtmp connect] id=KZLGN8TF ip=::ffff:127.0.0.1 app=live args={"app":"live","flashVer":"LNX 9,0,124,2","tcUrl":"rtmp://127.0.0.1:1935/live","fpad":false,"capabilities":15,"audioCodecs":4071,"videoCodecs":252,"videoFunction":1}
7/27/2019 14:42:59 17412 [INFO] [rtmp play] Join stream. id=E04VKSNO streamPath=/live/mystream  streamId=1 
7/27/2019 14:42:59 17412 [INFO] [rtmp play] Join stream. id=KZLGN8TF streamPath=/live/mystream  streamId=1 
7/27/2019 14:42:59 17412 [INFO] [rtmp publish] Handle audio. id=HUVSI3Z4 streamPath=/live/mystream sound_format=10 sound_type=2 sound_size=1 sound_rate=3 codec_name=AAC 44100 2ch
7/27/2019 14:42:59 17412 [INFO] [rtmp publish] Handle video. id=HUVSI3Z4 streamPath=/live/mystream frame_type=1 codec_id=7 codec_name=H264 1280x720
7/27/2019 14:43:00 17412 [INFO] [rtmp play] Close stream. id=KZLGN8TF streamPath=/live/mystream streamId=1
7/27/2019 14:43:00 17412 [INFO] [rtmp disconnect] id=KZLGN8TF
7/27/2019 14:43:00 17412 [INFO] [Relay end] id= HUVSI3Z4
7/27/2019 14:43:00 17412 [INFO] [rtmp play] Close stream. id=E04VKSNO streamPath=/live/mystream streamId=1
7/27/2019 14:43:00 17412 [INFO] [rtmp disconnect] id=E04VKSNO
7/27/2019 14:43:01 17412 [INFO] [Relay end] id= HUVSI3Z4
7/27/2019 14:43:26 17412 [INFO] [rtmp publish] Close stream. id=HUVSI3Z4 streamPath=/live/mystream streamId=1
7/27/2019 14:43:26 17412 [INFO] [rtmp disconnect] id=HUVSI3Z4

app.js

const NodeMediaServer = require('node-media-server');

const config = {
  rtmp: {
    port: 1935,
    chunk_size: 60000,
    gop_cache: true,
    ping: 30,
    ping_timeout: 60
  },
  http: {
    port: 8000,
    allow_origin: '*'
  },
 relay: {
  ffmpeg: '/usr/bin/ffmpeg',
  tasks: [
    {
      app: 'live',
      mode: 'push',
      edge: 'rtmp://a.rtmp.youtube.com/live2/YOUTUBE_STREAMKEY',
    },
    {
      app: 'live',
      mode: 'push',
      edge: 'rtmp://live-api-s.facebook.com:80/rtmp/FACEBOOK_STREAMKEY',
    }
  ]
 }
};

var nms = new NodeMediaServer(config)
nms.run()

I changed YOUTUBE_STREAMKEY and FACEBOOK_STREAMKEY to orginal keys, but above logs and confs were modified to prevent show orginal keys.

I think your log will be rtmp://a.rtmp.youtube.com/live2/YOUTUBE_STREAMKEY/mystream/ with / at the end. use this https://github.com/illuspas/Node-Media-Server/pull/210 to fix prolem about that

chrisspiegl commented 4 years ago

This issue is most likely fixed by #210 by adding the appendName: false option to the relay config.

relay: {
    ffmpeg: "path/to/ffmpeg",
    tasks: [{
        app: "live",
        mode: "push",
        edge: "FULL RTMP URL THAT DON'T HAS TO BE MODIFIED",
        appendName: false
    }]
}

This issue probably can be closed when adding the appendName: false.