TV Tuner

An article about configuring and using Television (TV) Tuners with Gentoo Linux.

See also Gentoo Linux VDR Guide

(Need entries for for Linux Kernel .config; analog and digital tuner drivers, as well as Analog TV configuration and using. Or, just included your data and fixes.)

(Need entries for your preferred method of viewing and recording. I use the console and figured some would be interested how I do this. ;-)

Command Line Tools
The package is needed.

Analog Tuner
These are pretty much deprecated within the US, however analog signals are still used extensively for Amateur Radio enthusiasts. Yes, Amateur Radio freaks even broadcast video signals.

XawTV
Below describes the last stable release of XawTV within Gentoo Portage. As far as development, XawTV version 3 git sees regular updates while, XawTV version 4 git hasn't seen any development for years.

Install
Install with zvbi (build scantv) and xext (include xdga) USE flags. (These are only some suggested USE flags.)

(See man xawtvrc)

Scan for Channels
Auto scan for channels:

(I'm having some problems with a HVR-1950 on the analog side with with scantv complaining about no vbi device. Try -C /dev/null and/or the latest GIT versions.)

Manually add channels using predefined listings:

IVTV-Utils
ivtv-utils is another program for tuning analog channels, primarily for Hauppauge tuners. (I'm having much better success with ivtv-utils with my Hauppauge HVR-1950, analog side.)

Install
Install :

The .ivtv-tune doesn't need to be hand edited as it seems to be automatically created. Here it is anyways in case you feel like manually creating.

Scan for Channels
ivtv-utils contains the frequency tables statically within it's code. No need to look for external files.

Get a list of supported frequency tables:

Tune to a channel:

ivtv-tune can also utilize an existing $HOME/.xawtv file as well. See ivtv-utils --help for additional options.

From here, a script can be easily created for automated channel scanning with ivtv-tune. Basically; 1) Tune to a channel. 2) Wait for a second or two for channel lock and then check for a signal (ie. grep /sys/class/pvrusb2/sn-6202710/ctl_signal_present/cur_val). 3) Change to next channel and repeat. A small script can also be created for simply changing channels, as well as incorporating IR support. (TV-Viewer is one such example.)

MythTV

 * Able to manage analog video tuners
 * Can be difficult to use from a computer desktop
 * Requires multiple dependencies
 * TODO: Insert link to it's Wiki page when available.

The Video Disk Recorder (VDR)

 * I would pressume this too can manage analog tuners
 * No experience with this package as it requires quite a bit of configuration and knowledge of dependencies.
 * Can also be difficult to use from a computer desktop as it was designed for dedicated computers.
 * TODO: Insert link to it's Wiki page when available.

dvbscan
To get a list of channels from your digital TV USB or PCI tuning device, the generic dvbscan application from the package can be used.

DVBScan requires initial tuning data file to find your local frequencies, and already has been prepackaged with numerous generic initial tuning data files. To acquire your own initial tuning data for your area, use.

You may also create the list of channels directly using w_scan, thus skipping over the need for an initial tuning file, see w_scans output formats.

This will generate the initial tuning data for US ATSC over-the-air digital TV:

For the US ATSC over-the-air digital TV with LinuxTV packaged generic tuning data:

w_scan
w_scan is newer and more robust then the previously mentioned dvbscan, as well as also previously mentioning having the ability to generate initial tuning data.

Channel Naming Problems
The channel naming scheme for over-the-air digital TV is likely not well thought out in your area. The first field of this file is the lettered name field, of which, you may likely see duplicate identical names and no channel numbers. The remainder of the fields relate to the frequency.

For my area, the channel number reported by dvbscan on stdout is correct, but the channel lettered identification contains identical duplicates or is not well named. I have already emailed the linux-media mailing list on Sep 29 2011 to include a switch for writing the channel number to the file instead of the channel letter identification.

For the meantime, I've found a method of creating duplicate frequency entries, and then replacing the channel letter name field with the channel's number. More duplicated entries can be created to eleviate the need for typing ".1" for the first channel.

Linux Virtual Terminal with Framebuffer
Compile with fbcon and svga USE flags. (In the latest mplayer versions, USE flag svga is deprecated.)

Compile. This is a SVGA Linux Kernel driver for framebuffer console applications such as &.

Make sure to have booted Linux with a framebuffer enabled virtual terminal(s). Make the necessary edits within the bootloader configuration file. (ie. Lilo/GRUB). (ie. Add "vga=788" or "video=uvesafb:nocrtc,ywrap,mtrr:3,1280x1024-16@60")

Up until quite recently, MPlayer could only be used within a plain Linux virtual terminal. It is now possible to use MPlayer even within a Linux virtual terminal running GNU Screen! Full size video playback using MPlayer within Linux virtual terminals doesn't seem to work here.

MPlayer: Slow CPU or Graphics Card
For most scenarios, playing live streams on slower machines is not possible. One solution around this is to first record the MPEG streams to file and then play them using your media player.

The following will resize your previously recorded MPEG to something adequately smaller. Use lowres=1 or lowres=2 depending on how slow your system is.

From Console within Xorg
There's a multitude of media players, of which, mplayer seems to be the most popular and lightest on resources.

MPlayer will use the first field of each line within the channels.conf file for playback. If you have duplicate entries like I do and haven't renamed them as I've done so above, you'll need to specify the entire line from the channels.conf to play the second, third, fourth, ... duplicated entries:

