8

I am running motion on my raspberry pi using the V4L2 driver. While motion is running, I can't take a snapshot using raspistill. Is is possible to take a snapshot of the virtual V4L2 device using another tool while motion is running?

I guess /dev/video0 (created by V4L2) should be accessible by multiple clients? But which tool would I use to take a snapshot?

mpromonet
  • 1,124
  • 1
  • 19
  • 38
me.at.coding
  • 683
  • 1
  • 8
  • 11

1 Answers1

8

You should look to v4l2loopback in order to allow to open "twice" a V4L2 device.

1 - It will allow to create a virtual video device using :

sudo apt-get install v4l2loopback-dkms    
sudo modprobe v4l2loopback video_nr=10

This will add a new device /dev/video10

2 - Next you will need to copy the real device (/dev/video0) to the virtual one (/dev/video10) using ffmpeg or gstreamer.

  • using ffmpeg
sudo apt-get install ffmpeg
ffmpeg -f video4linux2 -i /dev/video0 -vcodec copy -f v4l2 /dev/video10
  • using gstreamer
sudo apt-get install gstreamer1.0-tools gstreamer1.0-plugins-good
gst-launch-1.0 v4l2src device=/dev/video0 ! v4l2sink device=/dev/video10
  • using v4l2tools (some of my tries with V4L2 programming)
git clone https://github.com/mpromonet/v4l2tools
sudo apt-get install liblog4cpp5-dev
make v4l2copy
./v4l2copy /dev/video0 /dev/video10

3 - Finally the v4l2loopback virtual device, that could be openned severals times,
could be used by motion and an other one to take snasphot (for instance using webcam or v4l2grab)

mpromonet
  • 1,124
  • 1
  • 19
  • 38