Node-fluent-ffmpeg: Streaming to RMTP YouTube results in error

Created on 25 Sep 2018  路  3Comments  路  Source: fluent-ffmpeg/node-fluent-ffmpeg

Version information

  • fluent-ffmpeg version: latest on npm
  • ffmpeg version: 4.0
  • OS: Windows 7

Code to reproduce

// Requires
var fs = require("fs");
var ffmpeg = require("fluent-ffmpeg");

// Config
var config = require("./config");

// FFMpeg setup
ffmpeg.setFfmpegPath("bin/ffmpeg.exe");
ffmpeg.setFfprobePath("bin/ffprobe.exe");

// first command
var command = ffmpeg()
        .input("videos/first.mp4")
        .fps(15)
        .size('150%')
        .autopad()
        .on('start', function() {
            console.log("Started!");
        })
        .on('error', function(err) {
            console.log("Error!");
            console.log(err);
        })
        .on('end', function() {
            console.log("Finished!");
        })
        .save("rtmp://a.rtmp.youtube.com/live2/STREAMKEY");

(note: if the problem only happens with some inputs, include a link to such an input file)

Expected results

No thrown error and some way of receiving an information when the streaming of the file ended (does it trigger the end function? I want to maintain the stream and run another file once one ends)

Observed results

running this code results in following error

Error: ffmpeg exited with code 1: rtmp://a.rtmp.youtube.com/live2/[MYSTREAMKEY]: Invalid argument

    at ChildProcess.<anonymous> (E:\Development\node-videostream\node_modules\fluent-ffmpeg\lib\processor.js:182:22)
    at ChildProcess.emit (events.js:127:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)

Running the same code with the stream function rather than the save function results in following error:

E:\Development\node-videostream\node_modules\fluent-ffmpeg\lib\recipes.js:51
    if (stream && !('writable' in stream)) {
                               ^

TypeError: Cannot use 'in' operator to search for 'writable' in rtmp://a.rtmp.youtube.com/live2/[MYSTREAMKEY] at FfmpegCommand.proto.writeToStream.proto.pipe.proto.stream (E:\Development\node-videostream\no
de_modules\fluent-ffmpeg\lib\recipes.js:51:32)
    at Object.<anonymous> (E:\Development\node-videostream\index.js:28:6)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Function.Module.runMain (module.js:703:10)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:665:3

Most helpful comment

You need to include the port (:1935) to get rtmp to stream properly, and you need to specify your format as "flv":

var command = ffmpeg()
        .input("videos/first.mp4")
        .fps(15)
        .size('150%')
        .autopad()
        .format('flv')
        .on('start', function() {
            console.log("Started!");
        })
        .on('error', function(err) {
            console.log("Error!");
            console.log(err);
        })
        .on('end', function() {
            console.log("Finished!");
        })
        .save("rtmp://a.rtmp.youtube.com:1935/live2/STREAMKEY");

All 3 comments

Hi! Could someone provide an example about creating stream to YT using the ffmpeg?
Have the same issues as above

You need to include the port (:1935) to get rtmp to stream properly, and you need to specify your format as "flv":

var command = ffmpeg()
        .input("videos/first.mp4")
        .fps(15)
        .size('150%')
        .autopad()
        .format('flv')
        .on('start', function() {
            console.log("Started!");
        })
        .on('error', function(err) {
            console.log("Error!");
            console.log(err);
        })
        .on('end', function() {
            console.log("Finished!");
        })
        .save("rtmp://a.rtmp.youtube.com:1935/live2/STREAMKEY");

thank you, this worked!

Was this page helpful?
0 / 5 - 0 ratings