[beta testing] nodes for live streaming mp4

I have re-merged the "new" thread to here so they are now in one place and this should no longer auto close...

1 Like

Happy New Year all!

I have managed to get some RTSP cameras working with this example, with buttons to select the source, but cannot figure out what command I need to show an mjpeg stream. I can display it in a template node but I would like to have just the one video "window" for all my camera feeds.

Any help would be much appreciated

Happy New Year too!

Glad to help but you have to provide some more details. I suppose you are looking for how the command for ffmpeg should look like?

What is the source of your mjpeg stream? Is it a network camera? Is it a USB camera? If it is a USB camera, is it attached to a Raspberry Pi? If so have you prepared the Raspberry to use the GPU? What have you tried so far?

Anyway, running ffmpeg and converting mjpeg to mp4 is loading the CPU pretty heavy, so it is better if you can utilize the GPU. Alternativelly you can stream mjpeg directly to the dashboard by using the "pipe2jpeg" and media nodes

Can you elaborate what you mean by having just one video window? Show what you have done so far

Hi,

I'm using a pi4. I have a number of buttons which pass the ffmpeg command line to a single exec node, which feeds into the mp4frag and then ui_mp4frag node. This alows me to select from a number of RTSP camera feeds to view. This is working fine.

I also have an mjpeg stream from an android tablet, which I would like to view in the same ui_mp4frag node window. After some searching I belive that this mjpeg stream can be "wrapped" into a an mp4, so no encoding needed ?

The command I though should be something like this -

ffmpeg -loglevel quiet mjpeg -r 15 -i <(wget http://192.168.1.128:2971/camera/stream -O -) -c:v copy -f mp4 -movflags +frag_keyframe+empty_moov+default_base_moof pipe:1

However its not correct as I just get a pid# followed by rc1 on the exec node.

Thanks...

I have a camera that delivers mjpeg streams and I have to convert it to mp4. I don't think you can do without converting. I use this command line:

ffmpeg -re -i http://192.168.0.237:8889/?action=stream -c:v h264_omx -bsf:a aac_adtstoasc -f mp4 -movflags +frag_every_frame+empty_moov+default_base_moof -min_frag_duration 500000 pipe:1

But I use the GPU in a RPi3. Instead of using the GPU, to use the CPU, the command line should be:

ffmpeg -re -i http://192.168.0.237:8889/?action=stream -c:v libx264 -bsf:a aac_adtstoasc -f mp4 -movflags +frag_every_frame+empty_moov+default_base_moof -min_frag_duration 500000 pipe:1

Using the CPU, the load is 99%, no good, using the GPU, the CPU load is lower at around 19%. You might be more succesful

This sort of works but the video keeps jumping back and replaying the same clip plus a bit of new video, in an amusing "max headroom" kind of way :wink:

I'm assuming this is to do with -min_frag_duration 500000, tried removing that but effect is even worse.

I couldn't find out what -re means -r is frame rate, but what does e mean ?

In my case, using a RPi3, it works but I could wish for better quality. On the other hand, my source is just 640x480 so I should not complain. The video is delayed a second or so relative to real time and I can briefly see a fragment of the reload arrow approx every 3rd second. But it is not replaying the same. I thought my issues where maybe related to using a slower RPi

Anyway let's check your setup a bit. Your version of ffmpeg and how you built it. Did you build it to also support the OpenMAX H.264 GPU acceleration?

In a command/terminal window, run ffmpeg -encoders | grep 264 What does it show?

In the ui_mp4frag node config, what player do you have/using in the order 1 position? In my case I use hls.js, Also mp4 works but then the reload arrow stays longer in the video

Regarding all parameters for ffmpeg, I honestly don't know. The -re I think means "read from real time", maybe try without this parameter? Found the post where @kevinGodell explained this:
" One thing I noticed is that the ffmpeg command needs a little tweak to smooth out the video. Add -re in front of the -i so that it reads at realtime instead of going too fast."

ffmpeg version 4.1.6-1~deb10u1+rpt1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Raspbian 8.3.0-6+rpi1)
V..... libx264 libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
V..... libx264rgb libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264)
V..... h264_omx OpenMAX IL H.264 video encoder (codec h264)
V..... h264_v4l2m2m V4L2 mem2mem H.264 encoder wrapper (codec h264)
V..... h264_vaapi H.264/AVC (VAAPI) (codec h264)

