Lesson 10 : USB Cameras

Valkka has experimental support for H264 streaming USB Cameras. To see if your camera supports H264 streaming, use the following command:

v4l2-ctl --list-formats -d /dev/video2

Information about your cameras can be found also under this directory structure:

/sys/class/video4linux/

The only difference to handling IP cameras is that a different thread (USBDeviceThread) is used to stream the video.

Download lesson [here]

import time
from valkka.core import *
glthread        =OpenGLThread ("glthread")
gl_in_filter    =glthread.getFrameFilter()

avthread        =AVThread("avthread",gl_in_filter)
av_in_filter    =avthread.getFrameFilter()

USBDeviceThread reads and multiplexes all USB cameras

usbthread       =USBDeviceThread("usbthread")

Define the usb camera (/dev/video2) and where it is going to be streamed (to av_in_filter with slot number 1):

ctx = USBCameraConnectionContext("/dev/video2", 1, av_in_filter)
# The default resolution is 720p
# If you want to set the width and height yourself, uncomment the following line
# ctx.width  = 1920; ctx.height = 1080;

glthread.startCall()
avthread.startCall()
usbthread.startCall()

avthread.decodingOnCall()

window_id =glthread.createWindow()

glthread.newRenderGroupCall(window_id)

context_id=glthread.newRenderContextCall(1,window_id,0) # slot, render group, z

time.sleep(1)

usbthread.playCameraStreamCall(ctx);

Stream for a minute. Patience. At least the HD Pro Webcam C920 does not send keyframes too often ..

time.sleep(60)

usbthread.stopCameraStreamCall(ctx);

glthread.delRenderContextCall(context_id)
glthread.delRenderGroupCall(window_id)

avthread.decodingOffCall()

usbthread.stopCall()
avthread.stopCall()
glthread.stopCall()

print("bye")