Can I use my DSLR as webcam through gphoto2 + v4l2loopback?

7

6

So, what i'm trying to do may be a little complicated, by i'm finding my way.

Let me explain the basics:

1 - I have an DSLR camera and i want to use it as webcam (but v4l2 can't make a /dev/videoX device with it, so no internet application can use it, only specific applications such as Darktable)

2 - I can get get live frames from the camera through gphoto2 (but i'm not sure about how to pipe them, and if i'm going to need to scale and encode/decode them)

3 - I can use v4l2loopback to create a fake webcam device (like /dev/video1) and i can use gst-launch to pipeline data to it (But i'm not sure how can i pipeline frames to it tough)

And what i know about it:

1 - I can send the frames from the camera to stdout like this:

gphoto2 --capture-movie --stdout

2 - I can send data from a video test source to the fake webcam device like this:

gst-launch-0.10 videotestsrc ! v4l2sink device=/dev/video1

3 - the format used by gphoto2 is mjpg (JPEG format)

So, can you help me with this?

How can i pipeline the frames from gphoto2 to gst-launch, and use it with v4l2sink to send them to /dev/video1 (so i'll be able to use it as a webcam)?

Thanks!

user2934303

Posted 2015-01-28T19:36:02.330

Reputation: 211

Answers

6

Turned out to be rather straightforward:

modprobe v4l2loopback

and then do this

gphoto2 --stdout --capture-movie | gst-launch-0.10 fdsrc ! decodebin2 name=dec ! queue ! ffmpegcolorspace ! v4l2sink device=/dev/video0

You should of course change the video device depending on your situation.

Reinaert Albrecht

Posted 2015-01-28T19:36:02.330

Reputation: 71

5

As of October 2017, GStreamer has been updated to 1.0 and v4l2loopback has also received some updates.

As such, the old command posted by @Reinaert Albrecht doesn't work anymore, and the new command that works now is

gphoto2 --stdout --capture-movie | gst-launch-1.0 fdsrc fd=0 ! decodebin name=dec ! queue ! videoconvert ! tee ! v4l2sink device=/dev/video0

Florian Segginger

Posted 2015-01-28T19:36:02.330

Reputation: 221

1Unfortunately, that fails with libv4l2: error getting pixformat: Invalid argument for me if I choose /dev/video1 instead of /dev/video0 and with more errors in case of /dev/video0. – kelunik – 2018-05-11T14:04:53.567

1

This command worked better for me:

gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video1

Vincent Maucorps

Posted 2015-01-28T19:36:02.330

Reputation: 11