steeley
Posts: 20
Joined: Fri Jun 22, 2012 3:00 pm

Re: Pi Zero + Camera Board = USB webcam gadget?

Tue Apr 28, 2020 11:14 am

thanks for the script,
Just some advice about the g_webcam driver in linux on pi4 it seems to be bugged.... Try to use uvc with configFS
this cannot run as the directory it does not exist

/sys/kernel/config/usb_gadget

is not there and cannot be created manually


UPDATE:
I did modprobe g_webcam and it makes the directory, but the script does not execute correctly and gets stuck.

what does it need to work?
TIA

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2421
Joined: Thu Jul 11, 2013 2:37 pm

Re: Pi Zero + Camera Board = USB webcam gadget?

Thu Apr 30, 2020 12:02 pm

ikester wrote:
Mon Apr 27, 2020 7:57 pm

Second question, why would the g_webcam driver work that differently, compared to the configfs one? When using the configfs approach I get stuck like steeley and longinus, and I don't even get the gradient video pattern. Knowing that g_webcam has been deprecated in favor of configfs, I would like to use the newer method if I can make it work.
ConfigFS is "the future" and offers far more flexibility in modifying USB descriptors for data formats and resolutions. It should map much better to sourcing video from any random v4l2 device rather than the narrow set that g_webcam offers.

The configFS interface changes significantly between kernel 4.19 and 5.4 (which is our next stable kernel, once the kinks have been worked out), so the associated webcam script(s) won't be compatible between revisions.

Getting a working UVC webcam gadget on 5.4 on a pi zero would be very useful.
Rockets are loud.
https://astro-pi.org

kbingham
Posts: 6
Joined: Wed Mar 06, 2019 11:20 am

Re: Pi Zero + Camera Board = USB webcam gadget?

Thu Apr 30, 2020 12:26 pm

Indeed, the two approaches are different - and the uvc-gadget had to be 'taught' about that, which is why I would recommend using the upstream version at http://git.ideasonboard.org/uvc-gadget.git over other versions.

We updated the uvc-gadget application to be able to interact with the configfs module, and I recall aiming to at least try to make sure the app would continue to work with the old g_webcam gadget, but we only focussed on the configfs route from that point so that would be the only real supportable path. YMMV and all that.

The 'script' referenced from my gist.github account in this thread is also in that upstream repository and has had updates too I believe, so that's possibly a better one to use.

I hope to play with this on the RPi4/0 sometime but I'm afraid current deadlines are preventing me from taking a look at the moment.

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2421
Joined: Thu Jul 11, 2013 2:37 pm

Re: Pi Zero + Camera Board = USB webcam gadget?

Thu Apr 30, 2020 1:06 pm

kbingham wrote:
Thu Apr 30, 2020 12:26 pm


I hope to play with this on the RPi4/0 sometime but I'm afraid current deadlines are preventing me from taking a look at the moment.
We have a v4l2 driver for the camera interface that provides h264-encoded frames. Ideally for Pi Zero UVC we'd need a zero-copy solution that forwarded both the untouched video data and inserted the frame PTS in the UVC header.

