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

Is it possible to restream to Youtube? #196

Open durygus opened 5 years ago

parthibd commented 5 years ago

Please check the readme .

durygus commented 5 years ago

Thanks, I can't do it, although I tried many configuration options in relay mode. And how would you do it?

durygus commented 5 years ago

Where do I have to specify the "stream name / key" that Google broadcasts authenticates?

durygus commented 5 years ago

Here is how I did it: 1) My Node-Media-Server config: const config = { logType: 3,

rtmp: { port: 1935, chunk_size: 60000, gop_cache: true, ping: 30, ping_timeout: 60 }, http: { port: 8000, mediaroot: './media', allow_origin: '*' },

relay: { ffmpeg: '/usr/local/bin/ffmpeg', tasks: [ { app: 'live', mode: 'push', edge: 'rtmp://a.rtmp.youtube.com/live2', name: '{secret stream name/key from Youtube Stream Now}', } ] } };

2) Lanched a video stream: ffmpeg -re -i ~/Downloads/temp/Ma\ Long\ Forehand\ and\ Backhand\ Technique.mp4 -c copy -f flv rtmp://192.168.31.230/live/

3) Console output: 5/1/2019 11:06:48 31572 [INFO] Node Media Server v2.1.0 5/1/2019 11:06:49 31572 [INFO] Node Media Rtmp Server started on port: 1935 5/1/2019 11:06:49 31572 [INFO] Node Media Http Server started on port: 8000 5/1/2019 11:06:49 31572 [INFO] Node Media WebSocket Server started on port: 8000 5/1/2019 11:06:49 31572 [INFO] Node Media Relay Server started 5/1/2019 11:13:20 31572 [INFO] [rtmp connect] id=BHTK17JL ip=::ffff:192.168.31.216 app=live args={"app":"live","type":"nonprivate","tcUrl":"rtmp://192.168.31.230/live"} 5/1/2019 11:13:20 31572 [INFO] [rtmp publish] New stream. id=BHTK17JL streamPath=/live/ streamId=1 5/1/2019 11:13:20 31572 [FFDEBUG] -fflags,nobuffer,-i,rtmp://127.0.0.1:1935/live/,-c,copy,-f,flv,rtmp://a.rtmp.youtube.com/live2/ 5/1/2019 11:13:20 31572 [INFO] [Relay dynamic push] start BHTK17JL rtmp://127.0.0.1:1935/live/ to rtmp://a.rtmp.youtube.com/live2/ 5/1/2019 11:13:20 31572 [INFO] [rtmp publish] Handle video. id=BHTK17JL streamPath=/live/ frame_type=1 codec_id=7 codec_name=H264 1280x720 5/1/2019 11:13:20 31572 [INFO] [rtmp publish] Handle audio. id=BHTK17JL streamPath=/live/ sound_format=10 sound_type=2 sound_size=1 sound_rate=3 codec_name=AAC 44100 2ch 5/1/2019 11:13:20 31572 [FFDEBUG] FF输出:ffmpeg version N-91148-g8557a0940e Copyright (c) 2000-2018 the FFmpeg developers built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516 configuration: 5/1/2019 11:13:20 31572 [FFDEBUG] FF输出: libavutil 56. 18.102 / 56. 18.102 libavcodec 58. 19.102 / 58. 19.102 libavformat 58. 16.100 / 58. 16.100 libavdevice 58. 4.100 / 58. 4.100 libavfilter 7. 24.100 / 7. 24.100 libswscale 5. 2.100 / 5. 2.100 libswresample 3. 2.100 / 3. 2.100 5/1/2019 11:13:20 31572 [INFO] [rtmp connect] id=GS4LBHCY 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} 5/1/2019 11:13:21 31572 [INFO] [rtmp play] Join stream. id=GS4LBHCY streamPath=/live/ streamId=1 5/1/2019 11:13:23 31572 [FFDEBUG] FF输出:Input #0, flv, from 'rtmp://127.0.0.1:1935/live/': Metadata: major_brand : mp42 5/1/2019 11:13:23 31572 [FFDEBUG] FF输出: minor_version : 0 compatible_brands: isommp42 encoder : Lavf58.20.100 Duration: 00:00:00.00, start: 0.040000, bitrate: N/A Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 125 kb/s Stream #0:1: Video: h264 (Main), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 815 kb/s, 25 fps, 25 tbr, 1k tbn, 50 tbc 5/1/2019 11:13:23 31572 [FFDEBUG] FF输出:rtmp://a.rtmp.youtube.com/live2/: Input/output error 5/1/2019 11:13:23 31572 [INFO] [rtmp play] Close stream. id=GS4LBHCY streamPath=/live/ streamId=1 5/1/2019 11:13:23 31572 [INFO] [rtmp disconnect] id=GS4LBHCY 5/1/2019 11:13:23 31572 [INFO] [Relay end] id= BHTK17JL

parthibd commented 5 years ago

Can you please format the console output ?

parthibd commented 5 years ago

Can you try the config like this


relay: {
  ffmpeg: '/usr/local/bin/ffmpeg',
  tasks: [
    {
      app: 'live',
      mode: 'push',
      edge: 'rtmp://a.rtmp.youtube.com/live2/<stream_key>',
    }
  ]
}

without the <>

parthibd commented 5 years ago

Because in rtmp://a.rtmp.youtube.com/live2/: Input/output error the stream key is missing . So please try out my solution and let me know if it works .

parthibd commented 5 years ago

Maybe we should add one more key in the relay config to substitute for the stream key ? Can you make a pull request with this feature ?

durygus commented 5 years ago

Thanks for the help, but for some reason, the NMS inserts the symbol "/" at the end of the URL, and perhaps because of this, Youtube does not accept the content:

5/2/2019 08:13:00 5238 [INFO] Node Media Server v2.1.0 5/2/2019 08:13:00 5238 [INFO] Node Media Rtmp Server started on port: 1935 5/2/2019 08:13:00 5238 [INFO] Node Media Http Server started on port: 8000 5/2/2019 08:13:00 5238 [INFO] Node Media WebSocket Server started on port: 8000 5/2/2019 08:13:00 5238 [INFO] Node Media Relay Server started 5/2/2019 08:13:21 5238 [INFO] [rtmp connect] id=1S8T3UZU ip=::ffff:192.168.31.216 app=youtube args={"app":"youtube","type":"nonprivate","tcUrl":"rtmp://192.168.31.230/youtube"} 5/2/2019 08:13:21 5238 [INFO] [rtmp publish] New stream. id=1S8T3UZU streamPath=/youtube/ streamId=1 5/2/2019 08:13:21 5238 [FFDEBUG] -fflags,nobuffer,-i,rtmp://127.0.0.1:1935/youtube/,-c,copy,-f,flv,rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46/ 5/2/2019 08:13:21 5238 [INFO] [Relay dynamic push] start 1S8T3UZU rtmp://127.0.0.1:1935/youtube/ to rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46/ 5/2/2019 08:13:21 5238 [INFO] [rtmp publish] Handle video. id=1S8T3UZU streamPath=/youtube/ frame_type=1 codec_id=7 codec_name=H264 1280x720 5/2/2019 08:13:21 5238 [INFO] [rtmp publish] Handle audio. id=1S8T3UZU streamPath=/youtube/ sound_format=10 sound_type=2 sound_size=1 sound_rate=3 codec_name=AAC 44100 2ch 5/2/2019 08:13:21 5238 [FFDEBUG] FF输出:ffmpeg version N-91148-g8557a0940e Copyright (c) 2000-2018 the FFmpeg developers built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516 configuration:

