4

A ffmpeg webcam capture is running in the background.

ffmpeg -f video4linux2 -s vga -i /dev/video0  capture.mp4    (1)

I am therefore unable to read it with ffplay since the device /dev/video0 is used:

ffplay -f video4linux2 -s vga -i /dev/video0                  (2)
[...]
/dev/video0: Device or resource busy

How to read the webcam with ffplay without stopping the background capture?

PS: The background capture command should not be modified. I am aware that this can be done by modifying the command (1) with fifo.

1 Answer 1

9

Do this:

sudo modprobe v4l2loopback devices=1

If you get similar error like modprobe: FATAL: Module v4l2loopback not found in directory /lib/modules/4.6.0-kali1-amd64, just install v4l2loopback-dkms first, e.g.:

sudo apt-get install v4l2loopback-dkms

Now run it first (Note that it can't run as background process by trailing &):

ffmpeg -f video4linux2  -i /dev/video0 -codec copy -f v4l2 /dev/video1

Without stop the process above, in other bash session(s), you should able to run your two commands, i.e. ffmpeg -f video4linux2 -s vga -i /dev/video1 capture.mp4 and ffplay -f video4linux2 -s vga -i /dev/video1 (change it to /dev/video1) at the same time..

If you set it to 2:

sudo modprobe v4l2loopback devices=2

Then you can do ffmpeg -f video4linux2 -i /dev/video0 -codec copy -f v4l2 /dev/video1 -codec copy -f v4l2 /dev/video2, which allow you to used both /dev/video1 and /dev/video2 in the same time.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .