Wednesday, July 30, 2014

Capturing video from camera device under Linux

Uses the video4linux2 (or simply v4l2) input device to capture live input such as from a webcam.

To list the supported, connected capture devices you can use the v4l-ctl tool. This example shows two connected webcams: /dev/video0 and /dev/video1.

$ v4l2-ctl --list-devices

Acer Crystal Eye webcam (usb-0000:00:1a.7-1):
/dev/video0

PATHPARTNER 5MP-OV-1 CAMERA (usb-0000:00:1d.7-1):
/dev/video1

Adjusting camera functions

Brightness, zoom, focus, etc, can be adjusted with v4l2-ctl. Display all controls and their menus:

$ v4l2-ctl -L
                     brightness (int)    : min=-64 max=64 step=1 default=-20 value=20
                       contrast (int)    : min=0 max=95 step=1 default=0 value=0
                     saturation (int)    : min=0 max=128 step=1 default=60 value=60
                            hue (int)    : min=-40 max=40 step=1 default=-5 value=-5
   white_balance_component_auto (bool)   : default=1 value=1
    white_balance_red_component (int)    : min=1 max=500 step=1 default=100 value=100
   white_balance_blue_component (int)    : min=1 max=500 step=1 default=100 value=100
                          gamma (int)    : min=72 max=500 step=1 default=110 value=110
           power_line_frequency (menu)   : min=0 max=2 default=2 value=2
    0: Disabled
    1: 50 Hz
    2: 60 Hz
                      sharpness (int)    : min=0 max=7 step=1 default=2 value=2
         backlight_compensation (int)    : min=0 max=1 step=1 default=0 value=0


Then adjust the value:
v4l2-ctl -c

asvkarthick@asvkarthick:~$ v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
Index       : 0
Type        : Video Capture
Pixel Format: 'YUYV'
Name        : YUV 4:2:2 (YUYV)

asvkarthick@asvkarthick:~$ cat /dev/video
video0  video1
asvkarthick@asvkarthick:~$ v4l2-ctl --all
Driver Info (not using libv4l2):
Driver name   : uvcvideo
Card type     : Acer Crystal Eye webcam
Bus info      : usb-0000:00:1a.7-1
Driver version: 3.2.55
Capabilities  : 0x04000001
Video Capture
Streaming
Format Video Capture:
Width/Height  : 640/480
Pixel Format  : 'YUYV'
Field         : None
Bytes per Line: 1280
Size Image    : 614400
Colorspace    : SRGB
Crop Capability Video Capture:
Bounds      : Left 0, Top 0, Width 640, Height 480
Default     : Left 0, Top 0, Width 640, Height 480
Pixel Aspect: 1/1
Video input : 0 (Camera 1: ok)
Streaming Parameters Video Capture:
Capabilities     : timeperframe
Frames per second: 25.000 (25/1)
Read buffers     : 0

  avconv -f video4linux2 -i /dev/video0 video0.avi

Records the captured video frame into the file

1 comment:

Unknown said...

You want to achieve in Embedded System and Technologies .We are providing industrial training with 100% Job Opportunities in Core Industries. Sessions will be practical on software as well as hardware. We are providing on microcontrollers such as 8051, PIC, AVR, ARM7, ARM9, ARM11 and RTOS with 100% Placement Assistance

Contact : +91-9940426826 / 044-26209369.

Website : www.bestembeddedsystemtraininginchennai.com