5/2/2019 08:13:21 5238 [FFDEBUG] FF输出: libavutil 56. 18.102 / 56. 18.102 libavcodec 58. 19.102 / 58. 19.102 libavformat 58. 16.100 / 58. 16.100 libavdevice 58. 4.100 / 58. 4.100 libavfilter 7. 24.100 / 7. 24.100 libswscale 5. 2.100 / 5. 2.100 libswresample 3. 2.100 / 3. 2.100

5/2/2019 08:13:21 5238 [INFO] [rtmp connect] id=65ADIACS ip=::ffff:127.0.0.1 app=youtube args={"app":"youtube","flashVer":"LNX 9,0,124,2","tcUrl":"rtmp://127.0.0.1:1935/youtube","fpad":false,"capabilities":15,"audioCodecs":4071,"videoCodecs":252,"videoFunction":1} 5/2/2019 08:13:21 5238 [INFO] [rtmp play] Join stream. id=65ADIACS streamPath=/youtube/ streamId=1 5/2/2019 08:13:23 5238 [FFDEBUG] FF输出:Input #0, flv, from 'rtmp://127.0.0.1:1935/youtube/': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 encoder : Lavf58.20.100 Duration: 00:00:00.00, start: 0.033000, bitrate: N/A Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 128 kb/s Stream #0:1: Video: h264 (Main), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 1813 kb/s, 30 fps, 30 tbr, 1k tbn, 60 tbc

5/2/2019 08:13:24 5238 [FFDEBUG] FF输出:rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46/: Input/output error

5/2/2019 08:13:24 5238 [INFO] [rtmp play] Close stream. id=65ADIACS streamPath=/youtube/ streamId=1 5/2/2019 08:13:24 5238 [INFO] [rtmp disconnect] id=65ADIACS 5/2/2019 08:13:24 5238 [INFO] [Relay end] id= 1S8T3UZU

Tell me, please, how I can format the console output more readable?

parthibd commented 5 years ago

ffmpeg has one option -loglevel . It must be set to make ffmpeg spit out more readable info .

parthibd commented 5 years ago

Thanks for the help, but for some reason, the NMS inserts the symbol "/" at the end of the URL, and perhaps because of this, Youtube does not accept the content:

5/2/2019 08:13:00 5238 [INFO] Node Media Server v2.1.0 5/2/2019 08:13:00 5238 [INFO] Node Media Rtmp Server started on port: 1935 5/2/2019 08:13:00 5238 [INFO] Node Media Http Server started on port: 8000 5/2/2019 08:13:00 5238 [INFO] Node Media WebSocket Server started on port: 8000 5/2/2019 08:13:00 5238 [INFO] Node Media Relay Server started 5/2/2019 08:13:21 5238 [INFO] [rtmp connect] id=1S8T3UZU ip=::ffff:192.168.31.216 app=youtube args={"app":"youtube","type":"nonprivate","tcUrl":"rtmp://192.168.31.230/youtube"} 5/2/2019 08:13:21 5238 [INFO] [rtmp publish] New stream. id=1S8T3UZU streamPath=/youtube/ streamId=1 5/2/2019 08:13:21 5238 [FFDEBUG] -fflags,nobuffer,-i,rtmp://127.0.0.1:1935/youtube/,-c,copy,-f,flv,rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46/ 5/2/2019 08:13:21 5238 [INFO] [Relay dynamic push] start 1S8T3UZU rtmp://127.0.0.1:1935/youtube/ to rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46/ 5/2/2019 08:13:21 5238 [INFO] [rtmp publish] Handle video. id=1S8T3UZU streamPath=/youtube/ frame_type=1 codec_id=7 codec_name=H264 1280x720 5/2/2019 08:13:21 5238 [INFO] [rtmp publish] Handle audio. id=1S8T3UZU streamPath=/youtube/ sound_format=10 sound_type=2 sound_size=1 sound_rate=3 codec_name=AAC 44100 2ch 5/2/2019 08:13:21 5238 [FFDEBUG] FF输出:ffmpeg version N-91148-g8557a0940e Copyright (c) 2000-2018 the FFmpeg developers built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516 configuration:

