-1

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.

fivedogit
  • 8,374
  • 7
  • 34
  • 43

1 Answers1

1

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.

fivedogit
  • 8,374
  • 7
  • 34
  • 43
Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Thanks, but would you mind to decipher what this means? It doesn't work out of the box and without knowing what each part does, I can't even begin to fix it. I'm trying to read the lavfi docs, but it's pretty involved. Would appreciate your additional assistance. – fivedogit Jan 07 '19 at 16:09
  • I grok what your suggestion is supposed to do now after RTFM and experimenting. As written, it gives "invalid argument". After changing command to "ffmpeg" the error is now "Invalid outpad name 'v1'". It stays invalid regardless of what I name it. I'll keep working at it, but would welcome further input. – fivedogit Jan 07 '19 at 20:29
  • Share report file of your ffplay attempt after adding -report – Gyan Jan 08 '19 at 03:10