EPG Guide Data
There's several methods for grabbing EPG TV Guide data and printing to stdout.

Method 1: dvbstreamer
Q. How do I update the EPG data ... (Untested)

Method 2: atsc_epg
This atsc_epg (media-tv/linuxtv-dvb-apps) is a true gem as it prints EPG data to stdout which can later be easily parsed or saved.

(According to LinuxTV.org, their linuxtv-dvb-apps package is now considered legacy code. No recent snapshot has been made of their dvb-apps GIT repository since.)

Also, LinuxTV has a wealth of information on it's linuxtv-dvb-apps package.

Usage example. Take an entry from the $HOME/.mplayer/channels.conf (from dvbscan) and strip the first field. (ie. "KUAC-DTO:189028615:8VSB:49:52:3")

This will print a very nicely formated schedule to stdout!

Now automating this process to use $HOME/.mplayer/channels.conf (dvbscan) data is a bit of a trick, especially if channels are updated. However, notice the atsc_epg command only needs a frequency and atsc_epg will tell you the channel number(s) the frequency will resolve to on stdout as well. (ie. This one PBS frequency will broadcast all four PBS channel's EPG data along with printing each of the four channel numbers to stdout.)

Use EPG Data for Syning Time
With a little grep or awk scripting and placing into /etc/init.d, could easily use atsc_epg EIT/ETT scheduling data for syncing your local computer's time.

For example: $ atsc_epg -a0 -f 189028615:8VSB:49:52:3 tuning to 189028615 Hz, please wait... tuner locked. system time: Mon Nov 28 19:18:27 2011 TS STT time: Mon Nov 28 19:18:43 2011 MGT table: ...

As you can see, my system is synced using a popular NTP client daemon and it's approximately 15 seconds slow when compared to the of the locally broadcasted EIT/ETT scheduling data. If you record frequently or rarely have local Internet access for syncing your computer's time, this might be the next best method, if not the best method for keeping your computer's time accurate.

Issues with Only One Available Tuner
The catch is, you need to have this run in the background while you are not recording as it will use the only tuner on your card for getting the broadcasted EPG data. When a recording starts, the recording script needs to check for this dvbstreamer and kill it before the recording starts, else the recording will fail to initiate as the only tuner is being used. The data being retrieved is simple ASCII text and can be likely easily parsed by even a script. I just haven't had the time to write such a script or console program, and the EPG data broadcasted here is not consistent with more accurate web based options such as TitanTV.

Scheduling
You can schedule to records a channel by creating a script to record (mencoder) a certain number of minutes (or hours) using vixie-cron (ie. crontab -e).

Create a recording script
One method is to create a script for each channel, such as the one below. One problem with this is, transmitter technicians keep changing the channel naming and frequencies. So it's wise to use my suggestion about creating aliases within the channels.conf file, noted at the beginning.

Recording using zap and cat|dd (Preferred Method)
A combination of azap, czap or tzap, along side cat or dd can be used to record from a digital DVB device. I've already taken the liberty and done much of the work and created the record-dvb.sh already posted within the above Note.

The record-dvb.sh accepts the channel id and number of minutes as options. The script then calls /usr/bin/azap alongside /bin/dd and backgrounds them both, then sleeps for the specified amount of time. File naming is also handled well within the script and only modifying the variables at the very top of the script should be required.

To test this recording method on your computer, issue the following two commands.

Set the channel using azap, czap or tzap:

Once a successful channel lock has been established, use /bin/cat or /bin/dd to record the stream:

Schedule a recording
Setup a crontab entry, as user, root or within /etc/cron, but I prefer a user cron entry.

# Record Doctor Who #  Sundays @ 23:00 #0 23 * * 0 $HOME/bin/record-ch9.1-60m.sh #0 23 * * Sun $HOME/bin/record-ch9.1-60m.sh   0 23 * * Sun $HOME/bin/record-dvb.sh -c 9.1 -m 60

#  Thursdays @ 20:00 #0 20 * * 4 $HOME/bin/record-ch9.1-60m.sh #0 20 * * Thu $HOME/bin/record-ch9.1-60m.sh   0 20 * * Thu $HOME/bin/record-dvb.sh -c 9.1 -m 60

Save and exit your console editor of choice. No need to restart cron as changes take effect immediately.

(Read 'man 5 crontab' for an explanation of crontab field names.)

MythTV

 * Able to manage digital video tuners
 * Can be difficult to use from a computer desktop
 * Requires multiple dependencies
 * TODO: Insert link to it's Wiki page when available.

The Video Disk Recorder (VDR)

 * implements an digital video recorder for digital tuners on dedicated computers
 * huge bunch of Plugins extending its functionality
 * stream audio/video
 * can be used on desktops using Plugins xine or xineliboutput
 * teletext
 * analog TV (only TV cards with hardware MPEG Encoder)
 * advertising search
 * channel scan
 * server/client
 * remote timers
 * DVD burning
 * other media
 * english wiki available on linuxtv, but the German wiki is by far more up to date.
 * english wiki available on linuxtv, but the German wiki is by far more up to date.

External resources

 * Dvbscan - LinuxTVWiki
 * Zap - LinuxTVWiki
 * W scan - LinuxTVWiki - An alternative, faster and easier channel scanner then DVBScan.
 * record-dvb.sh - Bash Script records using LinuxTV dvb-apps' zap. Written for using with Cron.