As a proof-of-concept, just getting frames out (even at 1fps/with memcpy's) would be worthwhile.

Can you give me some pointers as to what needs doing to configfs/uvc-gadget so I can hack around on it?
Rockets are loud.
https://astro-pi.org

ikester
Posts: 9
Joined: Sun Apr 26, 2020 3:08 am

Re: Pi Zero + Camera Board = USB webcam gadget?

Mon May 04, 2020 2:40 am

jdb wrote:
Thu Apr 30, 2020 12:02 pm
ConfigFS is "the future" and offers far more flexibility in modifying USB descriptors for data formats and resolutions. It should map much better to sourcing video from any random v4l2 device rather than the narrow set that g_webcam offers.

The configFS interface changes significantly between kernel 4.19 and 5.4 (which is our next stable kernel, once the kinks have been worked out), so the associated webcam script(s) won't be compatible between revisions.

Getting a working UVC webcam gadget on 5.4 on a pi zero would be very useful.
Thanks jdb. I got to the point where I'm able to configure a UVC gadget using the ConfigFS. But, in my case, I'm not looking to use v4l2 sources. I just want to be able to send synthetic frames as a quick test. For instance, a static Jpeg image, which I haven't been able to do.

The Pi Zero does show up on the host machine as a UVC device, but no video is received, even though running the exact same uvc-gadget binary I do get that gradient pattern shown above with the g_webcam approach. I tried capturing the USB traffic in both cases and using Wireshark to try to figure out the differences, but I haven't been able to grok the entire flow yet.

I also have not been able to create a composite device that functions as an Ethernet adapter and UVC. If I create both configs and functions (ECM [ethernet] and UVC) in ConfigFS, as soon as I bind the gadget, neither of them work. Creating an ECM device on its own works just fine and I'm able to communicate from the host machine to the Pi over the virtual ethernet device. Creating the UVC device partially works (as described above). But if both are created together, neither works (nothing is recognized on the host side). And there's nothing obvious to show in the log files.

Do you have any idea why that would be? Could it be a USB bandwidth reservation issue with both devices? Do you know of any driver or hardware limitation that would prevent those two devices working simultaneously?

treefella
Posts: 21
Joined: Thu Mar 24, 2016 11:59 pm

Re: Pi Zero + Camera Board = USB webcam gadget?

Thu May 07, 2020 12:39 am

I am looking for a similar config as @Ikester, I would like Ethernet and Webcam working at thesame time for a custom CM Board. I'm also interested in adding MIDI to that composite gadget if possible. I am looking to send along synthesized frames from an existing GL Engine, there is no wifi on my CM board so Ethernet is essential for me to able to debug.

I have been able to get g_webcam to send test lines to OBS/Skype with github.com/wlhe/uvc-gadget utility.

Also can't get anything from the configfs method, with either uvc-gadget repo suggested.

I was able to get a configfs script working with ACM/ECM alone but adding anything beyond that disables ECM functionality. I tried this with UVC and MIDI, adding either disables ECM. When using UVC + ECM + ACM + MIDI, ACM & MIDI does not start working until I start uvc-gadget.
Ron S
instagram.com/teafela/

User avatar
psergiu
Posts: 224
Joined: Mon Nov 07, 2011 8:36 am
Location: TX, U.S.A. (was: RO, E.U.)
Contact: Website

Re: Pi Zero + Camera Board = USB webcam gadget?

Fri May 08, 2020 2:46 pm

I tried on a Pi Zero running an up-to date Buster all combinations of "libcomposite" / "g_webcam", kernel 4.19 / 5.4 and the three available versions of "uvc-gadget" and no luck. While uvc-gadet is running, i can see a webcam over USB but no image is sent to the other side.

Curious to see if anyone ever gets-it to work AND can explain exactly what he did.

siggibartman
Posts: 3
Joined: Sat May 09, 2020 7:23 pm

Re: Pi Zero + Camera Board = USB webcam gadget?

Sat May 09, 2020 7:32 pm

Hi i tried this on with my Raspberry Pi zero and couldn´t get a video stream showing.
If i use one of the configs Scripts i get an i/o error. With the g_webcam method i can get the usb camera to show up on my computer but no video is transfered. I tried using the -d modifer and managed to get the test frames like other guys. Whats interesting is that if i use the -r 1(for resulution 720p) the videostream is no more black but white, so i don´t know if thats a good or a bad sign but i hope it will work in some time

Eluvio
Posts: 1
Joined: Mon May 11, 2020 8:37 am

Re: Pi Zero + Camera Board = USB webcam gadget?

Mon May 11, 2020 9:07 am

Hello!

Been hacking on this for the last two weeks or something, way too many hours spent on this, although I have learned a lot about C, video stuff & v4l2 :)

The furthest I have been able to do is using g_webcam & this fork https://github.com/jdonald/uvc-gadget, I was able to actually send video from my camera, however I was not able to use the bcm2835-v4l2 device directly, it did not work. However what worked was using v4l2loopback, and then use ffmpeg with the bcm2835-v4l2 device as input, and then v4l2loopback as output with yuyv422 as pixelformat & resizing the output to 640 x 360. However it was really laggy and a lot of delay, but at least I got video output.

