I've been trying to Livestream a programmatically created image to youtube using node. I've had very limited success using FFmpeg. While I have managed to create and save an image thanks to this insightful thread, I have yet to make the code work for streaming to an RTMP server.
const cp = require('child_process'),
destination = 'rtmp://a.rtmp.youtube.com/live2/[redacted]', //stream token redacted
proc = cp.spawn('./ffmpeg/bin/ffmpeg.exe', [
'-f', 'rawvideo',
'-pix_fmt', 'rgb24',
'-s', '426x240',
'-i', '-', //allow us to insert a buffer through stdin
'-f', 'flv',
destination
]);
proc.stderr.pipe(process.stdout);
(function loop() {
setTimeout(loop, 1000 / 30); //run loop at 30 fps
const data = Array.from({length: 426 * 240 * 4}, () => ~~(Math.random() * 0xff)); //create array with random data
proc.stdin.write(Buffer.from(data)); //convert array to buffer and send it to ffmpeg
})();
When running this code no errors appear and everything appears to be working, however, YouTube reports that no data is being received. Does anybody know what is going wrong here?
Update: This is really counter-intuitive but adding a slash to the destination like this 'rtmp://a.rtmp.youtube.com/live2/[redacted]/' causes ffmpeg to throw a generic I/O error. This is really weird to me. Apologies if the answer to this is obvious, I'm really inexperienced with ffmpeg.