0

I need some help reading video from a USB webcam.

I'm writing a Java application that streams video too authenticated users. This is working fine with the Pi camera as raspivid is able to output an h.264 stream to stdout. I'm able to read this in, stream it to the client and have them watch it with an h.264 video player. This is working 100% fine (even on a Pi Zero).

I'm looking to expand on this by supporting USB webcams as well. I purchased a webcam that advertises that it can output h.264, however I'm struggling to read from it.

All the example code that I found online reads still images from the webcam (raw) and then encodes it to an h.264 video. This encoding is quite CPU intensive and it's killing the Pi Zero that I intend to run this application on.

Any advice on how I can access the h.264 stream?

Output from gst-device-monitor-1.0

name  : web camera: UVC Camera
class : Video/Source
caps  : video/x-raw, format=(string)YUY2, width=(int)640, height=(int)360, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1;
        image/jpeg, width=(int)1920, height=(int)1080, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1;
        image/jpeg, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1;
        image/jpeg, width=(int)640, height=(int)360, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1;
        video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, width=(int)1920, height=(int)1080, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1;
        video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1;
        video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, width=(int)640, height=(int)360, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1;
properties:
    udev-probed = true
    device.bus_path = platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0
    sysfs.path = /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.1/1-1.1:1.0/video4linux/video0
    device.bus = usb
    device.subsystem = video4linux
    device.vendor.id = 23c5
    device.vendor.name = Xiongmai
    device.product.id = 1478
    device.product.name = "web\ camera:\ UVC\ Camera"
    device.serial = Xiongmai_web_camera_12345678
    device.capabilities = :capture:
    device.api = v4l2
    device.path = /dev/video0
    v4l2.device.driver = uvcvideo
    v4l2.device.card = "web\ camera:\ UVC\ Camera"
    v4l2.device.bus_info = usb-0000:01:00.0-1.1
    v4l2.device.version = 328787 (0x00050453)
    v4l2.device.capabilities = 2225078273 (0x84a00001)
    v4l2.device.device_caps = 69206017 (0x04200001)
gst-launch-1.0 v4l2src ! ...
9
  • use the h264 caps as advertised by the cam. For example gst-launch-1.0 v4l2src ! video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1 ! .... – Fl0v0 Apr 13 at 15:42
  • The command above does not work for me. The error message is erroneous pipeline: no element "video" – HuH Apr 13 at 15:56
  • Strange. A complete pipeline would be: gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1 ! videoconvert ! autovideosink – Fl0v0 Apr 13 at 20:41
  • Unfortunately that doesn't work either. In both cases I removed the brackets (string) as it was complaining. Running the code above failed with: erroneous pipeline: could not link v4l2src0 to videoconvert0, videoconvert0 can't handle caps video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1. Not sure if I'm missing a dependency? – HuH Apr 13 at 22:23
  • do you have a display? Maybe just try fakesink instead of autovideosink, to see if you at least get the stream out of the cam. – Fl0v0 Apr 14 at 9:10

Your Answer

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

Browse other questions tagged or ask your own question.