I've also been trying the original repo (http://git.ideasonboard.org/uvc-gadget.git), the code is more updated, however the biggest problem (as far as I understand, sorry if I am wrong) with that version is that it is using DMABUF's to provide source buffers to the output. But the problem is that bcm2835-v4l2 is not implementing DMABUF's, and because of that, the ioctl call VIDIOC_EXPBUF (exporting dmabuf from a mmap buffer if I understand correctly) will error, and then it will not work. And v4l2loopback does not implement them either.

I tried to remove the DMABUF implementation of the original repo, but I completely misunderstood everything, so I created mmap buffers on both camera side & output side, and then I got basically a green screen output over USB, so I was really confused, and I used GDB to dump the buffer memory on both sides and used https://rawpixels.net/ to see what was the problem, and it turned out that the source buffer dump had a correct image of my room, and the output buffer just had 0's, and because of that it would output just a green color. So then I basically made a giant facepalm when I realized that the buffer content was completely separated from eachothers, and would not copy over.

So I tried to implement the USERPTR method from source to output, but has not been able to get it to work, a lot of errors related to the sizeimage not being identical for different buffers, and that's where I am now.

Honestly this task is way out of my league for a simple junior java engineer, and I have probably said a lot of incorrect things here, but I am determined to learn more and try to get this to work, so if anyone got any idea of how to go forward, then please let me know :)

kbingham
Posts: 6
Joined: Wed Mar 06, 2019 11:20 am

Re: Pi Zero + Camera Board = USB webcam gadget?

Mon May 11, 2020 12:09 pm

Eluvio wrote:
Mon May 11, 2020 9:07 am
Hello!

Been hacking on this for the last two weeks or something, way too many hours spent on this, although I have learned a lot about C, video stuff & v4l2 :)
Great! Learning is always a good thing.

Eluvio wrote:
Mon May 11, 2020 9:07 am
The furthest I have been able to do is using g_webcam & this fork https://github.com/jdonald/uvc-gadget, I was able to actually send video from my camera, however I was not able to use the bcm2835-v4l2 device directly, it did not work. However what worked was using v4l2loopback, and then use ffmpeg with the bcm2835-v4l2 device as input, and then v4l2loopback as output with yuyv422 as pixelformat & resizing the output to 640 x 360. However it was really laggy and a lot of delay, but at least I got video output.
V4L2loopback is not supported by the linux-media community so I get lost there I'm afraid. I would fear that it would add both latency and potentially copies in to the pipeline though, and it shouldn't be necessary... Still ... you managed to make progress with it - so that's something., but really the task that v4l2loopback is doing is essentially all the uvc-gadget application is trying to do. It needs to feed frames into the UVC gadget device.

Eluvio wrote:
Mon May 11, 2020 9:07 am
I've also been trying the original repo (http://git.ideasonboard.org/uvc-gadget.git), the code is more updated, however the biggest problem (as far as I understand, sorry if I am wrong) with that version is that it is using DMABUF's to provide source buffers to the output. But the problem is that bcm2835-v4l2 is not implementing DMABUF's, and because of that, the ioctl call VIDIOC_EXPBUF (exporting dmabuf from a mmap buffer if I understand correctly) will error, and then it will not work. And v4l2loopback does not implement them either.
I assume here you mean that you are using the bcm2835-camera driver? (I'm not sure otherwise what bcm2835-v4l2 would be? unless it's a driver name from a specific version of the raspberry pi tree?)

So - two options, add DMABUF support to the bcm2835-camera driver, or update uvc-gadget to process MMAP buffers ;-)

Eluvio wrote:
Mon May 11, 2020 9:07 am
I tried to remove the DMABUF implementation of the original repo, but I completely misunderstood everything, so I created mmap buffers on both camera side & output side, and then I got basically a green screen output over USB, so I was really confused, and I used GDB to dump the buffer memory on both sides and used https://rawpixels.net/ to see what was the problem, and it turned out that the source buffer dump had a correct image of my room, and the output buffer just had 0's, and because of that it would output just a green color. So then I basically made a giant facepalm when I realized that the buffer content was completely separated from eachothers, and would not copy over.

