= USB Web Cams = The 825 Gen2 has support for UVC (USB Video Class) compatible web cameras. After plugging a Logitech USB webcam into the 825 from a terminal type **dmesg**. {{{ card825gen2:~$ dmesg ... [ 7653.802688] usb 1-1.4: new high-speed USB device number 4 using xhci-hcd [ 7654.211992] usb 1-1.4: Found UVC 1.00 device (046d:0825) [ 7654.324569] input: UVC Camera (046d:0825) as /devices/platform/soc@0/38200000.usb/xhci-hcd.0.auto/usb1/1-1/1-1.4/1-1.4:1.0/input/input7 [ 7654.325132] usbcore: registered new interface driver uvcvideo [ 7655.880687] usb 1-1.4: set resolution quirk: cval->res = 384 [ 7655.881370] usbcore: registered new interface driver snd-usb-audio }}} This shows the webcam was detected, "registered new interface driver uvcvideo". Many webcams currently are UVC (USB Video Class) compliant. The 825gen2 has support for this. Type **lsmod** to show loaded modules {{{ card825gen2:~$ lsmod Module Size Used by snd_usb_audio 294912 0 snd_hwdep 20480 1 snd_usb_audio snd_usbmidi_lib 36864 1 snd_usb_audio uvcvideo 106496 0 algif_hash 20480 1 algif_skcipher 20480 1 af_alg 32768 6 algif_hash,algif_skcipher cardmnbdm 24576 0 rpmsg_ctrl 16384 0 … }}} The **uvcvideo** module was loaded automatically when the camera was plugged in and detected. == Capture still image == From the terminal type the following command to capture a still image from the camera. {{{ card825gen2:~$ gst-launch-1.0 v4l2src device=/dev/video2 num-buffers=1 ! jpegenc ! filesink location=/tmp/test.jpg Setting pipeline to PAUSED ... Pipeline is live and does not need PREROLL ... Pipeline is PREROLLED ... Setting pipeline to PLAYING ... New clock: GstSystemClock Redistribute latency... Got EOS from element "pipeline0". Execution ended after 0:00:02.385972216 Setting pipeline to NULL ... Freeing pipeline ... }}} The file /tmp/test.jpg contains the image. To capture an image from an app a **system** call could be used to perform the above command line. However, it is better to use the gstreamer library within the code. An example function to capture an image follows: {{{ void WebCamCapture(const char* writePath) { char cmd[200]; GstElement* pipeline; GstBus* bus; GstMessage* msg; snprintf(cmd, sizeof(cmd), "v4l2src device=/dev/video2 num-buffers=1 ! jpegenc ! filesink location=%s", writePath); pipeline = gst_parse_launch(cmd, NULL); gst_element_set_state (pipeline, GST_STATE_PLAYING); /* Wait until error or EOS */ bus = gst_element_get_bus(pipeline); msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS)); if(msg != NULL) { gst_message_unref(msg); } gst_object_unref(bus); gst_element_set_state(pipeline, GST_STATE_NULL); gst_object_unref(pipeline); } }}} == Display Live Video == To display live video on the LCD display the following terminal command may be used: {{{ card825gen2:~$ gst-launch-1.0 v4l2src device=/dev/video2 ! autovideosink }}} Following is an example function to display live video for the specified number of seconds: {{{ void WebCamDisplayVideo(int seconds) { GstElement* pipeline; GstBus* bus; GstMessage* msg; const char* cmd = "v4l2src device=/dev/video2 ! autovideosink"; pipeline = gst_parse_launch(cmd, NULL); gst_element_set_state (pipeline, GST_STATE_PLAYING); /* Wait until error or EOS */ bus = gst_element_get_bus(pipeline); msg = gst_bus_timed_pop_filtered(bus, seconds * 1000 * GST_MSECOND, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS)); if(msg != NULL) { gst_message_unref(msg); } gst_object_unref(bus); gst_element_set_state(pipeline, GST_STATE_NULL); gst_object_unref(pipeline); } }}} == Capture Video == From the terminal the following command will capture a video until CTRL-C is pressed: {{{ gst-launch-1.0 v4l2src device=/dev/video2 ! jpegenc ! avimux ! filesink location=/tmp/test.avi -e }}} The **-e, --eos-on-shutdown** parameter is important for this example. When CTRL-C is pressed to end the capture this causes a proper shutdown so that the capture file is complete. Video capture will create large files. It is best to limit the time of any video captures.