seriously
seriously

Reputation: 1367

using ffmpeg and node to stream a fixed video

I am trying to use a node module to stream a video on a website. The modules name is node-media-server. I currently have set it up to work when streaming a live source from obs and it works fine. What I can't figure out is how to stream a fixed h.264 video. There npm documentation says to use FFMPEG but this got me confused what does this exactly mean. How do I use ffmpeg to publish the fixed video to the node media server? The how to is mentioned under the "Publishing live streams" section in their npm documentation. Can you please help me understand how ffmpeg will come in handy here? Thanks in advance.

Their npm documentation: https://www.npmjs.com/package/node-media-server

Upvotes: 1

Views: 2062

Answers (1)

seriously
seriously

Reputation: 1367

I used fluent-ffmpeg to run the ffmpeg command from node js and it works.

const fs = require('fs');
const path = require('path')

const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const fluent = require('fluent-ffmpeg');
fluent.setFfmpegPath(ffmpegPath);

const executeFfmpeg = args => {
  let command = fluent().output(' '); // pass "Invalid output" validation
  command._outputs[0].isFile = false; // disable adding "-y" argument
  command._outputs[0].target = ""; // bypass "Unable to find a suitable output format for ' '"
  command._global.get = () => { // append custom arguments
    return typeof args === "string" ? args.split(' ') : args;
  };
  return command;
};

executeFfmpeg(`ffmpeg -re -i INPUT_FILE_NAME -c copy -f flv rtmp://localhost/live/STREAM_NAME`)
  .on('start', commandLine => console.log('start', commandLine))
  .on('codecData', codecData => console.log('codecData', codecData))
  .on('error', error => console.log('error', error))
  .on('stderr', stderr => console.log('stderr', stderr))
  .run();

Upvotes: 1

Related Questions