5/2/2019 08:13:21 5238 [FFDEBUG] FF输出: libavutil 56. 18.102 / 56. 18.102 libavcodec 58. 19.102 / 58. 19.102 libavformat 58. 16.100 / 58. 16.100 libavdevice 58. 4.100 / 58. 4.100 libavfilter 7. 24.100 / 7. 24.100 libswscale 5. 2.100 / 5. 2.100 libswresample 3. 2.100 / 3. 2.100

5/2/2019 08:13:21 5238 [INFO] [rtmp connect] id=65ADIACS ip=::ffff:127.0.0.1 app=youtube args={"app":"youtube","flashVer":"LNX 9,0,124,2","tcUrl":"rtmp://127.0.0.1:1935/youtube","fpad":false,"capabilities":15,"audioCodecs":4071,"videoCodecs":252,"videoFunction":1} 5/2/2019 08:13:21 5238 [INFO] [rtmp play] Join stream. id=65ADIACS streamPath=/youtube/ streamId=1 5/2/2019 08:13:23 5238 [FFDEBUG] FF输出:Input #0, flv, from 'rtmp://127.0.0.1:1935/youtube/': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 encoder : Lavf58.20.100 Duration: 00:00:00.00, start: 0.033000, bitrate: N/A Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 128 kb/s Stream #0:1: Video: h264 (Main), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 1813 kb/s, 30 fps, 30 tbr, 1k tbn, 60 tbc

5/2/2019 08:13:24 5238 [FFDEBUG] FF输出:rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46/: Input/output error

5/2/2019 08:13:24 5238 [INFO] [rtmp play] Close stream. id=65ADIACS streamPath=/youtube/ streamId=1 5/2/2019 08:13:24 5238 [INFO] [rtmp disconnect] id=65ADIACS 5/2/2019 08:13:24 5238 [INFO] [Relay end] id= 1S8T3UZU

Tell me, please, how I can format the console output more readable?

No thats not the reason . The reason is that the stream key is missing

parthibd commented 5 years ago
5/2/2019 08:13:00 5238 [INFO] Node Media Server v2.1.0
5/2/2019 08:13:00 5238 [INFO] Node Media Rtmp Server started on port: 1935
5/2/2019 08:13:00 5238 [INFO] Node Media Http Server started on port: 8000
5/2/2019 08:13:00 5238 [INFO] Node Media WebSocket Server started on port: 8000
5/2/2019 08:13:00 5238 [INFO] Node Media Relay Server started
5/2/2019 08:13:21 5238 [INFO] [rtmp connect] id=1S8T3UZU ip=::ffff:192.168.31.216 app=youtube args={"app":"youtube","type":"nonprivate","tcUrl":"rtmp://192.168.31.230/youtube"}
5/2/2019 08:13:21 5238 [INFO] [rtmp publish] New stream. id=1S8T3UZU streamPath=/youtube/ streamId=1
5/2/2019 08:13:21 5238 [FFDEBUG] -fflags,nobuffer,-i,rtmp://127.0.0.1:1935/youtube/,-c,copy,-f,flv,rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46/
5/2/2019 08:13:21 5238 [INFO] [Relay dynamic push] start 1S8T3UZU rtmp://127.0.0.1:1935/youtube/ to rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46/
5/2/2019 08:13:21 5238 [INFO] [rtmp publish] Handle video. id=1S8T3UZU streamPath=/youtube/ frame_type=1 codec_id=7 codec_name=H264 1280x720
5/2/2019 08:13:21 5238 [INFO] [rtmp publish] Handle audio. id=1S8T3UZU streamPath=/youtube/ sound_format=10 sound_type=2 sound_size=1 sound_rate=3 codec_name=AAC 44100 2ch
5/2/2019 08:13:21 5238 [FFDEBUG] FF输出:ffmpeg version N-91148-g8557a0940e Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration:

