0

I need to display the live streaming vidoe(rtsp) on a website(http, vue framework) with nodejs and vue framework.

I've looked it up a lot and got the basic logic of what they are and how it works. So I'm planning on to convert rtsp to hls with nodejs using socket.io and display it on a web.(let me know if there's more efficient way way to do it)

The thing is, for some reason, when I try to develop it in my backend(nodejs), node just keep sends me an error that FFMpeg module wasn't found. It's been over a week.. please help.

Btw, all works with ffmpeg cmd(window powerShell).

How I set up(ffmpeg):

  1. downloaded ffmpeg from https://ffmpeg.org/

  2. added to system path: C:\Users\Marie\Desktop\ffmpeg-4.3.1-2020-11-19-full_build\bin\

  3. tested with window powerShell and converted rstp to m3u8:

    ffmpeg -i 'rtsp://ip.ip.ip/media/video1' -hls_time 3 -hls_wrap 10 'C:\Users\Marie\Desktop\tmp\hls/streaming.m3u8'

below is a screen shot of no. 3 result enter image description here


how I set up(nodejs)

  1. npm i ffmpeg fluent-ffmpeg rtsp-ffmpeg
  2. I've just copied and pasted the example working code and changed rtsp link to mine. e.g: (https://www.npmjs.com/package/rtsp-ffmpeg)

=> didn't work out, error says can't find ffmpeg module

  1. set up path manually e.g.) ffmpeg.setFfmpegPath(path)

=> didn't work out. error says can't find ffmpeg module

... I've seriously tried almost everything like delete, re-install ffmpeg, changed path, added path manyally, .. Please help....

Edited: package.json

{
  "name": "streaming",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node app.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1",
    "ffmpeg": "0.0.4",
    "fluent-ffmpeg": "^2.1.2",
    "jsmpeg": "^1.0.0",
    "node-media-server": "^2.2.4",
    "node-onvif": "^0.1.7",
    "node-rtsp-stream": "0.0.9",
    "rtsp-ffmpeg": "0.0.15",
    "socket.io": "^3.0.4",
    "ws": "^7.4.1"
  }
}

app.js

const Stream = require('node-rtsp-stream')

// let path = 'C:/Users/Marie/Desktop/ffmpeg-4.3.1-2020-11-19-full_build/bin/ffmpeg.exe'
// let path = 'C:/Users/Marie/Desktop/ffmpeg-4.3.1-2020-11-19-full_build/bin/'
let path = 'C:/Users/Marie/Desktop/ffmpeg-4.3.1-2020-11-19-full_build/bin'
const ffmpeg = require('fluent-ffmpeg')

ffmpeg.setFfmpegPath(path)

stream = new Stream({
  name: 'name',
  streamUrl: 'rtsp://ip.ip.ip.ip/media/video1',
  wsPort: 9999,
  ffmpegOptions: { // options ffmpeg flags
    '-stats': '', // an option with no neccessary value uses a blank string
    '-r': 30 // options with required values specify the value after the key
  }
})

Error: spawn ffmpeg ENOENT

app.js (for another test)

const app = require( 'express' )(),
    server = require( 'http' ).Server( app ),
    io = require( 'socket.io' )( server ),
    rtsp = require( 'rtsp-ffmpeg' )

process.env.FFMPEG_PATH = 'C:/Users/Marie/Desktop/ffmpeg-4.3.1-2020-11-19-full_build/bin/ffmpeg.exe'
// console.log( rtsp.FFMpeg )

server.listen( 6147 )
var uri = 'rtsp://ip.ip.ip.ip/media/video1',
    stream = new rtsp.FFMpeg( { input: uri } )
io.on( 'connection', function ( socket )
{
    var pipeStream = function ( data )
    {
        socket.emit( 'data', data.toString( 'base64' ) )
    }
    stream.on( 'data', pipeStream )
    socket.on( 'disconnect', function ()
    {
        stream.removeListener( 'data', pipeStream )
    } )
} )
app.get( '/', function ( req, res )
{
    res.sendFile( __dirname + '/index.html' )
} )

error: FMpeg executable wasn't found. Install this package and check FFMpeg.cmd property

nodejs version = 10.16.3

Chawchawchaw
  • 203
  • 1
  • 4
  • 13

1 Answers1

0

Turns out, this library doesn't work properly in windows. Changed to rtsp-ffmpeg and I got it work.

related git issue: https://github.com/kyriesent/node-rtsp-stream/issues/28

  • You have to add ffmepg.exe in your project folder to trigger ffmpeg in nodejs. This library can find the path properly in Linux/Unix. Also, many of other functions from this library doesn't work properly (maybe on windows only) so I do not suggest it to anyone who needs to develop it on window, web, and nodejs based environment.

The one I've got it work: https://www.npmjs.com/package/rtsp-ffmpeg

Chawchawchaw
  • 203
  • 1
  • 4
  • 13