So I tried to implement the USERPTR method from source to output, but has not been able to get it to work, a lot of errors related to the sizeimage not being identical for different buffers, and that's where I am now.
The idea is to obtain a buffer from the camera device (I presume, unless you're talking about the m2m codec device?) and then pass that into the uvc-gadget video node so that the USB stack can transmit that upstream. It sounds like you have perhaps created two buffers (one where you captured the image into), and then another empty one which you ahve transmitted. So indeed, you need to make sure that the one you capture is the one that gets transmitted.
Eluvio wrote:
Mon May 11, 2020 9:07 am
Honestly this task is way out of my league for a simple junior java engineer, and I have probably said a lot of incorrect things here, but I am determined to learn more and try to get this to work, so if anyone got any idea of how to go forward, then please let me know :)
It sounds like you've made a really good attempt at understanding the problem, and indeed identifying the lack of DMABUF support in one of the drivers provides direction on what to implement next.
Either fix the DMABUF support in the drivers being used, or extend the uvc-gagdet application to support MMAP buffers (though I'm surprised to hear it doesn't already... but I haven't checked yet)

kbingham
Posts: 6
Joined: Wed Mar 06, 2019 11:20 am

Re: Pi Zero + Camera Board = USB webcam gadget?

Mon May 11, 2020 12:21 pm

jdb wrote:
Thu Apr 30, 2020 1:06 pm
kbingham wrote:
Thu Apr 30, 2020 12:26 pm

I hope to play with this on the RPi4/0 sometime but I'm afraid current deadlines are preventing me from taking a look at the moment.
We have a v4l2 driver for the camera interface that provides h264-encoded frames. Ideally for Pi Zero UVC we'd need a zero-copy solution that forwarded both the untouched video data and inserted the frame PTS in the UVC header.
Indeed, it sounds like from the recent posts that the V4L2 camera driver, which utilises the VC4 does not export DMABUFs, where our uvc-gadget app expects to use them. 6by9 can probably provide guidance to extend that if that's a path you guys want to take, otherwise the unicam+ISP path already supports that - but then you're going to be bringing in extra complexity with needing to use libcamera which complicates matters a little, so for the current topic I would stick to using the simple camera interface first.

I would hope to see some helpful libcamera integration with uvc-gadget in the future but it's not currently anything we're looking at. Essentially we would need to add libcamera support to the uvc-gadget application. A desirable goal all the same, but we haven't (yet?) got a customer requirement for it.
jdb wrote:
Thu Apr 30, 2020 1:06 pm
As a proof-of-concept, just getting frames out (even at 1fps/with memcpy's) would be worthwhile.

Can you give me some pointers as to what needs doing to configfs/uvc-gadget so I can hack around on it?
Without looking myself I can only currently guess from what people post. So I would first suggest:

- Add DMABUF export support to the bcm2835-camera driver as a first step and see if that lets the upstream uvc-gadget application take frames from the camera and send them back into the UVC gadget device.

You could also try to make changes in the uvc-gadget app to support mmap buffers, but then you still need to import them into the UVCgadget app and configure everything. I think the DMABUF interface might be simpler, but I won't know until it's tried.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9293
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Pi Zero + Camera Board = USB webcam gadget?

Mon May 11, 2020 12:27 pm

kbingham wrote:
Mon May 11, 2020 12:09 pm
Eluvio wrote:
Mon May 11, 2020 9:07 am
Honestly this task is way out of my league for a simple junior java engineer, and I have probably said a lot of incorrect things here, but I am determined to learn more and try to get this to work, so if anyone got any idea of how to go forward, then please let me know :)
It sounds like you've made a really good attempt at understanding the problem, and indeed identifying the lack of DMABUF support in one of the drivers provides direction on what to implement next.
Either fix the DMABUF support in the drivers being used, or extend the uvc-gagdet application to support MMAP buffers (though I'm surprised to hear it doesn't already... but I haven't checked yet)
I thought upstream had enabled DMABUFs for bcm2835-camera (the module name is bcm2835-v4l2 for some odd reason). I have memories of a patchset from Hans that enabled it for all drivers as it's done by videobuf2, so the driver itself doesn't really have to care.
...
Ah, it's newer than I remembered, and not applied - https://patchwork.linuxtv.org/patch/61782/
It is a one liner though

Code: Select all

> diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> index 1ef31a984741..fe7a8205bfd4 100644
> --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> @@ -1919,7 +1919,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
>                 q = &dev->capture.vb_vidq;
>                 memset(q, 0, sizeof(*q));
>                 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
> -               q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
> +               q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ | VB2_DMABUF;
>                 q->drv_priv = dev;
>                 q->buf_struct_size = sizeof(struct mmal_buffer);
>                 q->ops = &bm2835_mmal_video_qops;
> --
It is using vmalloc for backing storage, therefore it may not be compatible with the importer. That's the joy of dmabufs.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

kbingham
Posts: 6
Joined: Wed Mar 06, 2019 11:20 am

Re: Pi Zero + Camera Board = USB webcam gadget?

Mon May 11, 2020 12:49 pm

6by9 wrote:
Mon May 11, 2020 12:27 pm
I thought upstream had enabled DMABUFs for bcm2835-camera (the module name is bcm2835-v4l2 for some odd reason). I have memories of a patchset from Hans that enabled it for all drivers as it's done by videobuf2, so the driver itself doesn't really have to care.
...
Ah, it's newer than I remembered, and not applied - https://patchwork.linuxtv.org/patch/61782/
It is a one liner though

Code: Select all

> diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> index 1ef31a984741..fe7a8205bfd4 100644
> --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
> @@ -1919,7 +1919,7 @@ static int bcm2835_mmal_probe(struct platform_device *pdev)
>                 q = &dev->capture.vb_vidq;
>                 memset(q, 0, sizeof(*q));
>                 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
> -               q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
> +               q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ | VB2_DMABUF;
>                 q->drv_priv = dev;
>                 q->buf_struct_size = sizeof(struct mmal_buffer);
>                 q->ops = &bm2835_mmal_video_qops;
> --
It is using vmalloc for backing storage, therefore it may not be compatible with the importer. That's the joy of dmabufs.
I wondered if it was that easy ;-)

The importer should be fine, as I expect the uvc-device is likely going to be using the CPU to packetise the frame to send over USB all the same.

So - a oneline patch to try!

SoulMan
Posts: 2
Joined: Thu Apr 16, 2020 9:08 am

Re: Pi Zero + Camera Board = USB webcam gadget?

Mon May 11, 2020 9:25 pm

Hi all.. a short long summary of my adventure..We are all working from home and good webcams are either hard to find or overpriced nowadays so i decided it would be worth to explore the raspberry route..and so it begins..
I will try to answer some questions that arose here also..
First I got a working camera on a pi zero and pi 3a+ ! not perfect but at least a start..
I used https://github.com/wlhe/uvc-gadget and legacy g_webcam and am on 4.19.115 of the kernel/modules.

To answer some questions:
- the colored bars purple/green is because there is no actual source.. (due to -d)
-depending when g_webcam is loaded, by hand after boot or at cmdline.txt, the V4L /UVC device may be switched around, you need to use -u /-v options when starting uvc-gadget to correct this (you get errors like V4L2: /dev/video1 is no video capture device / UVC: /dev/video0 is no video output device)
-when you see a black image there is actually no stream arriving at the host (try to take a snapshot, you get a timeout)
- when you see a white image and are able to take a snapshot.... then streaming works but the brightness is simply way to high.. ( i think i even had to change defaults)
- g_webcam is very limited in resolutions /frame rates, so i had to made some additions here to add more resolution/framerate combinations
- i tried using uvc_config on pi zero, using script on https://gist.github.com/kbingham/c39c4c ... f5206e2f9f and enabling the line #modprobe libcomposite... this is still pending to get it to work.. i stopped when i got legacy g_webcam going ..with the latest remarks i will have another look at it

So how to get it to work :
- make sure to connect the pi using the USB port for gadget mode :) typical late night mistake...
- add modules-load=dwc2 in the cmdline.txt after rootwait
- in config.txt add dtoverlay=dwc2 (pi zero) or dtoverlay=dwc2,dr_mode=peripheral (pi 3a+)
- modprobe g_webcam (by hand method)
- start uvc gadget .. eg ./uvc-gadget -r1 -f0 -s2 (resolution 720p format V4L2_PIX_FMT_YUYV, check if your V4L /UVC device is correct)
if I use the format V4L2_PIX_FMT_YUYV in combination with r0 (360p) the image will be black and there will be no stream, vice versa f1 will not work with r1 !
so for 360p use ./uvc-gadget -r10-f1 -s2 (resolution 360p format V4L2_PIX_FMT_MJPEG)