5/2/2019 08:13:21 5238 [FFDEBUG] FF输出: libavutil 56. 18.102 / 56. 18.102
libavcodec 58. 19.102 / 58. 19.102
libavformat 58. 16.100 / 58. 16.100
libavdevice 58. 4.100 / 58. 4.100
libavfilter 7. 24.100 / 7. 24.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100

5/2/2019 08:13:21 5238 [INFO] [rtmp connect] id=65ADIACS ip=::ffff:127.0.0.1 app=youtube args={"app":"youtube","flashVer":"LNX 9,0,124,2","tcUrl":"rtmp://127.0.0.1:1935/youtube","fpad":false,"capabilities":15,"audioCodecs":4071,"videoCodecs":252,"videoFunction":1}
5/2/2019 08:13:21 5238 [INFO] [rtmp play] Join stream. id=65ADIACS streamPath=/youtube/ streamId=1
5/2/2019 08:13:23 5238 [FFDEBUG] FF输出:Input #0, flv, from 'rtmp://127.0.0.1:1935/youtube/':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
encoder : Lavf58.20.100
Duration: 00:00:00.00, start: 0.033000, bitrate: N/A
Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 128 kb/s
Stream #0:1: Video: h264 (Main), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 1813 kb/s, 30 fps, 30 tbr, 1k tbn, 60 tbc

5/2/2019 08:13:24 5238 [FFDEBUG] FF输出:rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46/: Input/output error

5/2/2019 08:13:24 5238 [INFO] [rtmp play] Close stream. id=65ADIACS streamPath=/youtube/ streamId=1
5/2/2019 08:13:24 5238 [INFO] [rtmp disconnect] id=65ADIACS
5/2/2019 08:13:24 5238 [INFO] [Relay end] id= 1S8T3UZU
parthibd commented 5 years ago

Okay . The stream key is there . Can you give me the output of this

ffmpeg -loglevel debug -re -i <input> -f flv rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46/

parthibd commented 5 years ago

Here you are streaming a file as input to simulate a livestream .

durygus commented 5 years ago

A very large log will get with the "-loglevel debug" key. Let's make it easier:

1) With the symbol "/" at the end of the URL video broadcast does not work: MacBook-Pro:/ Vadim$ ffmpeg -re -i ~/Downloads/temp/Ma\ Long\ Forehand\ and\ Backhand\ Technique.mp4 -c copy -f flv rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46/ -loglevel error RTMP_ReadPacket, failed to read RTMP packet header rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46/: Unknown error occurred

2) Without the "/" symbol at the end of the URL, the video broadcast really works: MacBook-Pro:/ Vadim$ ffmpeg -re -i ~/Downloads/temp/Ma\ Long\ Forehand\ and\ Backhand\ Technique.mp4 -c copy -f flv rtmp://a.rtmp.youtube.com/live2/9qtz-mu76-7htf-ej46 -loglevel error

My qualification is not enough to correct the error in the code: "Do not put the character "/" if it is not in the edge URL in the config."

parthibd commented 5 years ago

Okay . That sounds great . Can you make a pull request to fix this ?

parthibd commented 5 years ago

It seems ffmpeg is not normalizing the urls . But thats fine . I'll make a pull request fixing this ASAP .

durygus commented 5 years ago

Thank you so much!

parthibd commented 5 years ago

You're welcome . :)

durygus commented 5 years ago

@parthibd, is it ASAP time to come soon? :)

NickGrant89 commented 5 years ago

@VadimGuslistov - I have a work around for this, if you still need a fix ?

durygus commented 5 years ago

Yes, I need it. Thank you very much!

JohnTrabusca commented 5 years ago

@VadimGuslistov - I have a work around for this, if you still need a fix ?

Hello do you mind sharing with me as well, I been trying to it on Facebook Live but I'm unable to do it, and I'm not sure what I'm doing wrong

amon-talha commented 4 years ago

Yes, I need it. Thank you very much!

Hello, I've got the same issue could you help me out if you've found the solution?

amon-talha commented 4 years ago

