uvc-gadget icon indicating copy to clipboard operation
uvc-gadget copied to clipboard

[IDEA][PI] Screen capture through UVC device

Open hkfuertes opened this issue 1 year ago • 3 comments

So I had an idea... what if we could send the screen through the UVC gadget. I have the PoC working, but I only get 1 FPS... If someone could point me in the right direction I ll be greatly gratefull.

#!/bin/bash

sudo modprobe v4l2loopback video_nr=100 exclusive_caps=1
ffmpeg -f x11grab -i :0.0+0,0 -vcodec mjpeg -pix_fmt yuv420p -f v4l2 /dev/video100 &
sleep 5
uvc-gadget -u /dev/video0 -v /dev/video100 -r 30 &

With this concept, the usb capture card wont be required. The pi could be connected to a pc via usb and get the image through vlc. Additionally with the ethernet gadget we could also use x2x to control de device...

hkfuertes avatar Dec 30 '23 18:12 hkfuertes

I'm pretty sure I've already seen that this fork has this idea implemented (well, the display side of things)

https://github.com/peterbay/uvc-gadget/blob/master/gadget-framebuffer.sh

kbingham avatar Dec 30 '23 21:12 kbingham

oh! thank you!! I managed to create the /dev/fb0 by changing values in config.txt, but I need the intermediate step... I guess that I need to startx on some display (I used xvfbor https://techoverflow.net/2019/02/23/how-to-run-x-server-using-xserver-xorg-video-dummy-driver-on-ubuntu/) so that X11/Xserver writes onto the same /dev/fb0 that uvc_gadget is reading from.... But I dont find the solution...

I'll keep digging. Also, Amazon should deliver me today some dummy hdmi plugs... maybe thats the issue....

hkfuertes avatar Dec 31 '23 13:12 hkfuertes

So, progress... If I run this, with the option in raspi-config of login to terminal:

echo "dtoverlay=dwc2,dr_mode=otg" | sudo tee -a /boot/firmware/config.txt
echo " modules-load=dwc2,libcomposite" | sudo tee -a /boot/cmdline.txt
git clone https://github.com/peterbay/uvc-gadget
cd uvc-gadget && make
sudo cp ./uvc-gadget /usr/bin/
sudo cp ./gadget-framebuffer.sh /usr/bin/uvcgfb
sudo chmod +x /usr/bin/uvcgfb
sudo cp uvcgfb.service /etc/systemd/system/
sudo systemctl enable uvcgfb.service
sudo apt install xserver-xorg-video-dummy

# Start X on dummy display
sudo startx -- -config dummy-1920x1080.conf
# Manually for now!
sudo uvc-gadget -f /dev/fb0 -u /dev/video0

https://github.com/hkfuertes/pi_uvc_screen_share/blob/main/dummy-1920x1080.conf https://github.com/hkfuertes/pi_uvc_screen_share/blob/main/uvcgfb.service

I get this: image

But I only get a black screen If I set it to autologin to desktop...

hahahaha maybe I write to much, but also, maybe its helpfull to someone else... but again if someone know and wants to point me in the right direction, I'll be greatly greateful :)

hkfuertes avatar Dec 31 '23 19:12 hkfuertes