Save 4 rtsp stream from 4 camera to video file (synchronized)

Hello I would like to know if there is a way to save 4 rtsp stream from 4 camera to video file with gstreamer or another library.
I try with openrtsp but I have a duration problem.
thanks in advance!

Hi,
For each RTSP source you can run a gstreamer command like this:

$ gst-launch-1.0 rtspsrc location=rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov ! rtph264depay ! h264parse ! matroskamux ! filesink location=a.mkv

Thanks but will the 4 records be synchronized ?
If not how can I do ?

Hi,
It is to save each input individually. If your usecase us to composite 4 source into one out, need to decode the inputs, composite four to one, and re-encode to one out file.

Thank for your answer, In my case I want to have 4 output separately

Hi,
So in your usecase, you can run 4 cameras individual gstreamer commands to save the files. No need to re-encode input streams. There’s synchronization mechanism in gstreamer, so output files should have timestamps identical to input sources.

Ok thanks , I have several questions :

Is this command is correct to run simultaneously 2 rtsp stream :
gst-launch-1.0 rtspsrc location=rtsp://192.168.1.19:554/1/h264major ! rtph264depay ! h264parse ! matroskamux ! filesink location=1.mkv & gst-launch-1.0 rtspsrc location=rtsp://192.168.1.20:554/1/h264major ! rtph264depay ! h264parse ! matroskamux ! filesink location=2.mkv

How do you stop recording the stream ?

How do you say to record only 10 seconds ?

Thanks in advance

Hi,
You may try this:
Gst-launch-1.0 nvcompositor bug in tegra-l4t-r32.5.1? - #6 by labi

sleep 10 second and run killall -2 gst-launch-1.0