I think I got a workaround, not sure if it's the correct way of doing it.

in the function onPostPublish in node_relay_server.js add a variable. let newStream = stream.length ?/${stream}: stream and change conf.ouPath = hasApp ?${conf.edge}/${stream}:${conf.edge}${streamPath}; to conf.ouPath = hasApp ?${conf.edge}${newStream}:${conf.edge}${streamPath};

could someone check it out if it's correct, please?

cpanel10x commented 4 years ago

I think I got a workaround, not sure if it's the correct way of doing it.

in the function onPostPublish in node_relay_server.js add a variable. let newStream = stream.length ?/${stream}: stream and change conf.ouPath = hasApp ?${conf.edge}/${stream}:${conf.edge}${streamPath}; to conf.ouPath = hasApp ?${conf.edge}${newStream}:${conf.edge}${streamPath};

could someone check it out if it's correct, please?

Its not work. My solution is replace all hasApp ? ${conf.edge}/${stream}:${conf.edge}${streamPath}; to 'rtmp://a.rtmp.youtube.com/live2/<stream key>' lol

NickGrant89 commented 4 years ago

Hi

Sorry I’ve been away. I will look at my fix later and update the form.

Nick Grant

On 18 Jul 2019, at 10:16, cpanel10x notifications@github.com<mailto:notifications@github.com> wrote:

I think I got a workaround, not sure if it's the correct way of doing it.

in the function onPostPublish in node_relay_server.js add a variable. let newStream = stream.length ? /${stream} : stream and change conf.ouPath = hasApp ? ${conf.edge}/${stream}:${conf.edge}${streamPath}; to conf.ouPath = hasApp ? ${conf.edge}${newStream}:${conf.edge}${streamPath};

could someone check it out if it's correct, please?

Its not work. My solution is replace all hasApp ? ${conf.edge}/${stream}:${conf.edge}${streamPath}; to rtmp://a.rtmp.youtube.com/live2/ lol

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/illuspas/Node-Media-Server/issues/196?email_source=notifications&email_token=AG4NAQPBDHGXFZGSBIVOQKTQAAYIPA5CNFSM4HJQ3D5KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2H3RLI#issuecomment-512735405, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AG4NAQN3ZP3NZ3YARD744J3QAAYIPANCNFSM4HJQ3D5A.

NickGrant89 commented 4 years ago

Hi All

To get this to work i removed ${stream} from the onPostPublish function .

onPostPublish(id, streamPath, args) { if (!this.config.relay.tasks) { return; } let regRes = /\/(.)\/(.)/gi.exec(streamPath); let [app, stream] = _.slice(regRes, 1); 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); } }

}

Then within my relay config this is my setup and it works like a dream. i'm not sure if this is the correct way around but it works.

relay: { ffmpeg: '/usr/local/bin/ffmpeg', tasks: [ { app: 'live', mode: 'push', edge: 'rtmp://a.rtmp.youtube.com/live2/', } ] }

cpanel10x commented 4 years ago
onPostPublish(id, streamPath, args) {
  if (!this.config.relay.tasks) {
  return;
  }
  let regRes = /\/(.*)\/(.*)/gi.exec(streamPath);
  let [app, stream] = _.slice(regRes, 1);
  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);
    }
  }

}
cpanel10x commented 4 years ago

Hi guys. That pull is great solution for fix that problem https://github.com/illuspas/Node-Media-Server/pull/210

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.

shubhamkourav commented 3 years ago

How to pass the dynamic stream key?

shubhamkourav commented 3 years ago

How to get the Stream path when disconnecting server

chrisspiegl commented 3 years ago

@kauravshubham Please open a new issue for whatever you are trying to achieve since this is not the topic that is being discussed here.

kamal-hossain commented 2 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.

For youtube:

NOTE: You need to add / after the main URL of rtmp.

Example: rtmp://a.rtmp.youtube.com/live1/jmhw-rgv0-uem7-6411-195h