Multimedia in GNU/Linux - Capturing
CAPTURING WITH VIDEO FOR LINUX (V4L).
The Video for Linux project develops drivers for analogue video capture hardware like TV-cards. Using these drivers you can watch and record TV programs and VHS tapes on your computer. Most capture cards have multiple inputs leaving you the choise which one to use. Most common video inputs are TV/FM in (RF), composite and s-video. Audio inputs should be 2 RCA ports for stereo sound.
Video for Linux has 2 main versions: v4l and v4l2. In this text we will be using v4l2 since it’s the latest and superior version. However when reffering to v4l2 we will use the abbreviation v4l.
In order to control the v4l driver we will use the v4l2-ctrl utility (/usr/bin/v4l2-ctrl). The v4l2-ctrl options will be discused along the article. The first options we will use are the ‘–*-video-input’ options. These options list, set and get the input port. Listing 1 shows the 3 options (the output for –list-video-inputs is wrapped with tree dots.
$ v4l2-ctrl --list-video-inputs ioctl: VIDIOC_ENUMINPUT Input : 0 Name : Tuner 1 ... Input : 1 Name : S-Video 1 ... Input : 2 Name : Composite 1 ... Input : 3 Name : S-Video 2 ... Input : 4 Name : Composite 2 ...
$ v4l2-ctrl --set-video-input=2 Video input set to 2 (Composite 1)
$ v4l2-ctrl --get-video-input Video input : 2 (Composite 1)
Tuner (TV and Radio).
In this article we will not use the TV/Radio port, nor the posibilities when watching TV.
Composite video is most commonly distributed over RCA ports and cables and therefore of lesser quality the newer connectors like s-video and scart. Composite video has tree components: 1 for luminance (brightness) and 2 for color information. The 2 color components are mixed together to create the chrominance (color) component. The first component by itself would output a monochrome picture. All components are transmitted on one wire.
The s-video standard is an extension of composite video. It separates the chrominance from the luminance by using different wires and thus leaving more bandwidth, hence more picture quality.
Note on s-video:
Most TV/VCR devices do not handle s-video correctly because the SCART specification (EURO-AV) does not implements ports for the s-video components, instead s-video over scart uses the RGB ports resulting that with some devices the image will be monochrome as only the luminance component is transmitted. If you need the quality of s-video, you will probably need to aquire an s-video device. JVC’s website is a good start.
In order to view the signal passed trough v4l we can use a commandline media player like mplayer. We just need to play the contents that v4l gets from the capture card, which usualy is mpeg-2 encoded. The content is a constant video stream, with, depending on the hardware, just a few seconds of delay because it is encoded on the fly.
The v4l devices are located in /dev/v4l but there should also be links inside the /dev directory. In the /dev/ directory there is also a direct link to the common video device named ‘video’. We will use this device to access the video stream.
$ ls /dev/v4l radio0 vbi0 video0 video24 video32
$ ls -al /dev |grep v4l lrwxrwxrwx 1 root root 10 Apr 17 13:10 radio -> v4l/radio0 lrwxrwxrwx 1 root root 10 Apr 17 13:10 radio0 -> v4l/radio0 drwxr-xr-x 2 root root 0 Apr 17 13:10 v4l lrwxrwxrwx 1 root root 8 Apr 17 13:10 vbi -> v4l/vbi0 lrwxrwxrwx 1 root root 8 Apr 17 13:10 vbi0 -> v4l/vbi0 lrwxrwxrwx 1 root root 10 Apr 17 13:10 video -> v4l/video0 lrwxrwxrwx 1 root root 10 Apr 17 13:10 video0 -> v4l/video0 lrwxrwxrwx 1 root root 11 Apr 17 13:10 video24 -> v4l/video24 lrwxrwxrwx 1 root root 11 Apr 17 13:10 video32 -> v4l/video32
$ mplayer -cache 8192 -ni /dev/video
This last command should play the video stream from the selected source in listing 1. Remember that there is a short delay (a few seconds). The video source should be started first. The v4l device will return a black (or blue, if the device is in standby position) screen until the picture is send trough. Making mplayer cache before it plays the stream is recommended, otherwise it might complain. The -ni option makes mplayer parse the stream as non-interleaved, which also clears some errors.
Now that we have selected the right video source we can start setting up the v4l sound and picture options.
CAPTURING WITH THE IEEE1394 ( FIREWIRE / ILink ) DRIVERS.
The ieee1394 project develops kernel modules (drivers) for firewire or i.Link harware (firewire and i.Link are the commercial names given to the ieee1394 protocol by Apple and Sony). There are no v4l devices for ieee1394, one can however use the v4l vloopback device but that is not within the scope of this text. In this text the video1394 module will be used instead.
The video1394 module uses a device named /dev/video1394, or /dev/video1394-0 where 0 indicates the current controller in use. (the module supports up to 4 different controllers or cards). The module may not be loaded by default, to check if it is loaded run ‘lsmod |grep video’ This should return (depending on which modules are loaded) something like:
$ lsmod |grep video video1394 18448 0 ohci1394 33608 2 video1394,dv1394 ieee1394 93144 4 video1394,dv1394,raw1394,ohci1394 videodev 27904 1 ivtv v4l2_common 18688 6 wm8775,cx25840,tuner,ivtv,cx2341x,videodev v4l1_compat 13956 2 ivtv,videodev
If the video1394 module is not listed, load it with modprobe, then run ‘lsmod |grep video’ again.
$ modprobe video1394 $ lsmod |grep video
Now check if the video1394 device is created properly with ‘ls /dev/*1394*’. This should return a list of ieee1394 devices similar to the next example depending on the ieee1394 modules that are loaded.
$ ls /dev/*1394* /dev/raw1394 /dev/dv1394 /dev/video1394-0
These devices are created following the conventions given in the udev ruleset (when running udev) or the devfs config file (when using devfs).
Further reading (and searching):
ENCODING MPEG-2 (DVD) WITH MENCODER.
DVD AUTHORING WITH DVDAUTHOR AND SPUMUX.