IP camera: stream and record a fragment

Hello, before anything, Im using windows 7.

I try to use an ip camera to stream live, and also i want be able to choose when to start recording and when to stop manually or by a node-red command.

I've tried things in node-js like the "JSmepg" library and the nodes "node-rtsp-stream" and "node-rtsp-recorder", but with this last one I didn't succeed.
(i tried this https://itqna.net/questions/74672/how-record-rtsp-stream)

I was searching for several forums and google, but almost all of them are just to stream..but found "node-red-contrib-onvif-nodes", and it seems to have things that might interest me, but they don't connect me.Somenone used them?
image

In short: I want to record a fragment of a stream my ip camera and I'm a little new in this area

We had a "long" discussion already about RTSP, and somewhere in the middle you can find a flow I created to achieve rtsp decoding in Node-RED. But it doesn't always work (as @SuperNinja reported me), but I have not enough Ffmpeg knowledge to get it solved, and no time to experiment with it...

But I think that flow might be a starting point for your question...

I have planned to continue improving this contribution further in a couple of months. But if I'm not mistaken, Onvif only offers you the ability to get an rtsp url from your camera. But it doesn't do any decoding. So my Onvif nodes won't be of any help to you for this particular issue you have.

Right now I was keeping an eye on your post, I will be commenting on my progress. If I get something I will mention it here

1 Like

With ffmpeg you can save a rtsp stream to a file

I use something like this within an exec node:

ffmpeg -i rtsp://ip:port/stream -vcodec copy recording.mp4
1 Like

Please do so!!!!! Need that stuff also for my own home project ...

Hey @bakman2,
In my flow I wanted to do everything in memory. So Ffmpeg puts the image in an output pipe, and then that data is transferred to the next nodes in the flow. And the next node could e.g. be a FileOut node to write it to a file, but it could also be my (draft) node-red-contrib-ui-camera-viewer node to show it on the dashboard, or whatever. Don't want to do everything via disc io...

But if you (or someone else) has ffmpeg experience, don't hesitate to improve my flow in the link above!!!!!

For some reason that I don't know now, node-red doesn't read the ffmpeg command, but the windows cmd does : /
image
image

You need to specify the path of the bin (try which ffmpeg and use that path), or it could be a permission problem.

(*edit you are on windows, I have no idea how it works there)

ok that worked for the code that @BartButenaers has given me

In your flow, you are re-encoding the stream, major cpu impact, is this needed?


Shouldn't the video be encoded?
vlc doesn't show Codec data and doesn't let me play the file. It is the same error I had with node-js
windows player say its a codec problem
image
Could I have an error with the ffmpeg?

Hmmm, not sure what you mean.
This was my command:

ffmpeg -f rtsp -i \"rtsp://freja.hiof.no:1935/rtplive/_definst_/hessdalen03.stream\" -f image2pipe pipe:1

I only see decoding of the RTSP stream and then redirecting the image to pipe 1 (to keep it in memory). Where is the re-encoding then?

[EDIT] Or do you mean that (to create afterwards in my flow e.g. an mp4 file) I have to run ffmpeg again (in an imageToMp4 node)? While you do it in a single ffmpeg command (decode and encode). I only want to have the individual images in my node-red flow, to be able to do some specific processing in the future (e.g. license plate recognition, face detection, motion detection, or whatever ...).

Ah no, I was reading -vcodec h264_mmal in the posts above.

If you want to do object recognition, isn't opencv a better option ?

1 Like

How can I stop the flow of the exec node without using msg.kill? I cut the recording and not let the process end. With windows cmd pressing ctrl + C saves the file and is visible with vlc
image
image

You can't, you either kill it with msg.kill (which is a programmatic ctrl+c) or it runs forever.

I use a trigger, based on motion, if motion, start recording 30 seconds, if new motion is detected keep recording until no motion is detected and a msg.kill is given.

in the exec node it marks several options, in wikipedia I saw that ctrl + c is SIGINT, but sometimes it gives me an error when using it
image

In any case, the exec node does not seem to be worth recording as the cmd

only with cmd is it working for me
i will try to do it with node.js .
if it works, I will try to create a simple node that reproduces this operation ( with http stream and download option)

On the commandline ctrl+c is a SIGINT (interrupt), I send {"kill":"SIGTERM"} without errors.

Absolutely, but then I used ffmpeg to decode the stream and opencv to do the processing.

Just for completeness: some time after we had the long RTSP discussion, there was another question on the forum about storing video as an mp4 file. Since then I don't use Exec nodes anymore for ffmpeg, but always the Daemon node instead (as you can see here). Because the Daemon node allows you to keep converting (endless) e.g. images to a video file... In that discussion I have added some drawings to explain how the pipes work.

Hello again, I did not have time to continue with this, so I will leave what I have done for the moment.
FFmpeg is surely what I'm looking for

it helps me to stream on node.js and node-Red, but when recording on node-network, it gives me errors if I don't assign the parameter "-t" (a timer)

To stream i gonna use rtsp-stream like this :
image
then on a html i did:
image

To record directly from the stream:

When i have time , i gonna continue with this proyect

Any comments to help me are well received
links: FFmpeg page
meanwhile, in node red:

[{"id":"4ff3a126.4214d","type":"exec","z":"85a6a280.b9cef","command":"fmepg -f rtsp -i \"rtsp://user:password@your rtsp dir here\" -f image2pipe pipe:1","addpay":false,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"Decode RTSP stream","x":1500,"y":1360,"wires":[["4ba72b96.2470c4"],[],[]]},{"id":"ceecc1f7.952bd","type":"inject","z":"85a6a280.b9cef","name":"Start stream","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1030,"y":1360,"wires":[["4ff3a126.4214d"]]},{"id":"4ba72b96.2470c4","type":"image","z":"85a6a280.b9cef","name":"","width":"500","x":1740,"y":1360,"wires":[]},{"id":"2b94ff5e.931a1","type":"change","z":"85a6a280.b9cef","name":"","rules":[{"t":"set","p":"kill","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1270,"y":1400,"wires":[["4ff3a126.4214d"]]},{"id":"baa491b5.74464","type":"inject","z":"85a6a280.b9cef","name":"Stop all streams","topic":"","payload":"SIGTERM","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1040,"y":1400,"wires":[["2b94ff5e.931a1"]]},{"id":"130e0105.6940af","type":"exec","z":"85a6a280.b9cef","command":"fmepg -i \"rtsp://user:password@your rtsp dir here\"  -t 10 -acodec copy -vcodec copy \"Your file direc. here\" -y","addpay":false,"append":"","useSpawn":"false","timer":"0","oldrc":false,"name":"Record RTSP stream","x":1500,"y":1660,"wires":[["1aa2ccc2.66ce13"],["1aa2ccc2.66ce13"],["1aa2ccc2.66ce13"]]},{"id":"8da68e48.8aedc","type":"inject","z":"85a6a280.b9cef","name":"Start stream","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1050,"y":1640,"wires":[["130e0105.6940af"]]},{"id":"1aa2ccc2.66ce13","type":"debug","z":"85a6a280.b9cef","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1790,"y":1660,"wires":[]},{"id":"c0861826.960798","type":"comment","z":"85a6a280.b9cef","name":" here y copy the codec, i set a time and i force the overwrite to a file","info":"fmepg -i \"rtsp://user:password@your rtsp dir here\"  -t 10 -acodec copy -vcodec copy \"Your file direc. here\" -y","x":1440,"y":1580,"wires":[]}]
1 Like

Hello, I would like to reopen this topic.
I am using Ffmpeg and the libraries "node-rtsp-stream", "fluent-ffmpeg"
and "JSmpeg" for this.
I need to stream and select with node-red when to start recording (with a true signal) and when to stop (with a false signal)

The biggest problem I am encountering is stopping the recording and saving it.
A msg.kill or things like that delete my video

(I have a half-done node for node-red for recording, but I don't stop it :sweat_smile:)
someone with experience with ffmpeg?

Hi Anxo,
Then you have a half of a node more than us :wink:
Perhaps you can share with us how it works. Is it available on Github? And why you are using all those libraries.
Thanks!
Bart