CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" >

3. Accessing the Video Device

The following section applies to all connection types.

3.1. The Video Devices Node

The Linux kernel requires a virtual device node be created to access and control the device in question. It may have already been created for you at boot-up; ls -l /dev/video* (with an asterisk) or alternatively find /dev -name video* or even visual inspection of the /dev directory with your favorite file manager can give you an idea if the video devices exist. If so you can proceed to Section 3.2; if not you will need to create them manually.

An easy way to create them, if available with your Linux distribution, is use of the MAKEDEV script, which may be located in /dev or the usual places for storing executable commands (/bin,/sbin and so on). The manual page for MAKEDEV (man MAKEDEV) can guide you further, but be aware of the device-specific command options. If MAKEDEV doesn't work or doesn't exist, or you just prefer doing things the hard way, move on to the next paragraph.

A device can be created as a block (such as a drive), a fifo (file-in-file-out or pipe, as in xconsole) or a character device, which represents other hardware. Each device has a major and a minor number "coordinate" to tell the kernel what it is and where to access it. These numbers are not arbitrary. The major number 81 with minor number 0, 1, 2, and so on are by convention assigned to Video4linux devices, including TV tuner boards and webcams. In order to create the video device /dev/video0, use mknod at the command line:

   #  mknod /dev/video0 c 81 0

where c represents a character device.

You can use the following script, which I have borrowed from the kernel source (located in linux/Documentation/video4linux/bttv/MAKEDEV of the source tree):

   #!/bin/bash
   function makedev () {
	for dev in 0 1 2 3; do echo "/dev/$1$dev:
	char 81 $[ $2 + $dev ]" rm -f /dev/$1$dev
	mknod /dev/$1$dev c 81 $[ $2 + $dev ] chmod
	666 /dev/$1$dev
   	done

   	# symlink for default device
	rm -f /dev/$1 ln -s /dev/${1}0 /dev/$1
   	}

	# see http://roadrunner.swansea.uk.linux.org/v4lapi.shtml
	echo "*** new device names ***" makedev video
	0 makedev radio 64 makedev vtx 192 makedev vbi 224
	# "*** old device names (for compatibility only) ***"
	#makedev bttv 0 #makedev bttv-fm 64 #makedev bttv-vbi 224

Simply copy and paste the above into your favorite editing program, save it as MAKEDEV or whatever name you like, make it executable (i.e., chmod u+x MAKEDEV), and then execute it as root:

   #  ./MAKEDEV

3.2. Groups and Permissions

It is a good idea to be sure that your user account can access the device once all modules are loaded and device nodes created. The most security-conscious way to do that is to add access for a particular group. On my system, the members of the group 'video' are allowed to use the webcam, scanner and other photographic devices. The way to accomplish this is to first change the ownership of the devices in /dev like so (as root):

   #  chown root.video /dev/usb/video*

...where root.video are the owner and group the device will now belong to. Obviously, the specific command will vary by your system and the type of device. It is important that you change the ownership of the device node itself and not the symlink; symlinks' ownerships are affected only by changing the parent devices or files they point to.

To see if your user account is a member of the group in question, as root issue the following command: grep -e video /etc/group. You should see something like the following:

   video:x:44:

...where '44' is the group number. Since no members follow the last colon in the 'video' group, we can add them, let's say user 'jhs' with the command

   #  adduser jhs  video

After this, it's simply a matter of allowing read and write access for the user in question of the device like so:

   #  chmod g+rw /dev/v4l/video0

...where g+rw means add read and write access for group. See the documentation for chmod (man chmod or info chmod) for further info.