Can I use my DSLR as webcam through gphoto2 + v4l2loopback?
Solution 1
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.
Solution 2
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
-
decodebin2
has been replaced bydecodebin
-
ffmpegcolorspace
has been replaced byvideoconvert
- the
tee
filter has been added to account for a bug in the v4l2loopback driver (see: https://github.com/umlaeute/v4l2loopback/issues/83)
Solution 3
This command worked better for me:
gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video1
Related videos on Youtube
user2934303
Updated on September 18, 2022Comments
-
user2934303 over 1 year
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!
-
kelunik about 6 yearsUnfortunately, 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
. -
lewis4u about 4 yearsI made it work with this command you posted... but I have another problem, it seems to me like it doesn't do autofocus... the image is blury... maybe you have experience with this?
-
Jamie Hutber about 4 yearsInterestinly I get
[video4linux2,v4l2 @ 0x7392700] Unable to open V4L2 device '/dev/video2' Could not write header for output file #0 (incorrect codec parameters ?): No such file or directory Error initializing output stream 0:0 --
-
Carl Berger almost 4 years@JamieHutber, I had the same error just trying the command above (linux mint 19.2). The issue: apparently i didnt have the v4l2loopback installed.. The solution: so something along the lines "apt-get install v4l2loopback-dkms", then "sudo modprobe v4l2loopback" upfront did the trick. there's also a good explanation on askubuntu.com/questions/856460/…