TV Tuner
2025.04.08
This is a copy of a lengthy article I had wrote sometime ago, how to
configure/use a Hauppauge TV Tuner card within Linux. The
article further mentions my record-dvb.sh
script (and published to my Gitlab page), used for
scheduling TV recordings using crontab scheduling. The below
text may inhibit old wiki mark-up syntax, interrupting your
reading! The record-dvb.sh script includes many comments
within.
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.
;-)
Contents
1 Install Software
1.1 Command Line Tools
2 Configure the Kernel
3 Analog Tuner
3.1 XawTV
3.1.1 Install
3.1.2 Scan for Channels
3.2 IVTV-Utils
3.2.1 Install
3.2.2 Scan for Channels
3.3 MythTV
3.4 The Video Disk
Recorder (VDR)
4 Digital Tuner
4.1 CLI or Console Method
4.1.1 Scan for Channels
4.1.1.1 dvbscan
4.1.1.2 w_scan
4.1.1.3 Channel Naming Problems
4.1.2 Playing Channels
4.1.2.1 Linux Virtual Terminal with Framebuffer
4.1.2.1.1 MPlayer: Slow CPU or Graphics Card
4.1.2.2 From Console within Xorg
4.1.3 EPG Guide Data
4.1.3.1 Method 1: dvbstreamer
4.1.3.2 Method 2: atsc_epg
4.1.3.2.1 Use EPG Data for Syning Time
4.1.3.3 Issues with Only One Available Tuner
4.1.4 Scheduling
4.1.4.1 Create a recording script
4.1.4.1.1 Recording using MPlayer's Mencoder
4.1.4.1.2 Recording using zap and cat|dd (Preferred Method)
4.1.4.2 Schedule a recording
4.2 MythTV
4.3 The Video Disk
Recorder (VDR)
5 External resources
Install Software
Command Line Tools
The package media-tv/linuxtv-dvb-apps is needed.
root # emerge --ask linuxtv-dvb-apps
Configure the Kernel
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 media-tv/xawtv with zvbi (build scantv) and xext (include
xdga) USE flags. (These are only some suggested USE flags.)
root # emerge --ask xawtv
[Collapse]
File$HOME/.xawtv
[global]
freqtab = usbcast
[defaults]
input = Television
norm = NTSC-M
[Camera]
input = Composite
(See man xawtvrc)
Scan for Channels
Auto scan for channels:
user $ scantv -a -C /dev/vbi -c /dev/video0 -f us-bcast -n NTSC-M
(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:
user $ cat /usr/share/xawtv/ntsc-bcast.list $HOME/.xawtv
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 media-tv/ivtv-utils:
root # emerge --ask ivtv-utils
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.
[Collapse]
File$HOME/.ivtv-tune
device /dev/video0
freqtable us-cable
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:
user $ ivtv-tune --list-freqtable
Tune to a channel:
user $ ivtv-tune --freqtable=us-bcast --channel=4
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.
Digital Tuner
CLI or Console Method
Scan for Channels
dvbscan
To get a list of channels from your digital TV USB or PCI tuning
device, the generic dvbscan application from the package
media-tv/linuxtv-dvb-apps 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 media-tv/w_scan.
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.
root # emerge --ask w_scan
This will generate the initial tuning data for US ATSC over-the-air
digital TV:
user $ w_scan -A1 -c US -fa -t3 -x
Note
w_scan is a scanner based from the linuxtv dvbapps scan code. w_scan
is a more intelligent intelligent and optimized scanner.
For the US ATSC over-the-air digital TV with LinuxTV packaged
generic tuning data:
user $ dvbscan -a 0
/usr/share/dvb/atsc/us-ATSC-center-frequencies-8VSB
>~/.mplayer/channels.conf.new
Warning
The above dvbscan incanatation is broken, as options have changed
for dvbscan and currently does not find my Hauppauge HVR-1950. (I
prefer to use w_scan.)
w_scan
w_scan (media-tv/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.
user $ w_scan -A1 -X -c US -fa -t3 > ~/.mplayer/channels.conf.new
Note
Within the w_scan output provided by the above, replace the channel
call letters with their related channel numbers. (ie. Replace "KUAC
1" with "9.1") Reason being, MPlayer has issues trying to use
channel names containing spaces or other characters, and just using
numbers makes playback using "mplayer dvb://9.1" easier.
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.
[Collapse]
File~/.mplayer/channels.conf.example
KUAC-DTO:189028615:8VSB:49:52:3
9:189028615:8VSB:49:52:3
9.1:189028615:8VSB:49:52:3
KUAC-DTO:189028615:8VSB:65:68:4
9.2:189028615:8VSB:65:68:4
KUAC-DT:189028615:8VSB:81:84:5
9.3:189028615:8VSB:81:84:5
KUAC-DT:189028615:8VSB:97:100:6
9.4:189028615:8VSB:97:100:6
KTVF DT:545028615:8VSB:65:68:4
11:545028615:8VSB:65:68:4
11.1:545028615:8VSB:65:68:4
KTVF DT:545028615:8VSB:49:52:3
11.2:545028615:8VSB:49:52:3
Note
Sometimes this works and sometimes this doesn't. If anybody has more
knowledge on this as well as corrected data, please update this
section!
Playing Channels
Linux Virtual Terminal with Framebuffer
Compile media-video/mplayer with fbcon and svga USE flags. (In the
latest mplayer versions, USE flag svga is deprecated.)
root # emerge --ask mplayer
Compile media-libs/svgalib. This is a SVGA Linux Kernel driver for
framebuffer console applications such as media-video/mplayer &
www-client/links.
root # emerge --ask svgalib
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.
user $ mplayer -vfm ffmpeg -lavdopts
lowres=1:fast:skiploopfilter=all -idx -framedrop test.mpg
From Console within Xorg
There's a multitude of media players, of which, mplayer seems to be
the most popular and lightest on resources.
user $ mplayer dvb://11
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:
user $ mplayer 'dvb://KTVF DT:545028615:8VSB:49:52:3'
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.
root # emerge --ask linuxtv-dvb-apps
(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")
user $ atsc_epg -a0 -f 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.
Note
Mencoder within the below script will tend to remux an already
broadcasted MPEG2 stream even though specifying 'copy', causing A/V
sync issues. As a result, I've gone ahead and created a more
elaborate record-dvb.sh which can be found on my server. The
record-dvb.sh script accepts a channel number and number of minutes
and can be used via cron. This record-dvb.sh supersedes the below
simpler script. This record-dvb.sh script uses a combination of azap
or czap or tzap and dd commands instead of mencoder. Bug: azap -r
option requires more then a one digit char for a channel identifier!
(ie. Not '9', use '9.1' instead)
Recording using MPlayer's Mencoder
[Collapse]
File~/bin/record-ch9.1-60m.sh
#!/bin/bash -
#===============================================================================
# FILE:
record-ch9-60m.sh
# USAGE:
./record-ch9-60m.sh
# DESCRIPTION: Record Channel 9 for 60 minutes
#===============================================================================
mencoder 'dvb://KUAC-DTC:189028615:8VSB:49:52:3' -really-quiet -of
avi \
-ovc copy -oac copy -o /stored/tv/ch9_60min-`date
+%Y%m%d-%H%M`.mpg &
pidof_mencoder=`echo $!`
sleep 59m # Only record for 58-59 minutes so we don't conflict next
scheduled
# recording.
kill $pidof_mencoder
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:
user $ $ azap -c $HOME/.mplayer/channels.conf -r 9.1
Once a successful channel lock has been established, use /bin/cat or
/bin/dd to record the stream:
user $ $ cat /dev/dvb/adapter0/dvr0 > test.mpg
user $ dd if=/dev/dvb/adapter0/dvr0 of=test.mpg conv=noerror
Note
Using /bin/cat on large files may spawn a "Value too large for
defined data type" even though you do have large file support
compiled in both kernel and system. A work-around is to use /bin/dd.
Schedule a recording
Setup a crontab entry, as user, root or within /etc/cron, but I
prefer a user cron entry.
user $ crontab -e
# 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) (Some additional notes by Wirbel
here.)
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.
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.
2014.02.02 - This article was copied from my authored "Gentoo Wiki:
TV Tuner"
page, for which the majority (if not all of it) were authored by
myself. A few
others made contributions, and it should be further noted that the
Revision
System does not seem to provide an accurate listing of denotations
by author
for some odd reason. I have snipped and preserved my
significant contributions
here, due to recently erratic Gentoo Code of Conduct authoring
submissions.
Particular parts of those submissions tends to conflict with others'
holding a
higher standard such as myself. As such, I do not plan on
volunteering more of
my time into the Gentoo Project and will likely start writing again
on my own
website. (ie. Based on current Code of Conduct, somebody
simply with a
"gentoo.org" domain mailing address could possibly delete this
entire page.) I
have made notes within showing the possible authors' contributions,
and note
the remainder of their contributions were grammatical or
Wikification
modifications.
Reverified by examining the diffs a second time and iterated here:
Grammatical
corrections by "Eliasp". Wirbel made some additions to the VDR
section at the
end of this page. Astaecker provided Wikification for Gentoo
Wiki
beautification, and mostly irrelevant of this text version.
From memory, this was a page I heavily authored and probably the
only page I'm
going to preserve due to the amount of time invested. Other
pages, my writings
were minimal and/or alongside other authors.