Note that the first time your image may be all white..but as said that is a good sign.. lower your brightness.. and there you are !!!
if you switch to a resolution at the host not matching uvc-gadget resolution your screen will be black..

I still have the following issues..
- Windows does not seem to be happy with the/my current uvc info.. it will only allow me to use 360p..
- Ubuntu guvcview does allow me to use 720p, however framerate is only 4.4fps .. to be investigated still (both pi zero and 3a+ same issue)
- Ubunta guvcview 1080p won't work yet..

its late so forgive me (or correct me) if there are any mistakes here :)

good luck..

justinschuldt
Posts: 2
Joined: Tue May 12, 2020 6:38 am
Contact: Website Twitter

Re: Pi Zero + Camera Board = USB webcam gadget?

Tue May 12, 2020 7:41 am

psergiu wrote:
Fri May 08, 2020 2:46 pm
Curious to see if anyone ever gets-it to work AND can explain exactly what he did.

I was able to get this working via uvc-gadget/ConfigFS, kernel 4.19, with the webcam functional in Windows10 for Zoom and Hangouts.

Steps to reproduce.

tl;dr I used g.letourneur's UVC ConfigFS script from earlier in this thread, with wlhe's uvc-gadget app. I did not try the upstream uvc-gadget.

Video of the webcam connected to Windows 10, "Camera" app. :geek:

TODO:
  • The framerate is very slow.
  • Need to make it run on boot.
I'm not sure this is good enough to be usable currently, but if we could refine it, I would love to help get it out there for people to use.

Not sure if this is helpful for what you're working on @jdb/@kbingham?

siggibartman
Posts: 3
Joined: Sat May 09, 2020 7:23 pm

Re: Pi Zero + Camera Board = USB webcam gadget?

Tue May 12, 2020 10:36 am

How can i set the Brightness on my Pi Camera, i get a white working stream
Edit:
Got it working you have to edit the uvc-gadget.c file and rebuild the projekt.
I changed #define PU_BRIGHTNESS_DEFAULT_VAL 127 to #define PU_BRIGHTNESS_DEFAULT_VAL 55
Thanks you all for your help!

SoulMan
Posts: 2
Joined: Thu Apr 16, 2020 9:08 am

Re: Pi Zero + Camera Board = USB webcam gadget?

Tue May 12, 2020 1:35 pm

justinschuldt wrote:
Tue May 12, 2020 7:41 am
..
TODO:
  • The framerate is very slow.
  • Need to make it run on boot.
I'm not sure this is good enough to be usable currently, but if we could refine it, I would love to help get it out there for people to use.

Not sure if this is helpful for what you're working on @jdb/@kbingham?
Hey thanks for this post, i was able to use this and i have a working stream now using configFS.. somehow uvc_gadget "f" parameter behaviour seems different than in my earlier tests, I was able to get 720p now on pi0 with a good framerate (26.76 fps with a datarate of 7515kbps).. im using a 5MP OV5647 camera with auto IR. (i also use -s2 as parameter for uvc_gadget).

I also extended the configFS script with 1080p, however in windows there is no option to select a resolution/refresh rate -> do you also have this issue ?
switching to a 1080p only configFS does result in a working image with decent frame rate but a lot of pixelation..(26.20 fps with a datarate of 13959kbps).. need to check here.

justinschuldt
Posts: 2
Joined: Tue May 12, 2020 6:38 am
Contact: Website Twitter

Re: Pi Zero + Camera Board = USB webcam gadget?

Tue May 12, 2020 6:01 pm

SoulMan wrote:
Tue May 12, 2020 1:35 pm
I also extended the configFS script with 1080p, however in windows there is no option to select a resolution/refresh rate -> do you also have this issue ?
switching to a 1080p only configFS does result in a working image with decent frame rate but a lot of pixelation..(26.20 fps with a datarate of 13959kbps).. need to check here.

Same.

I can stream at 1080p but it seems there is a mismatch in refresh config. I played with the options, tried settings like this, it did not improve the apparent image quality.

I think future efforts would be best spent getting the upstream uvc-gadget to work?

720p is working and looks pretty good to me, this fills my needs for now. Still would like to get it to work automatically on boot. Would be nice to make it easier to use, maybe like a custom Debian image that is ready to go?