Honestly cannot remember how I installed it, followed some instruction I found somewhere.
My source is also 640X480 at 10fps, I'm using the h264_omx option without audio settings you had.

It seems like the putting hls.js to the top of the list works, without the jumping effect.

However I can see the start of spinning circle constantly being redrawn in Chrome, although its not visible in firefox. I'm not sure if this is a problem or not, maybe it causes more traffic, connections etc ?

CPU load for ffmeg is only around 0.7 to 1% as shown by top so I guess thats no problem.

I happy to live with the circle, unless anyone has any other sugestions.

Thanks for pointing me in the right direction.

Hi. I try to install using the npm u give but results in error. May I know why?

I just reinstalled it on my pi4 using that command and it successfully installed and runs ok after reboot. My guess is that there is a configuration issue. Please post additional details, such as any errors listed in the command line when installing, etc.

is this only can be installed in Pi? if i using node red in laptop is it possible? i receive this error

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'install',
1 verbose cli 'kevinGodell/node-red-contrib-ui-mp4frag'
1 verbose cli ]
2 info using npm@6.14.5
3 info using node@v12.18.2
4 verbose npm-session 4987401f22a7e1c9
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 silly fetchPackageMetaData error for github:kevinGodell/node-red-contrib-ui-mp4frag Error while executing:
7 silly fetchPackageMetaData undefined ls-remote -h -t ssh://git@github.com/kevinGodell/node-red-contrib-ui-mp4frag.git
7 silly fetchPackageMetaData
7 silly fetchPackageMetaData
7 silly fetchPackageMetaData spawn git ENOENT
8 timing stage:rollbackFailedOptional Completed in 1ms
9 timing stage:runTopLevelLifecycles Completed in 746ms
10 verbose stack Error: spawn git ENOENT
10 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
10 verbose stack at onErrorNT (internal/child_process.js:469:16)
10 verbose stack at processTicksAndRejections (internal/process/task_queues.js:84:21)
11 verbose cwd C:\Program Files\nodejs\node_modules\npm\node_modules
12 verbose Windows_NT 10.0.18363
13 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "kevinGodell/node-red-contrib-ui-mp4frag"
14 verbose node v12.18.2
15 verbose npm v6.14.5
16 error code ENOENT
17 error syscall spawn git
18 error path git
19 error errno ENOENT
20 error enoent Error while executing:
20 error enoent undefined ls-remote -h -t ssh://git@github.com/kevinGodell/node-red-contrib-ui-mp4frag.git
20 error enoent
20 error enoent
20 error enoent spawn git ENOENT
21 error enoent This is related to npm not being able to find a file.
22 verbose exit [ 1, true ]

git is not installed on your machine.

because this package is being pulled from github and not published via npm, yet, you will need to setup git on your windows pc and then make sure the git command is in PATH.

okay thank you. i try first

make sure the git command is in PATH. can u explain more about this statement?

After installing git, it may not work by opening a command line and running it as git because your system may not know where it is. The git installer may do that for you, I am not sure. If you try to install git, let me know if the npm command works afterward.

According to this tutorial @ How to Install Git on Windows {Step-by-Step Tutorial} - PhoenixNAP, it may configure PATH for you.

I installed npm using your command in Git CMD. It said a peer of socket. Need to install peer dependecies yourself. But when I open my node red flow still those nodes are not available

ui_mp4frag already in my node red. only the mp4frag node is not available. according to command windows, it stated there is an error: cannot find module 'socket.io'

It was probably a warning and not an error, I hope. The reason for the peer dependency is because socket io v2 is not compatible with v3 and i did not want to force a version with my node that might break other nodes, such as the node-red-dashboard that is still using v2. Most likely you already have v2 installed if you have the dashboard installed and there should not be any run time errors. Maybe soon the node-red-dashboard will update to v3 and then I will also list socket.io as a regular dependency and no longer support v2.

i already got those nodes required. Just when being deployed, the dashboard ui only showing video playback ready sign. Not showing any stream from my camera