FFMPEG grab multi RTSP streams concurrently with their own start time offsets

AndrewDT

n3wb
Feb 18, 2025
6
0
Australia
Please can someone help me with my battle here.

I am trying to capture multiple RSTP streams from IP cameras at the same time, but with some of the cameras having a start tim delay by creating an offset. I can capture simultaneously without issue, but when I add an offset to any camera, all cameras listed afterwards are stuck with the same offset as that one above even when it is set to zero.

Below is the commands in my batch file run in windows.
_________________________________
@echo off
echo ========================================
echo RTSP Stream Capture Script
echo ========================================
echo.
echo Make sure FFmpeg is installed and in your PATH
echo.
echo Capturing 3 stream(s)...
echo.

TIMEOUT /T 0 /NOBREAK
START ffmpeg -i "rtsp:/admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0" -t 10 -c copy -c:v copy -an C:\CameraRecord\Zone_Acc_R2_33_John_Smith_CAM1.mp4

TIMEOUT /T 3 /NOBREAK
START ffmpeg -i "rtsp:/admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0" -t 5 -c copy -c:v copy -an C:\CameraRecord\Zone_Acc_R2_33_John_Smith_CAM2.mp4

TIMEOUT /T 0 /NOBREAK
START ffmpeg -i "rtsp:/admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0" -t 5 -c copy -c:v copy -an C:\CameraRecord\Zone_Acc_R2_33_John_Smith_CAM3.mp4

echo.
echo All recordings completed!
echo.
pause
_______________________________

The TIMEOUT is the delay in seconds to start capturing from runtime of batch file. So in the example above, CAM1 and CAM3 should record immediately at run time, with CAM2 having a delay of 3 seconds before starting to record. However, CAM3 only starts at the same time as CAM2. If I add a delay to CAM3, the timing starts only after CAM2 starts recording instead of being based on the run time of the batch file.

Any ideas on how to fix this?
Thank you in advance!
 
Not that I've used Windows batch for decades - so I may be wrong, but -
The batch file is executing in strict sequence, and the timeout command pauses execution for the specified period.
So in the example above, cam1 would start at run time, and cam3 would start after the pause in execution for cam2 has completed.
cam1 and cam3 would not start immediately at run time as the commands are executed in strict sequence.

If I was doing this in Linux, I'd spawn individual processes for each ffmpeg instance, to operate concurrently with their own independent time delay, with the parent script not waiting for the child process to finish.
 
Not that I've used Windows batch for decades - so I may be wrong, but -
The batch file is executing in strict sequence, and the timeout command pauses execution for the specified period.
So in the example above, cam1 would start at run time, and cam3 would start after the pause in execution for cam2 has completed.
cam1 and cam3 would not start immediately at run time as the commands are executed in strict sequence.

If I was doing this in Linux, I'd spawn individual processes for each ffmpeg instance, to operate concurrently with their own independent time delay, with the parent script not waiting for the child process to finish.
Do you think I would be better off running a Linux VM to do this?
 
Presumably the main batch file can just spawn per-camera command files in a mode that does not await their completion before the main file continues execution. If that makes sense.
 
That's exactly what I am attempting to do.
OK, maybe you can work from this example -
The main.bat runs straight through with no waits, starting all 3 child programs running independently with their own timings.

main.bat
echo "Starting"
start program_1.bat

start program_2.bat

start program_3.bat
echo "Ending"
timeout /T 2

program_1.bat
timeout /T 10
echo "Program 1"
timeout /T 2
exit

program_2.bat
timeout /T 15
echo "Program 2"
timeout /T 2
exit

program_3.bat
timeout /T 20
echo "Program 3"
timeout /T 2
exit