3

So I'm trying to create an application that will be able to send packets to Youtube as a live stream. So basically I enter my url to the program (rtmp://a.rtmp.youtube.com/live2) and then it would start streaming and sending packets of an image of youtube. I've looking everywhere and I'm not sure if this is possible with nodejs. So basically, I would be able to live stream to Youtube 24/7 with my nodejs application. Please feel free to comment any question.

Hackermon
  • 69
  • 1
  • 1
  • 8

1 Answers1

0

I don't know about image. But if you have a video then you can stream it to youtube with ffmpeg.

Method: 1

Without nodejs it can be done with the cli like this. Open the cli where your video file is stored. And run the follwing command:

ffmpeg -re -i vieo_you_wanna_stream.mp4 -c copy -f flv rtmp://a.rtmp.youtube.com/live2/SECRET_STREAM_KEY

Method: 2

If you really need to stream from nodejs server then you can do the following: Create a file called runCommand.js with these lines of code:

var spawn = require('child_process').spawn;
module.exports = (cmd, args, onData, onFinish) => {
    var proc = spawn(cmd, args.split(' '));
    proc.stdout.on('data', onData);
    proc.stderr.setEncoding("utf8")
    proc.stderr.on('data', err => console.log(err) );
    proc.on('close', onFinish);
}

Now in your app.js file put these lines of codes:

const runCommand = require('./runCommand')

runCommand(
  'ffmpeg',
  '-re -i vieo_you_wanna_stream.mp4 -c copy -f flv rtmp://a.rtmp.youtube.com/live2/SECRET_STREAM_KEY',
  (data) => console.log(data),
  () => console.log('finished')
)

Now from cli run

node app.js

If your video path, ffmpeg and your youtube rtmp link is corrent the it will immediately start the stream.

Note:

If you really want to stream only image to youtube with this method, then you can convert your image to a video with any kind of converter. And use this method to stream the video to youtube.

Kamal Hossain
  • 530
  • 7
  • 18