pts' TV recording with video4linux tutorial ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ by pts@fazekas.hu at Sat Feb 12 20:01:28 CET 2005 -- Sun Feb 13 04:55:43 CET 2005 -- Mon Mar 21 01:54:18 CET 2005 This tutorial will help you installing everything so you can watch and record TV and FM radio programmes on your PC running Linux. The tutorial focuses on properly configuring the hardware drivers, because that's the trickiest and the otherwise least documented part of the process. xawtv will be used to watch TV, and mencoder will be used to record it. The latest plain text version of this tutorial can be downloaded from: http://www.inf.bme.hu/~pts/pts-tv-record-video4linux-tutorial.txt An outdated HTML-version version of the tutorial, courtesy of Andrew W. Robinson, was available at: http://www.inf.bme.hu/~pts/tvt.html Sorry, this has been lost in the last system crash. If you are Andrew W. Robinson, please send the file to me again! (The HTML version is provided as is. If in doubt, read the plain text version.) There are multiple ways you can watch and record TV on Linux, but this tutorial describes only one way: the one that workes safely for the author. The discovery of the other possibilites are left as an exercise to you, the reader. This tutorial is based on the small notes made by the author when investing considerable amount of work to try to set up his new `Leadtek Winfast TV2000 Expert' TV tuner card on Linux. (This happened in early February, 2005.) So parts of the tutorial may not be applicable in general (especially those parts dealing with the loading of the cx8800.ko kernel module). Other parts of the tutorial are only applicable to the PAL-BG TV norm (see ``TV norms in the world'' below). The tutorial is by no means finished (and will probably never will), but the author decided to publish it early, so other people will probably have less trouble setting up their TV tuner cards. TV norms in the world: -- NTSC (720x480 @ 29.97 fps) is used in the USA and in Japan -- PAL-I (720x576 @ 25 fps) is used in the UK -- SECAM (720x576 @ 25 fps) is used in France -- PAL-BG (720x576 @ 25 fps) is used in Hungary and many other European countries -- (there are some others, see the video4linux .c sources) To understand the whole tutorial, you are expected to have a lot of Linux experience. You should know your Linux distribution: locating, downloading, installing and uninstalling packages. You should be able to make changes to your Linux system boot sequence. You should be able to download, compile an install the kernel for yourself. You should be able to install X11 (XFree86 or Xorg) and set it up with proper hardware acceleration and video modes. You should be able to compile UNIX software from source (./configure; make; make install), and fix little things in configure scripts, Makefiles and C source files in case of problems during the installation. You should be able to identify, download and install dependencies of the software you're installing. You should notice if an action suggested in this tutorial imposes a potential danger to your system (use the tutorial at your own risk!). Why record on a PC? ~~~~~~~~~~~~~~~~~~~ If you can afford it, buy a video casette recorder (VCR) or a digital video recorder (DVR), possibly with HDD. Some advandtages of the PC (with Linux): -- you can precisely tune the filter and quality settings of the recording -- if you already have a PC, it's cheaper -- you can choose from a wide variety of video editing software -- you can transfer the generated AVIs easily -- you don't have to waste DVDs -- the VHS resolution and quality is much lower than of TV -- even the MPEG2 encoding of the DVD imposes some quality loss, so if you have a DVD recorder, be prepared you're starting to lose quality as soon as you press the Record button. If your DVD recorder supports the DV codec (for recording, not for connecting to the PC!), that's good, because the DV codec doesn't lose much quality. Disadvantages of the PC: -- hardware setup on Linux is hard, espacially if your TV tuner card is not supported properly -- you cannot start recording with a single button, you have to type several commands -- the PC boots up much slower Requirements ~~~~~~~~~~~~ Hardware requirements: -- a PC with a monitor. A resolution of 800x600 is just perfect, because PAL TV is 720x480 (at 25 frames per second), and NTSC TV is 720x480 (at 29.97 frames per second). Please note that upon playback the width of the video is scaled to 768 pixels, because the original video pixels aren't of quare shape. -- a sound card (can be integrated to the motherboard) with audio input supported by Linux, properly installed and working (e.g. you can hear .wav files with mplayer, .mp3 files with mplayer and mpg123) -- a TV tuner card properly installed and connected (see the documentation accompanying the card) Costs vary between $40..$150. Ask your friends or the shop attendant about TV reception quality. You have to be careful. If you buy a TV tuner card that is not supported by Linux, you're lost. So be prepared before buying. Download the latest video4linux snapshot from http://linux.bytesex.org/v4l2/ (e.g video4linux-20050210-124039.tar.gz), have a look at the files doc/CARDLIST.*, and also do `grep "[.]name " cx88-cards.c'. Also read everyhing in the doc/ directory. Have a look at cards offered by the shops available to you. Before buying, ask advide on the video4linux mailing list or from your friends. The 3 most important drivers are: bttv.ko, cx8800.ko and sa7134.ko. The bttv driver is very stable, and it supports the most cards, but unfortunately cards with the BT848 and BT878 chipset become rare nowadays, and cx88 (Connexant)-based cards begin to dominate. I have the following TV tuner cards: -- Lifeview FlyVideo 2000, PAL (works with default config of bttv.ko) -- Leadtek Winfast TV2000 Expert, (works with cx8800.ko card=5 tuner=38, but setting it up was especially tricky) This will be described in greater detail in this tutorial. lspci -v says: Conexant Winfast TV2000 XP, PCI ID is 107d:6611 -- Hauppauge WinTV PCI FM, PAL, PCI ID 8811::3401 (works with cx8800.ko card=1 tuner=38, setting it up was quite easy after setting up Leadtek Winfast TV2000 Expert. It also seems to work with tuner=5, with its own brightness values.) The most important factors when choosing the TV tuner: -- does video4linux support it? -- is the TV picture quality good? (e.g is the tuner chip shaded?) -- does it support stereo TV (SECAM for the PAL norm)? -- does it support (stereo) FM radio? -- price (price is not that much important, because if you make your choice based on price, and buy a cheap but unsupported or partially supported card, you may waste weeks (!) of your life setting it up or replacing it) -- Fast processor for video recording. Real-time MJPEG (or DivX or DV) encoding with mencoder needs a Celeron 1400MHz or faster. This includes MP3 sound encoding, too. -- 13GB of free hard disk space for per hour of recorded video if you use the DV codec, or 3.6GB of free hard disk space per hour if you use MJPEG. You will have total control over the bitrate later, but usually one records the programme with little compression (and thus high quality), cuts out the unnecessary parts, and then re-encodes the whole video with the final quality settings. TV broadcast quality depends on the station and time-based factors, so it is quite impossible to know the best filter and quality settings setup beforehand. So video recording is the most comfortable if you have a spare 120GB HDD as temporary storage. -- a fast hard-drive with UDMA-133 or similar. You can measure the hard drive speed with hdparm: $# hdparm -Tt /dev/hda root@icy/pts/0 /dev/hda: Timing cached reads: 3096 MB in 2.00 seconds = 1547.46 MB/sec Timing buffered disk reads: 170 MB in 3.01 seconds = 56.47 MB/sec If the buffered disk read speed is above 20 MB/sec, that's fine. If it's not, you may have to issue `hdparm -d1' (on each system boot) and try again, or you may have to buy a new hard disk, or you may have to buy a new motherboard. Don't do video recording with an old PC! Some useful definitions: -- Definition: a `programme' is a compact unit of radio or TV broadcast. It can be a movie, a documentary, news, a talk show or a music top 10 etc. Its length is usually between 1 minute and 4 hours. -- Definition: a `station' is is a radio or TV broadcast on a fixed frequency. A station usually has a logo (in the corner of the TV screen), a theme and an intended audience. Some of the programmes offered by the station repeat daily or weekly. A station is usually a company on its own, having its own management, staff and reporters. -- Definition: `frequency': a physical parameter onto which the TV or radio receiver can be tuned to receive a specific station. Multiple stations are broadcast at the same time, but a single tuner is capable to receive only one of them. A TV tuner card usually has only a single tuner. The typical value for an FM radio frequency is between 64 and 128 Mhz, and a typical TV frequency is between 128 and 1024 MHz. -- Definition: a `channel' is a name--frequency pair found in one of the standard frequency tables. The name usually consists of a letter and a number. For example, channel E6 has frequency 182.25MHz (in the europe-east freqency table). In most countries it is customary to have all stations broadcast on channels (not just random frequency values), and most TV sets have some channels preprogrammed by default. Usually there are more channels than stations, so some of the channels are not used, i.e. only noise can be received on their frequency instead of a station. The notion of `channel' and `station' is sometimes confused in xawtv (especially in its sources, for example `struct CHANNEL **channels;' is a list of _stations_ defined in ~/.xawtv; I've corrected this to `struct STATION **stations'), but this tutorial tries to use them in a consistent way. Original xawtv: if (cur_sendername; if (cur_channelname; if (cur_channelhas_radio = 1; +#if 0 /**** pts ****/ /* Dat: I have eeprom_data[6]==0x11 */ core->tuner_type = (eeprom_data[6] == 0x13) ? 43 : 38; +#endif printk(KERN_INFO "%s: Leadtek Winfast 2000XP Expert config: " "tuner=%d, eeprom[0]=0x%02x\n", core->name, core->tuner_type, eeprom_data[0]); + "tuner=%d, eeprom[0,6]=0x%02x,0x%02x\n", + core->name, core->tuner_type, eeprom_data[0], eeprom_data[6]); } Later I discovered that the driver tries hard to detect mono/stereo mode, and from time to time (once in about 10 seconds), I hear a loud white noise for about 0.25s. Thus I decided to force mono mode with this patch: --- cx88-tvaudio.c.orig 2005-02-13 22:29:14.874300608 +0100 +++ cx88-tvaudio.c 2005-02-12 23:41:16.000000000 +0100 @@ -667,7 +667,11 @@ { /* end of list */ }, }; +#if 0 /**** pts ****/ set_audio_start(core, 0x0004, EN_DMTRX_SUMDIFF | EN_A2_AUTO_STEREO); +#else + set_audio_start(core, 0x0004, EN_DMTRX_SUMDIFF | EN_A2_FORCE_MONO1); +#endif set_audio_registers(core, a2_common); switch (core->tvaudio) { case WW_A2_BG: Please note that the patch above effectively changes stereo TV (and video) to mono on the cx88-based cards. I don't think so that it also disables FM radio stereo, but I wasn't able to get stereo radio anyway (even if I knew and verified that FM frequencies 103.3 and 107.8 in Budapest are stereo). I didn't have any problems concerning stereo with my bttv-based card. Recompiling video4linux might take a long time. You can make this shorter by commenting out the `.PHONY: FORCE' line in /usr/src/linux/scripts/Makefile.build and then calling `touch /usr/src/linux/FORCE' for the 1st time and each time you want to recompile everything. From the source I already new that the tuner type should be 43 or 38. But please note that video4linux sometimes cannot detect the tuner type properly, so you may have to try all tuner types, being 55 at the moment. Later I've tried all tuner types, and found 38 the best (for example, scantv has found the most number of TV stations with tuner 38, and this tuner type provided the best video quality). Do make && make install (-> /lib/modules/2.6.*/v4l2/) -- You will need the following devices in /dev: crw-rw---- 1 root video 81, 64 Jan 1 1970 radio0 crw-rw---- 1 root video 81, 224 Jan 1 1970 vbi0 crw-rw---- 1 root video 81, 0 Jan 1 1970 video0 Create symlinks video -> video0 etc. (If you have devfs, you don't have to worry about these.) Insert all users to be allowed to watch TV to the `video' group (/etc/group, NIS or whatever). -- MPlayer and MEncoder. Don't forget to use the patch http://www.inf.bme.hu/~pts/pts-mplayer-v4l2-b.patch.gz If you don't need external MEncoder recording in xawtv, use this instead: http://www.inf.bme.hu/~pts/pts-mplayer-v4l2-a.patch.gz Here is how to apply the patch: wget -c http://www2.mplayerhq.hu/MPlayer/releases/MPlayer-1.0pre6a.tar.bz2 wget -c http://www.inf.bme.hu/~pts/pts-mplayer-v4l2-b.patch.gz tar xjvf MPlayer-1.0pre6a.tar.bz2 cd MPlayer-1.0pre6a.tar <../pts-mplayer-v4l2-b.patch.gz gzip -cd | patch -p0 You need at least the following ./configure options: `--enable-tv --enable-tv-v4l --enable-tv-v4l2'. To test that your compiled mplayer has video4linux support, run `mplayer tv:// -tv driver=v4l2'. A new window should appear, and the ``MPlayer was compiled without TV Interface support'' message should not appear on the terminal. Raw YUYV etc. frames generated by xawtv or streamer are just too big for MPlayer and MEncoder, and they recommend using the `-ni' option to force non-interleaved AVI parsing. However, this doesn't work when the AVI file arrives in a pipe, so MPlayer's limits have to be increased. Unfortunately, after a couple of seconds, MEncoder will fail (with some `buffer full, use -ni' message) anyway, so the general solution is not to have MEncoder read from a pipe. The instructions below for patching can be ignore ignored: If you're compiling MPlayer, add the following lines to the end of libmpdemux/demuxer.h, _before_ running `make': #undef MAX_PACK_BYTES #define MAX_PACK_BYTES 0x2000000 Then, before running `make', run `rm -f libmpdemux/libmpdemux.a'. If you already have a decent mplayer/mencoder, you don't have to recompile it: just run `mpatch.pl mplayer' and `mpatch.pl mencoder' to have the binary patched. The patcher program, mpatch.pl is shipped with tvplus.pl. It has been tested with MPlayer 1.0pre5 and 1.0pre6. (If you are using UPX, don't forget to unpack your binaries before patching them!) -- My patched xawtv (xawtv-pts). It should compile with: ./configure && make Before doing `make install'', please remove _all_ instances of xawtv from /usr before installing this one, because xawtv looks for .so plugins and other resource files in various dirs (use `strace -e open xawtv' to determine), and it should really not find those extra files from a different installation of xawtv. I personnally recommend _not_ installing xawtv-pts, but running it from its source directory: cd /.../xawtv-pts . devsetup # important, sets up env vars for local use xawtv # runs x11/xawtv, because `. devsetup' has modified $PATH Loading the appropriate kernel modules """""""""""""""""""""""""""""""""""""" First we have to make sure that old or original (stock kernel) modules are _not_ loaded, and we also have to unload any video4linux modules. The only reliable way the change the card or tuner type is to unload and reload all modules. I've prepared a shell script that unloads all modules: $# cat tvclean.sh #! /bin/bash -- set -e # vvv move away video4linux modules coming from the original kernel in favour # of the v4l2 modules cd /lib/modules/"`cat /proc/sys/kernel/osrelease`" ORS="`find v4l2/ -name '*.ko' | perl -pe 's@^.*/@@;$_="-o -name $_"'`" find kernel/drivers -name STRANGE $ORS | perl -ne 'chomp;$o=$_;s@^(.*)/@$1/kernel_@&&s@[.][^./]+@.not_ko@&&print "mv \x27$o\x27 \x27$_\x27\n"' | bash depmod -a # vvv unload all loaded v4l2 kernel modules LA=a; LB=b while [ "$LB" != "$LA" ]; do LB="$LA" find v4l2 -name '*.ko' | perl -pe ' s@^.*/@rmmod \x27@;s@[.]ko$@\x27 || true@' | bash find kernel/drivers/media/video -name '*.ko' | perl -pe ' s@^.*/(?:kernel_)?@rmmod \x27@;s@[.]\w+$@\x27 || true@' | bash LA="`wc -l /dev/null ( set -x modprobe -v evdev || true # Dat: remote control modprobe -v cx88xx $CARDO $TUNERO $EXTRAO modprobe -v cx8800 #video_debug=1 chmod 640 /dev/input/event* || true chmod 600 /dev/input/event0 || true chown root:video /dev/input/event* || true ) | tee tvmod.log dmesg -c >tvload.log cat tvmod.log | grep -Ev '/videodev[.]k?o *$' | grep /kernel/drivers/media/ && exit 22 echo "load OK, see tvmod.log and tvload.log" grep -E '\[card=|tuner: type set to|IR.remote' tvload.log v4lctl setnorm PAL-BG echo "all OK" (Be careful: if you give someone write access to /dev/input/event0, he will be able to disable your keyboard or completely reorganize the scancode--keycode relationship. The `chmod' and `chown' commands here provide a little security, but this should really be addressed in the devfs layer.) If you need bttv.ko or saa7137.ko, replace cx88xx above accordingly, and remove the line containing cx8800. For the first time you may want to to omit the card= and tuner= parameters, and examine what video4linux reports to be autodetected. The report is written to tvload.log. If the module fails to load or it fails to find the tuner, try the other two drivers also. If your card doesn't seem to be autodetected (nothing in tvload.log that is similar to product title found on the box you bought), or the tuner type is reported to be unknown, you may have to try all possibilites. Have a look at the video4linux source tree for the possibilities, especially doc/CARDLIST.*, and also do `grep "[.]name " cx88-cards.c'. cx88 detected my Winfast TV200 XP card (card=5) properly, and tuner type=38. scantv worked fine, but I had some serious color problems with xawtv, so I decided to try all tuner types by hand. Since I knew the frequency of my favourite TV stations (and the frequencies were reported by scantv anyway), I wrote my ~/.xawtv file: $ cat ~/.xawtv [global] freqtab = europe-east [defaults] norm = PAL-BG capture = overlay input = Television [mtv 1] freq = 175.25 key = 1 [m2] freq = 182.25 key = 2 [TV2] freq = 559.25 key = 3 [RTL KLUB] freq = 210.25 key = 4 [duna] freq = 189.25 key = 5 [Video] input = Composite1 key = 0 It is customary to use `channel =' instead of `freq =' (the correspondance is written to the stderr of scantv), but I prefer the hard-coded numerical values, because they have one less level of indirection, so one less thing can go wrong. With these options I ran `xawtv' (version 3.94, not 4.x), pressed the keys <0>, <1>, <2>, <3>, <4> and <5>, and I got a quick glance of the picture reception quality. (I had my VCR connected to the Composite1 input, it was playing a long movie, so I can also test <0>). With these Please note that xawtv reads ~/.xawtv upon startup only. So if you make changes, you have to exit xawtv and restart in order for the changes to take effect. You might have to wait up to 30s after starting watching TV before color gets right. At least this happens with my WinTV card. For the sake of completeness, I include here my ~/.xawtv (with most of the channels removed): [global] freqtab = europe-east grab_format = YUYV snap-pattern = %(base)-%(channel)-%(yyyy)%(mm)%(dd)-%(HH)%(MM)%(SS)%(-newfilecount).%(ext) snap-maxsize = snapnorm # snap-maxsize=norm # ^^^ Dat: snap_maxsize=norm not recommended, loses information # snap_maxsize = 768x576 # vvv Dat: without ratio = 0:0, we cannot have `-geometry 720x576' # ratio = 0:0 osd = always start_setstation = yes start_geometry = norm #start_geometry = 800x600 grab_flicker = no snap_from_grab = yes mov-fvideo-pattern = /mnt/tvrecordings/xawtvrec-%(channel)-%(yyyy)%(mm)%(dd)-%(HH)%(MM)%(SS)%(-newfilecount).avi mov-mencoder-fsavenames-pattern = xawtvrec-%(channel)-%(yyyy)%(mm)%(dd)-%(HH)%(MM)%(SS)%(-newfilecount).prv mov-record-geometry = snapnorm mov-fps = norm mov-rate = 44100 mov-blit = yes mov-driver = mencoder mov-video = yuyv mov-audio = mjpeg-pcm mencoder-mjpeg-pcm = -oac pcm -ovc lavc -lavcopts vcodec=mjpeg:vhq -vf-add pp=lb -vf-add denoise3d -vf-add harddup mencoder-divx-mp3 = -oac mp3lame -lameopts abr:br=112:q=0 -ovc lavc -lavcopts vcodec=mpeg4:vhq -vf-add pp=lb -vf-add denoise3d -vf-add harddup use_xv = yes use_gl = yes use_dga = yes jpeg-quality =75 # Dat: no reason to keep it low (such as 50), JPEG can be converted later sane_scrollbars = yes parallel = 1 # vvv Dat: the `-i -cR' is important here # vvv Dat: -cR for Winfast, -lR for WinTV aumix-cmd = aumix -c0 -l0 -m0 # Dat: used by tvplus.pl only mixer = /dev/mixer:line mixer-igain = 64 # Dat: used by tvplus.pl only #: remote_control += if ($H{action}eq'press'&&$H{keysym}eq'RED' ) { system qw(v4lctl setattr hue 100); return 1 } #: remote_control += if ($H{action}eq'press'&&$H{keysym}eq'GREEN') { system qw(v4lctl setattr hue 255); return 1 } #: remote_control += if ($H{action}eq'press'&&$H{keysym}eq'YELLOW') { print "Hello, Yellow!\n"; return 1 } #: remote_control += if ($H{action}eq'press'&&$H{keysym}eq'BLUE') { system qw(v4lctl setstation TV2); return 1 } [launch] foo = Ctrl+A, mtt [defaults] norm = PAL-BG # capture = overlay # Dat: fast be no instant etc., untested capture = grabdisplay input = Television bright = 128 contrast = 60 hue = 255 color = 230 [launch] foo = Ctrl+A, mtt [mtv 1] freq = 175.25 # Dat: also in the kitchen, seems to be cable tv; 049.75 doesn't work key = 1 # color = 230 # Dat: winfast color = 160 # bright = 128 # Dat: winfast bright = 160 # Dat: wintv old # bright = 105 # Dat: wintv PCI in-out # contrast = 70 # Dat: wintv contrast = 70 [m2] #channel = e6 freq = 182.25 key = 2 bright = 160 color = 190 contrast = 50 # Dat: max, for logo with Mézga #mixer-volume-delta = 200 How to use ~~~~~~~~~~ Listening to the radio """""""""""""""""""""" # Connect the FM antenna cable to the card 1st. aumix -i40 -c64 -cR -l0 -m0 -w64 -p64 radio -qf 95.3 # `radio -c /dev/radio0' might be necessary if /dev/radio is missing # Change the frequency value from 95.3 to something else. # # The radio utility has options to tune the stations automatically, but this # didn't work for me: it found many frequencies which were not stations at # all, and it also failed to found more than half of the stations. Recording radio to .wav, without listening to it """""""""""""""""""""""""""""""""""""""""""""""" # Connect the FM antenna cable to the card 1st. # Don't forget to connect the TV tuner card to your sound card (either with # a jack--short_cable--jack outside the PC or a four-pin cable inside the # PC. aumix -i40 -c0 -cR -l0 -m0 radio -qf 95.3 v4lctl volume mute off # it is good to start wavrp inside `screen' wavrp -s c -c 2 -d 16 -r 44100 -f foo.wav # ^^^ wait until recording ends, and press Ctrl- to abort # Dat: -c 1 doesn't work with wavr: we get a slowed-down recording (why??), # so if you want to record to mono .wav, you have to post-process it # Dat: any -r can be specified (e.g -r 12345), the recording will be correct # (at least in Linux 2.6.10) # Dat: to listen to the recorded .wav while recording: # aumix -c64; sleep 42; aumix -c0 # Dat: the recorded .wav can be played back with `wavp foo.wav' or # `mplayer foo.wav' Recording radio to .mp3, without listening to it """""""""""""""""""""""""""""""""""""""""""""""" # Connect the FM antenna and the sound card to the TV tuner card (see above). aumix -i40 -c0 -cR -l0 -m0 radio -qf 95.3 v4lctl volume mute off # it is good to start wavrp inside `screen' wavrp -s c -c 2 -d 16 -f - -r 44100 | lame --preset fm - foo.mp3 # ^^^ wait until recording ends, and press Ctrl- to abort Scanning for TV stations """""""""""""""""""""""" # Connect the TV antenna cable (75 Ohm coax) to the TV tuner card. # Make sure there is signal on the coax cable. If you have a TV nearby, # connect the coax cable to the TV first. scantv -n PAL-BG -f europe-east >xawtv.scan # Add the following lines to xawtv.scan, so you can switch to the composite # (video) input by pressing <0>. [Video] input = Composite1 key = 0 # !! .xawtv warp # If not all stations are found, try a different tuner type when loading # the video4linux modules. # Dat: the set of allowed options are disjoint in the [global] and # [defaults] section # Dat: there is no [default] section, this is just a typo in the xawtv.1 # man page # Dat: `norm = pal' is not valid, must be `norm = PAL-BG' # Dat: xawtv doesn't do automatic deinterlace Reading teletext (PAL systems) """""""""""""""""""""""""""""" # Actually you can read teletext before properly configuring the # picture quality of the TV stations! Once you have run scantv and created # ~/.xawtv, you can start reading teletext of all stations identified # by scantv (except for `???' and `no station', of course). # # alevt (AleVT Version 1.6.0) doesn't work; use mtt from xawtv 3.94 # (or xawtv 4). mtt also makes Hungarian accented characters perfect. # You can select the station from the Station menu of mtt. mtt and xawtv # can run parallel. If you change the station in xawtv, the change is # reflected immediately in mtt. # # Once you have a proper ~/.xawtv, add these lines to it, [launch] teletext = Ctrl+A, mtt # and press Ctrl- inside xawtv to start mtt, showing teletext of the current # station. Watching TV """"""""""" # First make sure that the audio cable is connected to your sound card. # vvv Set the TV audio volume (64 out ouf 100). $ aumix -c64 -i40 -cR # # Make sure that the stations are listed in ~/.xawtv (look above about # running scantv to generate ~/.xawtv). # # In some cases, the Xv X11 extension must be present, because with # `xawtv -noxv', the capture may get 1-pixel high horizontal stripes with # cx88-based cards. In some other cases, especially if the X server is running # with the stock nVidia driver (nvidia.o), xawtv crashes unless `xawtv -noxv' # is specified. # # You should watch TV with xawtv. On PAL systems, start it with: $ xawtv -geometry 768x576 # or on NTSC systems: $ xawtv -geometry 720x540 # If you use the xawtv-pts, put these into ~/.xawtv: [global] start-geometry = norm [defaults] norm = PAL-BG # Modify your norm accordingly. This way xawtv will use 720x540 on NTSC # systems, and 768x576 on all other systems including PAL. Please note that # both resolutions have an aspect ratio of 4:3. Also note that TV broadcast # data is 720x480 on NTSC systems and 720x576 on PAL systems -- but you # should watch them scaled with aspect ratio 4:3. # # If you're not using xawtv-pts, you can change the default size # by adding the xawtv.geometry: 768x576 # line to your ~/.Xresources (and making sure that `xrdb -merge # $HOME/.Xresources' is executed each time you start your X11 session -- # see ~/.Xsession and ~/.Xinitrc in the docs of your X11 implementation). # # Please note that on some cx88 cards (e.g WinTV) it might take a couple of # seconds (5--10?) to recognise colors properly. This time is needed after the # computer has booted up, but not after the kernel module has ben reloaded. # # xawtv doesn't do deinterlacing. # If the picture is not right (except for colors and small, acceptable # white noise), try a different tuner type when loading # the video4linux modules. But first make sure that you are using the # right TV norm (PAL-BG in Hungary, PAL-I in the UK, PAL-BG or PAL-DK in # rest of Europe, NTSC-M in the USA, NTSC-JP in Japan etc., ask your # friends or TV company for details about your country). # # The color balance parameters are: bright(ness), contrast, hue, color # (saturation). # For cx88 cards, the values should be in the range 0..255. You have to # take care of these yourself, because the initial values are sometimes # bad. The initial values for my Winfast TV2000 XP were: $ su tvload.sh [...] $ v4lctl list [...] $ bright | int | 127 | 0 | range is 0 => 255 $ contrast | int | 61 | 0 | range is 0 => 255 $ color | int | 229 | 0 | range is 0 => 255 $ hue | int | 255 | 0 | range is 0 => 255 # The column with all zeros should be ignored, and we can get the defaults # from the third column. Write these to .xawtv, so these values are # enforced each time you switch stations (but the values are _not_ # enforced if you just start .xawtv without switching stations). [defaults] bright = 127 contrast = 61 color = 229 hue = 255 # You can set these in the command line, too: $ v4lctl setattr bright 127 && v4lctl setattr contrast 61 && v4lctl setattr color 229 && v4lctl setattr hue 255 # The changes take effect immediately (so you will see the difference in an # already running xawtv, mplayer or mencoder). When you find the changes # acceptable, do a `v4lctl list', and add the printed values to # one of the stations in ~/.xawtv (don't change the [defaults] yet)! # # For me, colors were totally screwed up (only gray, purple and green) # before I set `hue = 255'. Typical values for my Winfast TV2000 XP card # were: `bright = 128', `contrast = 60', `hue = 255', `color = 200'. # Please note that the saturation value varied between `color = 160' and # `color = 230' depending on the TV station (and also partially on the # programme). (It is possible that two stations have the same channel(freq) in # ~/.xawtv, so you can prepare different color balance settings for the # same channel -- but be preprated that `start_setstation = yes' would force # the 1st one appearing in ~/.xawtv.) # With the Hauppauge WinTV PCI FM card I had to increase # brightness from 128 to 160 for most of my TV stations. # # There are a couple of other programs beyond xawtv with which you can # watch TV, but this tutorial doesn't write about them, because the most # stable one is xawtv (the latest 3.x), and its development is closely # related to video4linux, so it is the safest to use it during # the hardware and software setup phase. (Anyway, I find it quite user # friendly and customizable, so I continued using it after setting up # everything.) # # xawtv recognises the stations listed in ~/.xawtv on startup and `setstation' # and `setchannel' commands (but not on `setfreq'!), so it will automatically # adjust the color balance (hue etc.) using the station entry in ~/.xawtv # whenever a known station is tuned. To disable this upon startup, use [global] start-setstation = no # in ~/.xawtv. Please use the xawtv-pts to get a reliable channel # detection. # # To have proper control over the sound card mixer, use xawtv-pts and # specify [global] mixer = /dev/mixer:line mixer-igain = 64 aumix-cmd = aumix -c0 -l0 -m0 # Dat: optional # to use LineIn. Then you will be able to control the mixer in the `Options' # window, and xawtv will be careful to set up mixer settings before recording, # so the audio doesn't get muted accidentally. # xawtv-pts also supports per-station volume adjustments. Search # for `volume-delta' and `mixer-volume-delta' in this tutorial to find out # more. # Grabbing snapshots (single frame captures) in xawtv """"""""""""""""""""""""""""""""""""""""""""""""""" # My cx88-based cards didn't support video grabbing in the rgb24 and bgr32 # (and similar) formats. But xawtv-pts has the [global] option # grab-format to correct this. I figured out setting it to YUYV, i.e having [global] grab_format = YUYV # in ~/.xawtv solves all grabbing (key in xawtv) and snapshot ( and # ) problems. (That root of the problems is 768x576 rgb24 is just too much # data, so horizontal stripes will appear.) # !! fix color problems/difference with this # # Please note that xawtv 3.94 has problems with all grab_format=RGB1?_?? # with the Winfast and WinTV card: the whole grabbed image becomes black. # # If you are using the unpatched xawtv, these limitations apply: # Sorry, pressing in # xawtv generates a bad-quality PPM snapshot with cx88 cards: some # 1-pixel high horizontal stripe noise is added to the output. This may be # due to the rgb24 color space being used. Pressing in xawtv freezes # the current frame (the audio keeps playing), but this uses the rgb32 # color space for me, so the captured frame is totally ugly. For JPEG # snapshots (with ) the situation is the same as with PPM snapshots. # # You can make a snapshot (of good quality) by running # `streamer -s 720x576 -o t.ppm' -- too bad you have to exit xawtv first, # and by that time the frame you wanted to save is already gone. # # Pressing worked for me with my FlyVideo card (bttv driver). Recording TV (mainly with mencoder) """"""""""""""""""""""""""""""""""" # xawtv comes with built-in recording capabilities (press to get the # window from which you can start recording). Some recording parameters can be # set with the `xawtv-remote movie ...', too. The standalone streamer(1) # utility (part of xawtv) and xawtv itself use the same set of codecs (audio # and video compression filters), file formats and # recording subsystem. The most important benefit of recording from within # xawtv is that you can watch the movie while it is being recorded. (And, # when watching, you can see the exact point when to stop recording.) Recording # from within xawtv will be discussed later in the tutorial. # # Using xawtv or streamer for recording is _not_ recommended, however, # because sometimes recording crashes xawtv, or or the audio-video will be # out of sync. (Try to do a 5-minute recording with xawtv, and if it works # OK, without out-of-sync and too many dropped frames, buffer overflows etc., # then you're lucky.) The # choice of filters and codecs is also very limited. The implementation of the # only useful compression codecs (JPEG and MJPEG) are too slow compared to # libavcodec (used by mencoder). # # This tutorial will describe later how to use the patched xawtv-pts to view # the movie while it is being recorded by mencoder. # # You should have mplayer and mencoder installed (both being part the # MPlayer package). The purpose of running mplayer first is to check # visually that the proper station with the proper settings will be # recorded. After everything is set up perfect, you can substitute mplayer by # mencoder in the command line (and add target options, see later), and the # recording will begin. # # After selecting the correct station and exiting from # xawtv, you can immediately start watching TV (but you shouldn't) with $ mplayer tv:// -tv driver=v4l2:width=768:height=576:outfmt=yuy2 -vf pp=lb # Don't worry if the colors are wrong here or you don't hear the audio -- these # will be resolved shortly. # # It is highly recommened that you use a patched mplayer/mencoder (see # in section `Installation'), because the patch fixes several video capture # problems. On some cx88-based cards, mplayer just resets the color balance # incorrect values before playback, which may make the whole video completely # red etc. It is also important to unmute the audio before starting mplayer. # All of these are done automatically in tvplus.pl (and also some other magic), # so it is recommended # that you don't call mplayer or mencoder directly, but use tvplus.pl instead. # tvplus.pl reads your ~/.xawtv, so it knows about your station, color balance # and sound settings. # # For audio recording it is important that the (1) audio is not muted by the # TV tuner card, (2) audio is not muted by the sound card, (3) the recorder # program is saving the audio. All of these are automatically ensured by # tvplus.pl if ~/.xawtv is written properly. # # First make sure that you have a proper `mixer' setting in ~/.xawtv: [global] mixer = /dev/mixer:line # You should change `line' to `cd' or `mic' if the TV tuner card is connected # to a different plug of the sound card. tvplus.pl also understands the # `aumix_cmd' and `mixer-igain' options: [global] aumix-cmd = aumix -c0 -l0 -m0 # Dat: default mixer-igain = 64 # Dat: default # With mixer-igain set to zero, the audio recording will be muted by the # sound card. Although `mixer-igain = 1' is also audible, `mixer-igan = 64' # is a little bit louder. # # tvplus.pl calls aumix before recording so the sound card won't mute the # audio. tvplus.pl also runs `v4lctl volume mute off' so the TV tuner card # won't mute the audio. tvplus.pl also sets up the proper mplayer/mencoder # options (e.g `-tv immediatemode=0:forceaudio') so the audio will be recorded. # # After all these preparations, the recommended way for watching TV with # mplayer is calling $ tvplus.pl mplayer tv://MyStation # where `MyStation' should be substituted by TV station name (section title # in ~/.xawtv). The call above generates and runs the following commands: $ aumix -c0 -l0 -m0 -d/dev/mixer -i64 -lR $ v4lctl volume mute off $ mplayer 'tv://' -tv 'driver=v4l2:input=0:width=768:height=576:\ outfmt=yuy2:immediatemode=0:forceaudio:brightness=63:contrast=24:\ hue=100:saturation=71:freq=559.25:norm=PAL-BG' -aspect '4:3' \ -vf-add 'pp=lb' -geometry 768x576 # You don't want to type all this by hand, do you? # Please note that hue=100 above is equivalent to `hue = 255' in ~/.xawtv, # etc. # # If you are not using tvplus.pl, be careful, because # the unpatched mplayer has some problems handling `-tv outfmt='. # For example, the defult outfmt=yv12 is buggy in cx88 (only the top half of # the screen is drawn and not in proper vertical order), so the use of # =yuy2 (or =i420 etc., see `mplayer -tv outfmt=help') is recommended. # The following outfmt={}s # didn't work for me with MPlayer 1.0pre5try2-3.3.4: =yv12 (default, # unfortunately) =rgb32 =rgb16 =rgb15 =y800 =bgr32 =rgb24 (good on WinTV, bad # on Winfast??). Please note that MPlayer falls back to an undefined outfmt= # if the TV tuner card doesn't support the outfmt= specified. # Note that YUYV == YUY2. # # See more about sampling formats at # http://www.fourcc.org/yuv.php # For converting between RGB and YUV (== YCbCr), see # http://www.fourcc.org/fccyvrgb.php # # If you have sound card compatible with i810_audio.ko, it might start # recording with 43567 samples per second (or something strange). This happens # with the 2.6.10 kernel, but not with 2.4. The correct rates for such cards # are 8000, 11025, 22050 and 44100. The card supports only these rates, even # if it reports 43567 or something similar. I think this is a bug in # linux-2.6.10:sound/oss/i810_audio.c:i810_configure_clocking(). If you get i810_audio: setting clocking to 48587 # or something similar in dmesg(8), # load i810_audio.ko with `clocking=48000' to enforce the original rate: $# rmmod -f ac97; rmmod -f i810_audio; modprobe i810_audio clocking=48000 # (Please note that the ratio is 48587/48000 == 44100/43567). # If you don't do this, recording with streamer will duplicate frames, and # thus will make timing in the generated AVI incorrect. # Specifying the `-srate 44100' mplayer option instead of clocking=... won't # solve the problem despite the fact that mplayer reports 44100 on the console. # # The TV broadcast needs deinterlacing, which is done by the `-vf pp=lb' # mplayer option. This is automatically included in tvplus.pl unless # the option `--interlaced' is specified. You might want to add the # `-vf il=s' mplayer option if your interlaced fields are swapped. (However, # this doesn't help some Hungarian broadcast, where only the TV station logo # is interlaced properly, but the image itself should be shifted by 1 line # before swapping fields.) # # If you don't use tvplus.pl, you should be aware that # mplayer resets all of the color balance settings. # # Now it is time to start the recording. First make sure that no processes # are running which use a lot of system resources. Exit from your web # browser and graphical e-mail client. Stop atd, crond, anacrond, lpd, # apache, smbd, ftpd and all other daemons that might make the system load # high during the recording. For example, if someone connects to the ftpd # and starts downloading files at high speed, that might produce a huge # system load, mencoder will report `video buffer full -- dropping frame', # and you'll have problems with your recorded AVI. To avoid this, stop as # many daemons as possible # # Now run this: $ tvplus.pl mencoder --mjpeg-pcm -o t.avi -frames 250 tv://MyStation # The --mjpeg-pcm is a shorthand defined in tvplus.pl. Without it, the # command line would be: $ tvplus.pl mencoder \ -srate 44100 -oac pcm -ovc lavc -lavcopts vcodec=mjpeg:vhq \ -o t.avi -frames 250 tv://MyStation -vf-add pp=lb -vf-add denioise3d # , which runs the following commands: $ aumix -c0 -l0 -m0 -d/dev/mixer -i64 -lR $ v4lctl volume mute off $ mencoder 'tv://' -tv 'driver=v4l2:input=0:width=720:height=576:\ outfmt=yuy2:immediatemode=0:forceaudio:brightness=63:contrast=24:\ hue=100:saturation=71:freq=559.25:norm=PAL-BG' -srate 44100 \ -oac pcm -ovc lavc -lavcopts 'vcodec=mjpeg:vhq:aspect=4/3' \ -aspect '4:3' -vf-add 'pp=lb' -vf-add denoise3d -frames 250 \ -vf-add harddup -o t.avi # The length of the resulting file is 250 frames, which equals 10 seconds # in the PAL norm, and about 250/29.97 (~ 8.34) seconds in the NTSC norm. # # Note: don't change the system clock (with hwclock, rdate etc.) while # recording, because it seriously affects MEncoder's internal timings. # # The resulting AVI files can be played (and edited) with the lavplay # utility of mjpegtools (`-vf-add harddup' is needed for that). # After recording, you can run mencoder on t.avi to further transform it. # The possibilities are endless. # # You can use `--dv-raw' instead of `--mjpeg-pcm' to generate a dvvideo # stream. First you have to compile the dvavi0 utility from dvavi0.c # (shipped with tvplus.pl). The file generated by `--dv-raw' is not an AVI, # so its extension should be `.dv'. The famous movie editing software, Kino # (http://kino.schirmacher.de/) can open and cut .dv files. # Example for DV recording: $ tvplus.pl mencoder --interlaced --dv-raw tv://MyStation -vf il=s -o u.dv # I don't recommend DV recording, because it adds perceptible additional noise, # and sometimes also a 1-pixel vertical shake to the material (much more than # MJPEG). Could someone please explain why? # # Cutting MJPEG # movies with mencoder is possible but a little inconvenient. For example, # the following command keeps frames 500..699: $ mencoder in.avi -o out.avi -ss 20 -frames 200 -oac copy -ovc copy \ -vf harddup # # The following steps are recommended for starting recording: # # -- start preparations at least 2 minutes before starting recording # -- load the appropriate kernel modules (with tvload.sh) # -- run xawtv to find the station/channel/frequency; also verify color balance # -- stop all unncecessary daemons and processes # -- make enough free disk space # -- add the station to ~/.xawtv if not already there # -- run `tvplus.pl mplayer' for a few seconds to get a preview. # You should definitely use an automated tool (like tvplus.pl), because it # eliminates the human error risk in copying and transforming ~/.xawtv # settings to command-line recording options. Always use mplayer (and not # xawtv!) to check what your recording will look like before starting it. # -- run `tvplus.pl mencoder' with the appropriate options for 10 seconds, # and play it back with mplayer (`mplayer t.avi') to ensure that your # recording settings are OK. # Kovács János has reported that some versions of MEncoder cannot record # unless they are started from X11 (i.e DISPLAY is set properly). Starting # from screen(1) under X11 is OK. # -- start `tvplus.pl mencoder' with the appropriate options as long as needed # -- make some more disk space free if needed # -- if needed, start watching the movie (with `mplayer t.avi') before # it finishes recording. If you want to seek (fast forward) in it, do # `mplayer -idx t.avi', but this would read the whole file from disk first, # thus using too many disk resources, so a frame drop might happen in # mencoder -- so you'd better not try to seek in an AVI file being recorded. # # Running mencoder for about 45 minutes was quite impressive for me: v4l2: 67017 frames successfully processed, 21 frames dropped. # The audio and the video were completely in sync. # # Start long recordings inside GNU screen(1), so they continue running # after you log out. Use at(1) or cron(8) to make scheduled recordings. # Develop a small framework for yourself or look for Linux-based VCR # projects on the web. # # Specify `-frames 90000' to have a one-hour recording (with 25 frames per # second -- PAL). If you don't specify it, recording will be infinite, but # you can abort mplayer safely any time by pressing Ctrl-. # # Recording with streamer (or xawtv) yielded v4l2: waiting for a free buffer rate: queueing frame twice (3) rate: queueing frame twice (3) rate: queueing frame twice (2) rate: queueing frame twice (3) rate: queueing frame twice (3) rate: queueing frame twice (3) rate: queueing frame twice (3) rate: queueing frame twice (3) rate: queueing frame twice (3) rate: queueing frame twice (2) rate: queueing frame twice (3) rate: queueing frame twice (2) rate: queueing frame twice (3) rate: queueing frame twice (3) rate: queueing frame twice (3) rate: queueing frame twice (3) # so it is constantly dropping frames and CPU load is 83% on a Celeron # 2400Mhz. That's why I switched to mencoder instead. It also had an a/v # sync difference of 0.33% (1.20s in 4 minutes), which later went down to # about 0.18s, but 1.20s is just too high. I was also unable to specify # aspect ratio (4:3). Decreasing the video size doesn't work either. And the # audio is more and more ahead of the video, they are not in sync. And I # tried to encode a 440x432 AVI, and it became 432x432 (because 440 is # not divisible by 16??) Reducing the resolution to 360x288 and the frame # rate to 12fps doesn't help either. # It is strange that after about 6 minutes a/v goes back to almost 0, then # it starts increasing (up to 1.8s) again. At 11:30 it became zero (+0.01s) # again, but then it started increasing. With the low-res setup, it # was +11.83s at 16:00. At 24:51 it was +18.58. # # The advantage of xawtv recording would be that it is possible to watch the # same TV station (sometimes only in reduced quality) while recording (its # work only for `15 bit TrueColor' and `MJPEG (AVI)'). However, I get the # `queing frame twice' message even if I am not coding. # # Another problem with streamer|xawtv recording: MJPEG doesn't work by # default, only `JPEG'. This is fixed in xawtv-pts. # # You can use $ tvplus.pl mplayer --which-mono tv://MyStation' to detect # whether you have one of the audio channels muted. If so, tvplus.pl will # recommend a line to ~/.xawtv (into the section [MyStation]) that would copy # copy this channel to the other one during playback (mplayer) and recording. # # If you record with streamer, it is highly recommended that you use the # streamer in xawtv-pts. # # A streamer command line for recording 1000/25 seconds in JPEG format: $ streamer -s 720x576 -t 1000 -o t.avi -f jpeg -F stereo -r 25 $ ls -l t.avi -rw-r--r-- 1 pts users 74524108 Feb 19 02:40 t.avi # The same, in MJPEG format: $ streamer -s 720x576 -t 1000 -o tm.avi -f mjpeg -F stereo -r 25 $ ls -l tm.avi -rw-r--r-- 1 pts users 80734636 Feb 19 02:41 tm.avi # (I was recording from a paused VCR, so the it can be assumed that the two # video streams are the same.) As shown above, MJPEG is a little longer, but # it also contains 4/3 as much information (MJPEG uses YUV422P: 4Y 1U 1V vs # JPEG, which uses YUV420P: 4Y 2U 2U). # # I have prepared a patch to lavrec (see URL earler), which makes it possible # to use it for MJPEG recording. Example: $ lavrec --software-encoding -U -i a -c 2 -g 720x576 -s -f a tl.avi # If something goes wrong, add `-v 1' or `-v 2'. # Without the patch, you get the error message: **ERROR: [lavrec] Error queuing buffers: Invalid argument # and it cannot start recording. # # Please note that lavrec always uses YUV420P, but it it tries to handle # interlacing intelligently. lavrec isn't faster (not even its JPEG/MJPEG # codec) than streamer or the recorder built into xawtv. # # Use top(1) to find out whether your system is too slow. If you use # streamer or xawtv to record, you will get `rate: queueing frame twice' # and `panic: reorder buffer full' messages. # # Use the xwd(1) utility to make a screen shot of mplayer(1). It doesn't work # with `mplayer -vo xv', so try `mplayer -vo x11' instead. Recording TV from within xawtv """""""""""""""""""""""""""""" # This applies only to xawtv-pts, the original xawtv is not supported. # The most important limitation of this solution that the recording subsystem # of xawtv is not stable, so you might experience audio-video sync problems or # too many dropped frames. If you want a good, stable recording with a lot # of configuration options, use mencoder (see in section `Recording TV'). See # also section `Recording TV with MEncoder from within xawtv' for a good and # comfortable solution. # # Some of the advices given here also apply to streamer, the command-line # recording program of the xawtv distribution. Please note that streamer # doesn't read ~/.xawtv! # # Yes, it is possible! If you set up everything properly, you can start # recording with a single keypress (Ctrl-), stop recording with another # keypress (Ctrl-Shift-), and you can watch the TV programme while # it is recorded. You can even use MEncoder to apply filters and do # video and audio compression in real time (!) -- all these without ever having # to leave xawtv. But these features don't come # by default -- you have to set up everything properly. # # You need a fast machine (see in the section ``Requirements'') and a lot of # hard disk space for recording. # # Make sure that you use xawtv-pts. Run `xawtv -debug 2 2>t.log' # (and exit), examine the log file t.log, and verify that xawtv doesn't try # to load auxilary files from the wrong directory (i.e a directory belonging # to another xawtv installation). # # I assume that you want to record in full resoltion, that is 720x576 for PAL # and 720x480 for NTSC. These can be specified in ~/.xawtv (needs xawtv-pts): [global] start_geometry = norm mov-record-geometry = snapnorm # Note that `norm' ensures that you get the aspect ratio of 4:3 when viewing, # and `snapnorm' ensures that you get the raw video data without rescaled to # force the aspect ratio when recording. # # It is recommended that you set [defaults] capture = grabdisplay # because this works more smoothly for watching while recording, and it also # makes snapshots (keys and ) instantly. However, grabdisplay consumes # more CPU time than overlay (but both times are negligable compared to # real-time encoding). # # It is recommended that you stop all system services before starting to # record. The most important services to be stopped are: cron, anacron and # atd. Make sure that their subprocessed are also killed. (An `updatedb' # called by cron would be dangerous, for example.) # # If you want instant recording, put thise into ~/.xawtv: [global] mov-driver = avi mov-video = mjpeg mov-fps = norm mov-audio = stereo mov-rate = 44100 mov-fvideo = rec.avi mov-record-geometry = snapnorm # Then -- while watching TV -- press Ctrl- to start recording immediately, # and later press Ctrl-Shift- to stop recording. # # When specifying filenames in the ``record a movie'' dialog, you can use the # key to have your existing filenames auto-completed. (However, if # multiple solutions are possible, you won't get a list of them, only a beep.) # This is a nice feature of the original xawtv. # # xawtv-pts doesn't let you overwrite an existing regular file, # so you won't accidentally clobber an existing precious movie. # # If you're recording AVI without sound, the time data in the record status # line will be filled with zeroes. Don't worry about that. # # It is no point to record to .mov files, because MPlayer cannot play them, at # least my MPlayer 1.0pre5 didn't recognise any of the video formats offered by # the .mov-writer of xawtv. So xawtv-pts has the `YUYV-mplayer' # video format, which works for mplayer and mencoder. However, mplayer and # mencoder relies on the fact that .mov files are seekable, so .mov writing # doesn't work with an mencoder-pipe (see more in section # ``Recording TV with MEncoder from within xawtv''). # # If you get the error message `error [start], see stderr' in the red line of # the `record a movie' window, it means that some of the recording threads # failed to start, or the video grabber or the movie writer failed to start. # This usually signifies an implementation error in xawtv or an unexpected # hardware problem. # # The most important disadvantage of recording from within xawtv is that you # cannot check whether audio is correct while recording. However, xawtv-pts # makes sure that the IGain and recsrc (recording audio channel # selection) are right -- upon startup and upon start of movie recording. Recording TV with MEncoder pipe from within xawtv """"""""""""""""""""""""""""""""""""""""""""""""" # There are some strange serialization problems with this # (the recording just halts after some time with a # `badly interleaved stream' error printed by MEncoder), and also the # recording subsystem of xawtv is not stable enough, so I have given up using # this, so this section of the tutorial has historic importance only. I # strongly recommend against doing recording this way. I am developing a new # solution, which leaks frames from a running (patched) mencoder, and it will # replace this one soon. # # You will need xawtv-pts. # You can get the benefits of both MEncoder and xawtv: xawtv is easy to # use (especially if you have set up your defaults in ~/.xawtv and you've # learned the hot keys -- even more if you've hacked the xawtv source for # your own needs :-)), and MEncoder has tons of codecs and filters. Of course # you have to know the parameters for MEncoder in advance; see # the documentation of MPlayer for hints. And -- most importantly -- MEncoder # codecs are _faster_: for example, the MJPEG codec of MEncoder (without # `-lavcopts vhq') eats about # 50% CPU, and the MJPEG codec in xawtv eats 85% on my machine. # # Applying my patch to MEncoder is strongly recommended (see in the # ``Installation'' section). Make sure that the properly patched `mencoder' is # on the $PATH. If you get the message # ``Badly interleaved AVI file detected - switching to -ni mode...'' on stderr # as soon as you start recording (described below), it is the sign that the # wrong, unpatched MEncoder is used. # # First we need a proper mencoder command line that does the encoding: mencoder - -oac pcm -ovc lavc -lavcopts vcodec=mjpeg:vhq \ -vf-add pp=lb -vf-add denoise3d -vf-add harddup -aspect 4:3 -o rec.avi # Please note the `-' (meaning: read input video from stdin) in the command # above. Note also `-vf-add pp=lb', which does deinterlacing. If you already # have an AVI file at hand, try the command above (but substitute `-' by # ). # !! command line for real-time DivX encoding # !! noise with DivX # # You also need xawtv-pts, because the original xawtv # didn't support video output piping. The trick is to to specify the MEncoder # pipe command line (prefixed by a `|') in the `movie/images filename' field # of the `record a movie' window instead of a real file name. But since you # don't want to type the same thing twice, put everything to ~/.xawtv: [global] mov-driver = avi mov-video = yuyv mov-fps = norm mov-audio = stereo mov-rate = 44100 mov-fvideo = |mencoder - -oac pcm -ovc lavc -lavcopts vcodec=mjpeg:vhq -vf-add pp=lb -vf-add denoise3d -vf-add harddup -aspect 4:3 -o rec.avi mov-record-geometry = snapnorm # Make sure that you don't specify `mov-video = jpeg' (or mjpeg), because the # actual coding should happen in mencoder. # # Restart xawtv, press Ctrl-, and the recording with mencoder begins # immediately. See stderr to spot when something goes wrong. If everything is # fine, MPlayer starts counting the frames and time on stderr. Stop recording # the usual way (press Ctrl-Shift- or click on the button # `start/stop recording'). Recording TV with external MEncoder from within xawtv """"""""""""""""""""""""""""""""""""""""""""""""""""" # !! This part of the tutorial is work-in progress. # !! why is this so good? # # You will need a patched MEncoder (that supports `-tv saveframes=)') # and xawtv-pts (working as of Mon Mar 21 00:54:41 CET 2005) # to make this working. If your mencoder is not patched properly, # you have to force `[global] mov-blit = no', and thus you won't be able to # watch the movie in the xawtv window while it is being recorded. # # You must select the # `external mencoder recording' movie driver in the `record a movie' () # window. The short name of this driver is `mencoder'. The recommended # configuration in ~/.xawtv is: [global] mov-fps = norm mov-rate = 44100 mov-driver = mencoder mov-video = yuyv mov-audio = mjpeg-pcm mov-mencoder-fsavenames-pattern = xawtvrec-%(channel)-%(yyyy)%(mm)%(dd)-%(HH)%(MM)%(SS)%(-newfilecount).prv mov-mencoder-prefix = mencoder mencoder-mjpeg-pcm = -oac pcm -ovc lavc -lavcopts vcodec=mjpeg:vhq -vf-add pp=lb -vf-add denoise3d -vf-add harddup mencoder-divx-mp3 = -oac mp3lame -lameopts abr:br=112:q=0 -ovc lavc -lavcopts vcodec=mpeg4:vhq -vf-add pp=lb -vf-add denoise3d -vf-add harddup # Of course, you will need some additional settings (not directly related to # the external MEncoder), for example: [global] mixer = /dev/mixer:line mov-record-geometry = snapnorm mov-fvideo-pattern = xawtvrec-%(channel)-%(yyyy)%(mm)%(dd)-%(HH)%(MM)%(SS)%(-newfilecount).avi mov-blit = yes # # Some mov_ settings retain their usual meaning: mov-driver (`movie driver'), # mov-fvideo-pattern (`movie/images filename'), mov-rate (`sample rate'), # mov-record-geometry (`video size') and mov-blit. However, some other settings # have special meaning in external MEncoder mode: # # -- mov-audio (`audio format') specifies the encoding command line option # set passed to mencoder. For example, `mov-audio = mjpeg-pcm' will make # xawtv look up `[global] mencoder-mjpeg-pcm' and pass everything found # there to mencoder. You cannot change the option values in the xawtv GUI; # you have to edit and save ~/.xawtv, and restart xawtv for these to take # effect. The original meaning of mov-audio, # the target audio format and the codec can be specified as options to # mencoder in `[global] mencoder-...'. # # -- mov-fps (`frames/sec') is ignored, always the maximum value supported by # the grabber is used # # -- mov-video (`video format') is not the target video format, but the video # format used for grabbing. `yuyv' or `uyvy' is recommended for both # performance, quality and compatibility (no horizontal stripes) reasons. # Only the formats supported by the TV tuner card appear in the list. # The target video format and the codec can be specified as options to # mencoder in `[global] mencoder-...'. # # The following settings are only for the external MEncoder: # # -- mov-mencoder-fsavenames-pattern: file name pattern for temporary file # needed by `mov-blit = yes'. # # -- mov-mencoder-prefix: the pattern for the name of the mencoder executable. # Will be tilde-expanded and split on whitespace. # # The options specified in `[global] mencoder-...' should usually contain: # # -- `-oac ...' or `-nosound' # -- `-lameopts ...' if `-oac mp3lame' is specified # -- `-ovc ...' # -- `-lavcopts vcodec=...:...' if `-ovc lavc' is specified # -- `-of' is optional (the default, AVI, should be OK, but you might want # to change it to `-of rawvideo') # -- `-af' is optional # -- several `-vf-add' are optional, but specifying # `-vf-add pp=lb' (deinterlace), `-vf-add denoise3d' (noise reduction) # at the beginning is recommended, and `-vf-add harddup' (encode empty # AVI video frames) at the end is strongly recommended. # The mjpegtools utilities can process the resulting AVI only if # `-oac pcm -ovc lavc -lavcopts vcodec=mjpeg:... -vf-add harddup' were # also specified. The `-vf ...', `-vop ...', `-vf-del ...', # `-vf-pre ...', `-vf-clr' options are not recommended; `-vf-add ...' # should be used instead. # # However, it must not contain `-srate', `-o', '-tv' or `tv://', `-aspect' # or `-lavcopts aspect=...', because xawtv-pts adds these automatically. Watching video (composite cable) """""""""""""""""""""""""""""""" # If your video has two or three RCA connectors, that's called ``Composite''. # (For the Leadtek WinTV Expert you'll need the adapter cable shipped with # the card.) You'll need a yellow cable (a cable with two yellow connectors # at the end) for the video signal, and a red and # a white cable for the (stereo) audio signal. Not all videos have stereo RCA # connectors -- then two cables (a yellow and a red/white) would be enough. # To get mono mode right, connect to the red adapter cable (the white one # didn't work for me in mono mode with Winfast TV2000 XP). # Add the following lines to ~/.xawtv, so you can switch to the composite # video input by pressing <0>. [Video] input = Composite1 key = 0 !! recording Video bttv sound problem Watching S-Video """""""""""""""" # This is similar to composite video, but you need a 5-pin S-Video cable, # which carries both the audio and the video (in better quality than the # composite cables), and you need this in ~/.xawtv so you can start watching # video by pressing : [S-Video] input = S-Video key = s Limited media playback support in xawtv-pts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # For better playback support, # try pia(1), but for serious media playback, use mplayer(1). # # To start playing back a file, run: $ xawtv-remote capture playback t.prv # When the playback is finished, you must press to resume normal TV. # # Changing stations during CAPTURE_PLAYBACK reverts to the default # CAPTURE_ON. # # Limitations: # # -- Only the video is played (the audio isn't). # -- Frames are not skipped if playback is too slow. # -- Only the PRV file format is fully supported # (see libng/plugings/read-prv.c). This file format is similar to YUV4MPEG. Non-interactive commands """""""""""""""""""""""" The `xawtv-remote' can be used a running instance of xawtv, and `v4lctl' can be used to control video4linux even when xawtv isn't running. xawtv-remote has no effect if xawtv is not running (but it reports that fact properly, and returns with exit code 2). However, some of the v4lctl instructions have no effect, for example `v4lctl capture off' is a no-op, but `xawtv-remote capture off' works. Using the remote control """""""""""""""""""""""" Most tuner cards come with an infrared remote contol. The receiver must be connected to the card, and the ``eye'' of the other end of the receiver (the small cylinder) must be visible to the remote control. A working set of batteries has to be installed into the remote control. The remote control of the WinTV card works perfectly, however, the Winfast card wasn't at the time of writing the tutorial, but progress was reported to be made in the video4linux list, so it should be working now. The Linux evdev module must be loaded before the tuner card module. This is done by tvload.sh automatically, and it prints something like `cx88[0]: registered IR remote control' on success. You can check whether you have a working remote control by searching for bttv|cx88|saa7134 in /proc/bus/input/devices. See also doc/README.ir in the video4linux package for more information concerning setup. Use the tools of the `input' package (see the ``Packages'' section) for debugging. For example, run `input-events 2' to dump events from /dev/input/event2. tvplus.pl comes with a preliminary built-in support for remote controls. Just run `tvplus.pl --remote-dump' to dump all events received. You can write your event handler in Perl. For example, add the lines #: remote_control += if ($H{action}eq'press'&&$H{keysym}eq'RED' ) { system qw(v4lctl setattr hue 100); return 1 } #: remote_control += if ($H{action}eq'press'&&$H{keysym}eq'GREEN') { system qw(v4lctl setattr hue 255); return 1 } #: remote_control += if ($H{action}eq'press'&&$H{keysym}eq'YELLOW') { print "Hello, Yellow!\n"; return 1 } #: remote_control += if ($H{action}eq'press'&&$H{keysym}eq'BLUE') { system qw(v4lctl setstation TV2); return 1 } to the [defaults] section of ~/.xawtv, and then start running `tvplus.pl --remote-dump' (possibly inside screen(1)). Try pressing the YELLOW button on the remote control and verify that the `Hello, Yello!' message appears. Modify the code added to ~/.xawtv to have your own event handler. The utilities v4lctl and xawtv-remote will be particularly useful. Please note that tvcode.pl reassigns some of the buttons so the codes won't conflict with your normal keyboard. As a result, the symbolic name for the button is lost, so don't be suprised to have 233 and 234 as keysym for the volume adjusting buttons etc. The keysyms depend on the TV tuner card model! The standard way for handling remote controls with Linux and xawtv is using lircd. The newest, CVS version of lircd is said to be compatible with the Linux 2.6 input methods (/dev/input/event*), so you may consider installing it instead of using the ad-hoc implementation in tvplus.pl. Setting brightness, contrast etc. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ These settings have serious effect on colors. The defaults might be ugly (for example, if you see only gray, and a little magenta and green, you should increase hue to maximum (255 for cx88) etc.), moreover, the card switches back to the defaults when changing TV stations. Imp: develop this properly Dat: mplayer audio mode (`Audio: no sound'), sometimes noise Dat: RTL Klub, mplayer: v4lctl volume mute off; v4lctl setattr bright 128; v4lctl setattr contrast 80; v4lctl setattr color 200 Dat: IGain mustn't be zero cx88[0]/0: AUD_STATUS: 0xfff2 [mono/no pilot] ctl=A2_AUTO_STEREO Dat: also OK: bright | int | 190 | 0 | range is 0 => 255 contrast | int | 60 | 0 | range is 0 => 255 color | int | 124 | 0 | range is 0 => 255 hue | int | 255 | 0 | range is 0 => 255 volume | int | 63 | 0 | range is 0 => 63 Balance | int | 64 | 64 | range is 0 => 127 Dat: better: bright | int | 160 | 0 | range is 0 => 255 contrast | int | 60 | 0 | range is 0 => 255 color | int | 210 | 0 | range is 0 => 255 hue | int | 255 | 0 | range is 0 => 255 Dat: good settings: bright | int | 168 | 0 | range is 0 => 255 contrast | int | 60 | 0 | range is 0 => 255 color | int | 124 | 0 | range is 0 => 255 hue | int | 255 | 0 | range is 0 => 255 # Imp: color==124 or color==210?? # Dat: m1: 210 is better; v4lctl setattr bright 168; v4lctl setattr contrast 60; v4lctl setattr color 210; v4lctl setattr hue 255 # Dat: m1: best (Gálvölgyi): v4lctl setattr bright 140; v4lctl setattr contrast 60; v4lctl setattr color 230; v4lctl setattr hue 255 Dat: sometimes color=255 is also OK # aumix -i3; v4lctl setattr mute off; v4lctl setattr bright 160; \ # v4lctl contrast 60; v4lctl setattr color 210; v4lctl setattr hue 255 # Dat: color OK between 200..255 Imp: correlation of values for mplayer/mencoder and v4lctl Setting up the beep (bell) to the classical way ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To get a beep, type Ctrl- on a shell prompt, or issue the command `echo -ne "\007" >/dev/tty'. On good old systems, this made an audio beep (or bell) sound on the built-in PC speaker. With kernel 2.6.10 you need the `pcspkr' module in order to get that sound. If you have a sound card module loaded, the beep will be audible on the sound card's output too. To disable this, set the PC speaker volume on the sound card to zero: `aumix -p0'. Palette, color space, uncompressed video format ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Analog TV signals (for all of PAL, NTSC and SECAM) are broadcast in the YUV, subsampled color space. -- The Y component of YUV is called luma, brightness, lightness, intensity, blackness or grayness. The most appropriate name is ``luma''. Black-and-white TV sets (produced in the 1950s) decode only the Y component of the signal. The U and V components are called ``chroma''. -- See http://www.answers.com/topic/yuv for an excellent tutorial on YUV and video cables. See http://www.fourcc.org/yuv.php and http://www.fourcc.org/rgb.php for a detailed list of video formats. -- See more in mplayer:DOCS/tech/colorspaces.txt -- The yellow video delivers contains the composite YUV signal. The S-Video cable (which provides sharper, better-quality picture) has 3 separate wires for Y, U, V, thus it delivers a component signal. -- Color space conversion between 8-bit YUV and 8-bit RGB formats are lossy, because too high and too low values are cropped. -- Subsampling means that the U and the V plane contains less information than the Y plane. For example, the UYVY format codes two consecutive pixels (Y0,U0,V0), (Y1,U1,V1) to ((U0+U1)/2, Y0, (V0+V1)/1, Y1). Further subsampling is possible, e.g YUV420P takes average of 2x2 pixels for both U and V. -- I recommend the UYVY format for video recording, because YUV<->RGB conversion is not necessary, extra subsampling is not done, and it is supported by many utilities. Other recommended formats are, in decreasing order of precedence: bgr24, yuv420p, rgb15_le and yuv420p. Here comes a table of the most important uncompressed video formats. Meaning of bbreviations and captions: -- 2: v4l2 -- m: mplayer/mencoder -- n: libng/xawtv -- 2==m: mplayer_tvi and v4l2 fourccs are the same -- moption: as printed by `mplayer -tv outfmt=help', found in mplayer:moption.c -- name: name from xawtv-pts:libng/grab-ng.c:ng_vfmt_info[] -- depth: number of (storage, not information!) bits a single pixel occupies Flags: -- M: supported my mplayer_tvi_v4l2 -- A: planar -- C: packed -- R: tested and recommended by mplayer-1.0pre6a:tv.c -- P: mplayer _can_ play (detect) such raw AVIs -- V: v4l1 flips the image vertically, mplayer:tvi_v4l.c flips back libng mplayer moption v4l1 v4l2 depth flags comments IMGFMT_YVU9 yvu9 V4L2_PIX_FMT_YVU410 9 MA 2==m IMGFMT_YV12 yv12 V4L2_PIX_FMT_YVU420 12 MAR 2==m mplayer grabs YUV420 and then swaps U<->V planes; grabbing is bad (misplaced high stripes) with cx88+v4l2+mplayer IMGFMT_NV12 nv12 V4L2_PIX_FMT_NV12 12 MA 2==m IMGFMT_NV21 nv21 12 MA yuv422p VIDEO_YUV422P IMGFMT_422P 422p VIDEO_PALETTE_YUV422P V4L2_PIX_FMT_YUV422P 16 MA 2==m easily convertible to MJPEG IMGFMT_411P 411p V4L2_PIX_FMT_YUV411P 16 MA 2==m uyvy VIDEO_UYVY IMGFMT_UYVY uyvy VIDEO_PALETTE_UYVY V4L2_PIX_FMT_UYVY 16 MCRP 2==m IMGFMT_Y41P --- V4L2_PIX_FMT_Y41P 12 MA 2==m IMGFMT_RGB8 rgb8 V4L2_PIX_FMT_RGB332 16 MC rgb15_le VIDEO_RGB15_LE IMGFMT_RGB15 rgb15 VIDEO_PALETTE_RGB555 V4L2_PIX_FMT_RGB555 16 MCRPV rgb16_le VIDEO_RGB16_LE IMGFMT_RGB16 rgb16 VIDEO_PALETTE_RGB565 V4L2_PIX_FMT_RGB565 16 MCRV rgb24 VIDEO_RGB24 IMGFMT_RGB24 rgb24 V4L2_PIX_FMT_RGB24 24 MCRPV rgb32 VIDEO_RGB32 IMGFMT_RGB32 rgb32 V4L2_PIX_FMT_RGB32 32 MCRPV bgr24 VIDEO_BGR24 IMGFMT_BGR24 bgr24 VIDEO_PALETTE_RGB24! V4L2_PIX_FMT_BGR24 24 MCP bgr32 VIDEO_BGR32 IMGFMT_BGR32 bgr32 VIDEO_PALETTE_RGB32! V4L2_PIX_FMT_BGR32 32 MCP gray VIDEO_GRAY IMGFMT_Y800 y800 VIDEO_PALETTE_GREY V4L2_PIX_FMT_GREY 8 MAC IMGFMT_IF09 if09 V4L2_PIX_FMT_YUV410 9 MA yuv420p VIDEO_YUV420P IMGFMT_I420 i420 VIDEO_PALETTE_YUV420P V4L2_PIX_FMT_YUV420 12 MARP easily convertible to JPEG; this is the YUV4MPEG format used by mjpegtools yuyv VIDEO_YUYV IMGFMT_YUY2 yuy2 V4L2_PIX_FMT_YUYV 16 MCRP VIDEO_PALETTE_YUYV also exists, but unused by xawtv3:drv1-v4l.c rgb08 VIDEO_RGB08 IMGFMT_BGR8? rgb8 VIDEO_PALETTE_HI240 V4L2_PIX_FMT_HI240 8 C dithering? pseudocolor? rgb15_be VIDEO_RGB15_BE IMGFMT_BGR15? bgr15 V4L2_PIX_FMT_RGB555X 16 C rgb16_be VIDEO_RGB16_BE IMGFMT_BGR16? bgr16 V4L2_PIX_FMT_RGB565X 16 C IMGFMT_444P 444p IMGFMT_ABGR abgr IMGFMT_ARGB argb IMGFMT_BG4B bg4b IMGFMT_BGR1 bgr1 IMGFMT_BGR4 bgr4 IMGFMT_BGR8 bgr8 IMGFMT_BGRA bgra IMGFMT_CLPL clpl IMGFMT_HM12 hm12 IMGFMT_I420 i420 IMGFMT_IYUV iyuv IMGFMT_RG4B rg4b IMGFMT_RGB1 rgb1 IMGFMT_RGB4 rgb4 IMGFMT_RGBA rgba IMGFMT_Y8 y8 How to convert YUV to RGB and back ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ These YUV -> RGB conversion macros are based on http://www.fourcc.org/fccyvrgb.php All vars (Y, V, U, R, G, B) are integers in the range 0..255. clip(x) := x < 0 ? 0 : x > 255 : 255 : round(x) RGB to YUV conversion: Y := clip( (0.257 * R) + (0.504 * G) + (0.098 * B) + 16 ) Cb = U := clip(-(0.148 * R) - (0.291 * G) + (0.439 * B) + 128) Cr = V := clip( (0.439 * R) - (0.368 * G) - (0.071 * B) + 128) YUV to RGB conversion: R = := clip(1.164(Y - 16) + 1.596(V - 128)) G = := clip(1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)) B = := clip(1.164(Y - 16) + 2.018(U - 128)) Misc information ~~~~~~~~~~~~~~~~ -- mencoder `-vf-add pp=al:f' has no effect (i.e. no automatic brightness/contrast): tuner/tvplus.pl mencoder --mjpeg-pcm -o t.avi tv://tv2 -tv brightness=10 -vf-add pp=al:f -- When you have a driver-related problem, use the latest kernel, video4linux and xawtv -- don't use third-party software, because it might not be up to date. -- Some of the v4lctl commands (such as `capture' and `fullscreen') do not have any effect at all. -- You cannot use ffv1rec (part of the source of avidemux2) to record TV, for example: $ ffv1rec -C MJPEG -p t.avi VIDIOCMCAPTURE1: Invalid argument VIDIOCMCAPTURE0: Invalid argument [... ad infinitum] Dat: not any more, doesn't have sound: streamer -r 25 -s 720x576 -t 10:0 -f rgb24 -o /dev/stdout | mencoder - -o t.avi -ovc lavc -lavcopts vcodec=mjpeg -nosound Dat: SUXX: Ctrl- doesn't work for streamer Dat: SUXX: (which program) ioctl: VIDIOC_DQBUF(index=0;type=VIDEO_CAPTURE;bytesused=0;flags=0x0 [];field=ANY;;timecode.type=0;timecode.flags=0;timecode.frames=0;timecode.seconds=0;timecode.minutes=0;timecode.hours=0;timecode.userbits="";sequence=0;memory=unknown): Input/output error Dat: needed: v4lctl setattr mute off Dat: the TV tuner card's audio output is connected to the CD input of the sound card. If this is not the case, swap -c with -l or -m in the aumix command line Dat: note that audio recording (to .wav or .avi) is not affected by -c, -l, or -m, but it is affected by -i. -i0 mutes audio recording, -i1 ... -i99 is OK (-i99 is just a little louder than -i1), -i4 would be specified so the non-muted IGain state is visible in aumix. Dat: SUXX: Ctrl-Alt-, Ctrl-Alt- makes mplayer freeze Dat: diff -ur xawtv-3.94.orig xawtv-3.94 | grep -v '^Only in ' | gzip -c9 >pts-xawtv-3.94.patch.gz Dat: for F in lavtools/{lib,}lavrec.c; do diff -u mjpegtools-1.6.2{.orig,}/"$F"; done >lavrec.patch Dat: the cx88 module had to be reloaded at some point (because it gave only single pics Dat: to create a simple (green--purple) YUV4MPEG file, do: perl -e 'my($NFRAMES,$W,$H)=(100,720,576);print"YUV4MPEG2 W$W H$H Ip F25:1 A0:0\n";for($I=0;$I<$NFRAMES;$I+=2){for("\xFF","\x00"){print"FRAME\n";print"\xff"x($W*$H);print$_ x(($W>>2)*$H);print$_ x(($W>>2)*$H)}}' | something where something is `cat >file.yuv', `yuvplay' or `yuv2lav -fa -I0 -q50 -o tes.avi' New features of xawtv-pts ~~~~~~~~~~~~~~~~~~~~~~~~~ -- misc. improvements and driver fixups (hopefully invisible) -- better ``record a movie'' dialog -- new ~/.xawtv options -- instant recording with Ctrl-, stop with Ctrl-Shift- -- recording doesn't start if filename already exists -- more verbose error messages with and without `xawtv -debug 1' -- config file lines can be longer (512 bytes), and comments are allowed in the middle of the line (starting with ` # ') -- xawtv automatically sets IGain and audio recording source upon startup, so you can be sure that your recording will not have its audio muted -- `sane-scrollbars = yes' makes the paned volume control scrollbars behave ,,sanely'', so you can drag-and-drop them (now all 3 mouse buttons are equivalent to the middle one). -- new attributes to control sound card mixer (e.g. mixer-volume) -- changed: /etc/X11/xawtvrc is not parsed if ~/.xawtv exists. This way the user has full control. -- specify `mixer-volume-delta = ' for a station to adjust the mixer (aumix(1)) volume (i.e the volume with which the sould card adds its LineIn (or `mixer = ...') to its output) by the specified integer offset each time the station is activated. The adjustment is undone before changing frequencies, channels or stations, and also upon normal exit from xawtv. The adjusted volume will not go out of bounds, i.e. if mixer-volume is 70 (with the maximum of 100), and mixer-volume-delta is 80, mixer-volume will become 100 when entering the station, and it will fall back to 70 upon leaving it. This feature was requested by Gergi Miklós. -- per-station option `volume-delta' is similar to `mixer-volume-delta', but it adjusts the volume of the TV tuner card's output. -- mtt knows keys etc. -- reduced flicker when pressing for pause with Xv, no flicker with -noxv -- when making a snapshot in pause (`capture off'), the paused ximage is saved -- limited media playback support in xawtv (see earlier) -- xawtv properly detects that another application is using the TV tuner. After quitting that application, you can press in xawtv to start watching TV. -- bugfix: both JPEG and MJPEG recording works -- bugfix: all video formats provided by the AVI writer _do_ work for recording (tested with MPlayer) -- customizable filename generation (see `[global] snap-pattern', `[global] mov-faudio-pattern' and [global] mov-fvideo-pattern', e.g `mov-fvideo-pattern = xawtvrec-%(channel)-%(yyyy)%(mm)%(dd)-%(HH)%(MM)%(SS)%(-newfilecount).avi' -- `[global] osd = always' for having OSD even in non-fullscreen mode -- !! tons more I've forgotten to mention Please note that some of my changes also improve `motv' and `streamer'. For information about compiling and installing my xawtv, see its README. What functionality is lost: -- motv (untested, probably doesn't work) -- obtaining the video with overlay (untested, probably doesn't work) Proposed improvements to xawtv ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !! XvSetPortAttribute(XvInternatiom("XV_SATURATION"),0/*-1000..1000*/); by default !! startup audio force unmute !! JPEG snap too long blue !! now `xawtv' produces wrong colors (YUYV), `xawtv -noxv' is OK; restarting the X server helped (Gentoo, x.org) !! use [global] mixer_igain in xawtv !! clear old background after !! conversion is now very slow! !! eliminate blue blinks, flickers with `-xv' !! make dist etc. !! emit SMJPEG container format !! xawtv conversion speed problems !! mencoder buffer full at about 15s (when reading AVI from stdin) !! why does VIDEO_BGR24 or VIDEO_RGB24 recording require `mplayer -ni' !! streamer aspect ratio (vprp) -> AVI !! relative timing (no gettimeofday()) in common/capture.c !! xawtv grab in a format supported by Xv display -- if possible !! xawtv test Xv blit_init_frame resizing with bgr24_to_yuyv conversion !! xawtv remember `v4lctl setattr hue', just like when changing interactively !! xawtv %-filename generation etc. !! xawtv record 10 seconds in advance (with pipe fill compensation) !! xawtv switching between snap_maxsize and start_geometry w/ a hot key !! xawtv deinterlacing while recording (configurable, even-odd frame swap etc.) !! xawtv write ODML avi index (low priority) !! xawtv should respond to events generated by v4l-ctl !! xawtv stop recording when specified time elapses !! xawtv time-based programmable recorder, ~/.xawrecord !! make `v4lctl capture off' etc. work !! xawtv snap long-lasting "capture" "off" image -- no effect of `v4lctl volume mute off' !! xawtv mute audio upon exiting (??) -- even `v4lctl volume mute off' has no effect, and radio(1) doesn't mute it too. !! xawtv enable audio recording, detected by volume etc. !! xawtv `record a movie' should be able to change current directory [UI] !! xawtv allow specifying mov-record-geometry in `record a movie' [UI] !! xawtv use movie_init_error_callback !! `make install' shouldn't overwrite normal xawtv !! xawtv no "capture off" in pixit !! bugfix: hard to reproduce bug upon exiting (after v4l2: close): X Error of failed request: BadWindow (invalid Window parameter) Major opcode of failed request: 2 (X_ChangeWindowAttributes) ==9810== Invalid read of size 4 ==9810== at 0x1BBB7964: XtWindow (in /usr/X11R6/lib/libXt.so.6.0) ==9810== by 0x1BBBC3C0: DoOtherSources (in /usr/X11R6/lib/libXt.so.6.0) ==9810== Address 0x1C697A50 is 96 bytes inside a block of size 160 free'd ==9810== at 0x1B9051B0: free (vg_replace_malloc.c:153) ==9810== by 0x1BBA1331: XtFree (in /usr/X11R6/lib/libXt.so.6.0) same bug(?): ioctl: VIDIOC_G_TUNER(index=0;name="";type=unknown;capability=0x0 [];rangelow=0;rangehigh=0;rxsubchans=0x0 [];audmode=MONO;signal=0;afc=0): Bad file descriptor Error: Object "xawtv" does not have windowed ancestor !! why is station switching slow (see 800x600) !! xawtv blue flicker on station switching !! auto-fix for bad field order in interlace-inv.ppm (mtv1) !! measure and compensate constant audio--video delay in xawtv recording; change init order back in movie_writer_start() !! rate: queueing frame twice (2) Pos:1044.1s 26103f ( 0%) 25fps Trem: 0min 0mb A-V:0.040 [12876:1411] Badly interleaved AVI file detected - switching to -ni mode... v4l2: waiting for a free buffer !! why do we have `rm libng/plugins/read-prv.o libng/contrib-plugins/widen.o libng/plugins/write-mencoder.o' in `make clean; make' !! test normal (raw) recording !! reload config file without exiting Not finished yet ~~~~~~~~~~~~~~~~ Some topics not covered in this tutorial: !! admw_save.pl !! libdv bad interlace quality?? !! mencoder/mplayer patches !! where to set proper field order (interlace-inv.ppm)? !! fix tvplus.pl to use `mixer = /dev/mixer:line'; don't use aumix anymore !! compare: frequency/channel switch speed !! compare: WinTV TV2 teletext isn't accurate with mtt(1), ok with m1 !! radio should be stereo with Hauppauge WinTV PCI FM !! document devsetup in xawtv !! document my own ~/.xawtv options !! cannot record audio from Video anymore (I get audio of TV) on the Hauppauge card! !! tdda9 patches by me !! more patches to tuner !! disable to-mono patch in cx88.c !! bad field order in interlace-inv.ppm vvv good effect, but distortion in the station logo! perl -e '++;print"P6\n768 576\n255\n";read(STDIN,$_,768*3);print;while(read(STDIN,$_,768*6)){print substr($_,3*768),substr($_,0,3*768)}' t.ppm Dat: 18446587: 0.33s Dat: sample streamer command line: console/streamer -f mjpeg -s 720x576 -d 2 -t 10:59 -r 25 -o t.avi -f jpeg -F stereo Dat: my i810_audio card reports 7903--10891--21783--43567Hz, but it operates on 8000--11025--22050--44106.25Hz The reports are false on 2.6.10. Were good on Linux-2.4 Dat: streamer SUXX: if something goes wrong, on quitting, it is just `waiting for a free buffer'; and then `one moment please...' forever Dat: SUXX: grabdisplay nice(10) load (Mozilla) Dat: mencoder final output not previewable here... Imp: doc: get rid of AUD_STATUS from the kernel log Imp: recording to mono .wav or .mp3 Imp: switching between video and TV sound may go away, `norm = PAL-BG' sets it Imp: why does my grab/snap code produce a different `color' value Further reading ~~~~~~~~~~~~~~~ -- Now you know what to search for. Google is your friend. -- If you have driver-specific quiestions, join the video4linux mailing list. See the URL https://listman.redhat.com/mailman/listinfo/video4linux-list at http://www.exploits.org/v4l/ . -- another tutorial for recording with xawtv / streamer: http://vmjpeg.sourceforge.net/REC_HOWTO __EOF__