8

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!

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.

| improve this answer | |
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
| improve this answer | |
  • 1
    Unfortunately, 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 May 11 '18 at 14:04
3

This command worked better for me:

gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video1
| improve this answer | |
  • I 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? – lewis4u Apr 6 at 6:58
  • Interestinly 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 -- – Jamie Hutber Apr 26 at 10:16
  • @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/… – Carl Berger Jun 19 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.