siggibartman
Posts: 3
Joined: Sat May 09, 2020 7:23 pm

Re: Pi Zero + Camera Board = USB webcam gadget?

Tue May 12, 2020 7:28 pm

justinschuldt wrote:
Tue May 12, 2020 6:01 pm
SoulMan wrote:
Tue May 12, 2020 1:35 pm
I also extended the configFS script with 1080p, however in windows there is no option to select a resolution/refresh rate -> do you also have this issue ?
switching to a 1080p only configFS does result in a working image with decent frame rate but a lot of pixelation..(26.20 fps with a datarate of 13959kbps).. need to check here.

Same.

I can stream at 1080p but it seems there is a mismatch in refresh config. I played with the options, tried settings like this, it did not improve the apparent image quality.

I think future efforts would be best spent getting the upstream uvc-gadget to work?

720p is working and looks pretty good to me, this fills my needs for now. Still would like to get it to work automatically on boot. Would be nice to make it easier to use, maybe like a custom Debian image that is ready to go?
I added the Lines

Code: Select all

sudo ./home/pi/uvc.sh
/home/pi/uvc-gadget/uvc-gadget -v /dev/video0 -u /dev/video1 -r 1 -f 1
inside /etc/rc.local

It works on boot but after some time it stops working

ikester
Posts: 9
Joined: Sun Apr 26, 2020 3:08 am

Re: Pi Zero + Camera Board = USB webcam gadget?

Tue May 12, 2020 10:14 pm

Great news from justinschuldt, siggibartman and SoulMan!

I still haven't had any luck on a Mac or getting a composite device to work (UVC and ETH).

In my case, I'm not trying to send video from an attached physical camera. My ultimate goal is still to create a virtual webcam device, that receives a video stream (via WiFi, ETH gadget) and feeds it through the UVC gadget as a "webcam".

dapetcu21
Posts: 1
Joined: Tue May 12, 2020 10:12 pm

Re: Pi Zero + Camera Board = USB webcam gadget?

Tue May 12, 2020 10:18 pm

Hi!

I seem to be stuck at trying to compile uvc-gadget.

I cloned https://github.com/wlhe/uvc-gadget, then installed kernel headers with

Code: Select all

sudo apt-get install raspberrypi-kernel-headers
then did

Code: Select all

cd uvc-gadget
make ARCH=arm KERNEL_DIR=/usr/src/linux-headers-4.19.97+
And I get

Code: Select all

/usr/src/linux-headers-4.19.97+/include/linux/mutex.h:14:10: fatal error: asm/current.h: No such file or directory
I even tried with a full kernel source tree and I still get the same error.

All of this is on the latest raspbian (buster 2020-02-13).

ergomacros
Posts: 2
Joined: Wed Mar 18, 2020 9:59 pm

Re: Pi Zero + Camera Board = USB webcam gadget?

Sun May 31, 2020 8:48 pm

Just saw this recent (April, 2020) article from: tomshardware
https://www.tomshardware.com/how-to/use ... -pc-webcam

Looks promising, though I have not tried it.

User avatar
thagrol
Posts: 3288
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi Zero + Camera Board = USB webcam gadget?

Sun May 31, 2020 11:24 pm

ergomacros wrote:
Sun May 31, 2020 8:48 pm
Just saw this recent (April, 2020) article from: tomshardware
https://www.tomshardware.com/how-to/use ... -pc-webcam

Looks promising, though I have not tried it.
While it might be functional it isn't the same thing.

That article has the Pi streaming it's camera over ethernet (or ethernet emulated over USB) then using a windows hack to pipe that stream into some video conferencing/calling software.

At no point does the Pi present itself to, or function as, a USB webcam.

Doesn't mean that aproach is invalid, just that it's off topic for this thread.
Arguing with strangers on the internet since 1993.

booboo
Posts: 1
Joined: Fri Jun 05, 2020 3:39 pm

Re: Pi Zero + Camera Board = USB webcam gadget?

Fri Jun 05, 2020 3:44 pm

Having read all the previous posts, I have to ask....

How did this good person make it work, as a plug-in gadget, and not as an IP camera?

https://www.youtube.com/watch?v=idD61VOJ024


Return to “Graphics, sound and multimedia”