How do I configure vlc/ffplay/cheese (or other) to automatically cycle/rotate between my 3 webcams?

321 Views Asked by At

I have 3 webcams which register in Ubuntu 18.04 as /dev/video0, /dev/video1 and /dev/video2. All three show up fine in Cheese and ffplay (but not vlc for some reason... not important for this question).

What I want is to open a viewing window and have the image shift automatically from device 0 to device 1 to device 2 and back to 0 every X seconds without the window closing or resizing.

I think the ultimate solution will come from creating a fake video device (let's say /dev/video3), watching it with a program and using ffmpeg or other command-line scripts to change the stream of /dev/video3. (v4l2loopback seemed promising)

Unfortunately, I have spent a few hours on this and gotten nowhere. Any help would be appreciated.

1

There are 1 best solutions below

3
On

Assuming all 3 clips have the same properties, basic syntax is

ffplay -f lavfi -i movie=filename="/dev/video0":f=v4l2,setpts=PTS-STARTPTS[v1];movie=filename="/dev/video1":f=v4l2,setpts=PTS-STARTPTS[v2];movie=filename="/dev/video2":f=v4l2,setpts=PTS-STARTPTS[v3];[v2][v3]overlay=enable='between(mod(t,15),10,15)'[v23];[v1][v23]overlay=enable='between(mod(t,15),5,15)'

This will show 5 seconds of video0 followed by 5s of video1 followed by 5s of video2.

Edit by OP: Using this suggestion, I was able to get this working for 4 cameras.

ffplay -f lavfi "movie=/dev/video0:f=video4linux2, setpts=PTS-STARTPTS [zero];movie=/dev/video1:f=video4linux2, setpts=PTS-STARTPTS [one];movie=/dev/video2:f=video4linux2, setpts=PTS-STARTPTS [two];movie=/dev/video3:f=video4linux2, setpts=PTS-STARTPTS [three];[one][zero]overlay=enable='between(mod(t,20),5,10)'[conn1];[conn1][two]overlay=enable='between(mod(t,20),10,15)'[conn2];[conn2][three]overlay=enable='between(mod(t,20),15,20)'[out]"

It defines 4 camera inputs, then does 3 video segments. The first video segment takes cams 0 and 1 and overlays 1 on top of 0 (but only for seconds 5-10). The second segment overlays cam 2 on the stream of cams 0+1 (but only for seconds 10-15). The third segment overlays cam 3 on the combined stream of cams 0+1+2 (but only for seconds 15-20). Each stream is only shown during its "turn" in the loop (again, multiples of 0-5, 5-10, 10-15, 15-20), governed by the overlay commands and the between+modulus magic suggested by Gyan.