Simultaneous synchonised launch

OK - so with my IP security cameras, they kept getting out of sync when launched via MPV and RTSP stream…

I wanted a shell script or some solution to launch BOTH at the EXACT same time… I don’t think cron would good for that (for a start - I’ve NEVER tried launching a GUI application from cron)…

Went hunting for solutions - they looked way too complex for something that should be simple… Gave up :

───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /home/x/bin/twincam88.bash
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ #!/usr/bin/env bash
   2   │ # fire up MPV @ VGA on BOTH TP-Link webcams
   3   │ SCRIPT=~/bin/wholycows.bash
   4   │ loopy_cnt () {
   5   │ for CAM in "1 2"
   6   │ do
   7   │     $SCRIPT $CAM 2 > /dev/null 2>&1 & disown
   8   │ done
   9   │ }
  10   │ $SCRIPT 1 2 > /dev/null 2>&1 & disown
  11   │ $SCRIPT 2 2 > /dev/null 2>&1 & disown
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

I don’t use that loop “loopy_cnt” - but I left it there in case I decide to try that method…
I just wish I could do BOTH those last two lines AT THE SAME TIME, instead of in that sequence, even if it less than 1 second delay…
But it kinda works…

2 Likes

The only way to do that in a serial computer is to make them one process.
Multitasking is a sham, it makes it look like 2 things are happening at once, but it is really sharing time slices.

2 Likes

@daniel.m.tripp Did you take a look at GNU Parallel?

GNU Parallel is a powerful tool that allows you to run commands in parallel, providing flexibility and control over the execution process.

3 Likes

I’d read about this a few years ago - interestingly - it didn’t come up in any google searches (maybe I should start using duck duck go)… Just installed it…

Could be the answer…

Parallel is not quite simultaneous, but it may be close.

Very close, if each job is running in separate cores.

OK - tried parallel - doesn’t seem much different from running two commands in a bash script…

And it launches the MPV sessions on my main display - not the display I’m running that terminal session in. With my shell script, it fires up the MPV windows on the same screen as the terminal session…

So - I think I’ll just use my shell script… if the cameras get several seconds out of sync, I’ll just kill the feed and run my shell script again…

Now I just gotta read up on launch options (geometry) for MPV i.e. which screen, co-ordinates and dimensions of each MPV window…

–geometry=1280x720 works fine…

Now I need some logic to decide the X/Y position of each window, so that the first camera is at 0,0, and second camera is at 1281,0

So - result :

╭─x@titan ~/bin  ‹main*› 
╰─➤  bat twincam96.bash 
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: twincam96.bash
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ #!/usr/bin/env bash
   2   │ # fire up MPV @ VGA on BOTH TP-Link webcams
   3   │ UZER="REDACTED"
   4   │ PSWD="REDACTED"
   5   │ CAM1=REDACTED
   6   │ CAM2=REDACTED
   7   │ STREAM=stream2
   8   │ # SCRIPT=~/bin/wholycows.bash
   9   │ # /usr/bin/mpv --geometry=1280x720 rtsp://$UZER:$PSWD@$CAM:554/live/$STREAM &
  10   │ # $SCRIPT 1 2 > /dev/null 2>&1 & disown
  11   │ # $SCRIPT 2 2 > /dev/null 2>&1 & disown
  12   │ /usr/bin/mpv --screen=1 --geometry=1280x720+0+0 rtsp://$UZER:$PSWD@$CAM1:554/live/$STREAM > /dev/null 2>&1 & disown
  13   │ /usr/bin/mpv --screen=1 --geometry=1280x720+1281+0 rtsp://$UZER:$PSWD@$CAM2:554/live/$STREAM > /dev/null 2>&1 & disown
  14   │ # /usr/bin/mpv --screen=1 --geometry=1280x720+1+1 rtsp://$UZER:$PSWD@$CAM1:554/live/$STREAM &
  15   │ # /usr/bin/mpv --screen=1 --geometry=1280x720+1281+1 rtsp://$UZER:$PSWD@$CAM2:554/live/$STREAM & 
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

And no matter what screen the terminal is running on from which I run the shell script - they go to screen 1 (default/main is “0”)

3 Likes