zap

From LinuxTVWiki
Revision as of 00:48, 19 May 2014 by Tvister (talk | contribs) (→‎Exiting after tuning)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


The process of tuning a television channel is sometimes referred to as "zapping"; the term is apparently in reference to the use of early Set Top Boxes " which could let you zap through a channel list but not much more" (see The Linux DVB API).

In the spectrum of analog TV software, "zapping" is also the name of a popular Gnome based tv viewer application.

In terms of DVB software, the abbreviated 'zap' relates to several small command line utilities found in the contents of the LinuxTV dvb-apps package .

  • The program zap (found within the ~/dvb-apps/util/zap directory of the package download) is really intended for developer use.
  • The four {a,c,s,t}zap utility programs (all found within the ~/dvb-apps/util/szap directory of the package download), on the other hand, are highly useful for the end user in setting up and testing dvb hardware devices. A given '_zap' command (azap, czap, szap or tzap) will respectively allow the user to tune a digital television (DTV) channel from a ATSC, DVB-C, DVB-S or DVB-T transmission. It is these utilities that will be discussed in the remainder of this article.

Introduction

In order to successfully tune with an {a,c,s,t}zap utility, the user must first have a valid channel configuration file (channels.conf) setup. A channels.conf file is generated by running the '[dvb]scan' utility, which is also found in the dvb-apps package -- see the scan documentation for specific details on how to create a channels.conf file. The '_zap' usage examples shown below assume that the user has already undertaken those steps to setup their channels.conf file.

Documentation

Within the dvb-apps package download itself (~/dvb-apps/util/szap directory) you will find a README file that gives a very brief explanation of how to use the {a,c,s,t}zap utilites.

Otherwise, passing an {a,c,s,t}zap command with the -h option, or without any parameters, will provide a summary of the commands usage. For example, running 'tzap' produces:

usage:
      tzap [options] <channel_name>
        zap to channel channel_name (case insensitive)
    -a number : use given adapter (default 0)
    -f number : use given frontend (default 0)
    -d number : use given demux (default 0)
    -c file   : read channels list from 'file'
    -x        : exit after tuning
    -r        : set up /dev/dvb/adapterX/dvr0 for TS recording
    -s        : only print summary
    -S        : run silently (no output)
    -F        : set up frontend only, don't touch demux
    -t number : timeout (seconds)
    -o file   : output filename (use -o - for stdout)
    -h -?     : display this help and exit

Most experts or experienced users will likely find that this information conveys sufficient details in so far as how to manipulate a specific DVB hardware device with {a,c,s,t}zap. 'New users', however, are probably left scratching their heads by some of the options listed in the output -- but fear not!

One thing that is noteworthy from the output above is that tzap does not take file system device names; instead, it cobbles them together from the adaptor, frontend and demux numbers. If you only have one tuner, you don't need to worry about this detail.

Tuning a channel

If you examine your 'channels.conf' file, you will discover that its contents are formated something like:

For ATSC (unless you saved it elsewhere, the location of the file is in the directory ~/.azap)

KPAX-DT:177028615:8VSB:49:52:1
KPAX-CW:177028615:8VSB:65:68:2
  ...
  ...
KECI-1:629028615:8VSB:49:52:3

For DVB-T (unless you saved it elsewhere, the location of the file is in the directory ~/.tzap)

ABC HDTV:226500000:INVERSION_AUTO:BANDWIDTH_7_MHZ:FEC_3_4:FEC_3_4:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_16:HIERARCHY_NONE:2314:0:592
ABC DiG Jazz:226500000:INVERSION_AUTO:BANDWIDTH_7_MHZ:FEC_3_4:FEC_3_4:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_16:HIERARCHY_NONE:0:2318:599
  ...
  ...
TEN Digital:219500000:INVERSION_AUTO:BANDWIDTH_7_MHZ:FEC_3_4:FEC_1_2:QAM_64:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_16:HIERARCHY_NONE:512:650:1617

What we're interested in here is the channel name contained in the first field of each line. (If you are interested in what the omitted fields mean, see the scan documentation for more details).

Note: For purposes of illustration, use of the 'tzap' utility is continued, however, the information contained in the following examples should largely be applicable for usage with the other '_zap' programs as well.
Note: You need the data right format in this file. Different scanning programs produce different output formats. For example w_scan must be run with the '-X' argument to obtain a channels.conf suitable for 'tzap'.

We use the specific name of a channel to tune with tzap. For example, to tune the channel named 'TEN Digital',you would enter the following in the command console:

$ tzap -r 'ten digital'
Note: You need to put the channel name in single or double quotes if it contains spaces. On the other hand, as can be seen (and as outlined in the documentation section above), you don't have to match case.

Running that command should produce output similar to the following:

using '/dev/dvb/adapter0/frontend0' and '/dev/dvb/adapter0/demux0'
reading channels from file '/root/.tzap/channels.conf'
tuning to 219500000 Hz
video pid 0x020, audio pid 0x028a
status 00 | signal 933f | snr 0000 | ber 00000000 | unc 00000000 | 
status 1f | signal a70f | snr d0d0 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
status 1f | signal aadf | snr cccc | ber 00000000 | unc 00000000 | FE_HAS_LOCK
 ...(repeated updated output) ...

The first four lines in the above output show what tzap is doing; they should reflect the corresponding fields in the channels.conf file.

Starting on the fifth line, several fields of information are presented. Each successive line afterwards simply displays the updated state or condition of each of these representative fields. The updating process will repeat continuously on its own, once every second (i.e. a new line is generated every other second), but you can terminate it at any time with Ctrl-C. In any regard, these information fields are:

  • status: The current status of the receiver.
    You will notice that the value found on the fifth line is "status 00". This shows that the tuner card has been initialized, but no signal has been decoded.
    On successive lines, ideally the status value should be 1f (as is the case in the example output), which would indicate that correct tuning is established.
    The actual bitmapped field possibilities are:
    • 0x01 = FE_HAS_SIGNAL - found something above the noise level
    • 0x02 = FE_HAS_CARRIER - found a DVB signal
    • 0x04 = FE_HAS_VITERBI - FEC is stable
    • 0x08 = FE_HAS_SYNC - found sync bytes
    • 0x10 = FE_HAS_LOCK - everything's working...
    • 0x20 = FE_TIMEDOUT - no lock within the last ~2 seconds
    • 0x40 = FE_REINIT - frontend was reinitialized
  • signal: Signal strength. The values shown here can vary from card to card, so if yours appears abnormally high or low, it probably means you're using a different card. In general, though, higher values mean better signal.
  • snr: The signal to noise ratio. This is more important than the signal strength. Many cards really only supply 8 bits of data (2 digits); the other two may be 00 or repeat the first two, as in this example.
  • ber: The bit error rate. This should be as low as possible, preferably 0.
  • unc: Uncorrected block errors. This should be 0 for a good signal; if it isn't, you'll have defects in the output stream.
  • FE_HAS_LOCK: This indicates that the tuner has tuned ("locked") into the stream.

Not all the numbers are implemented in some drivers, but good is signal > 8000, status 1f (all bits set), snr (Signal to Noise Ratio) should be > 8000, ber (bit error rate) - low is good, unc (Uncorrectable blocks) - low is good.

Recording a program

There are two ways to record a program. tzap can copy the data directly to a file:

tzap -o foo 'SBS digital 1'

This variant tunes to SBS digital 1 and then copies the stream to the file foo. It continues until you stop the tzap process.

Or, to record a channel for a specified period of time (this could be run from at to record at a specific time):

tzap -t 3600 -o foo.ts "BBC ONE"

(This records from the channel BBC ONE for 1 hour (3600 seconds)).

Alternatively, you can make the MPEG stream available via one of the DVB adaptor devices, typically /dev/dvb/adaptor0/dvr0. For this, you need to specify at least the -r option. If you have more than one tuner and want a different device, for example /dev/dvb/adaptor3/dvr0, use the option '-a 3' as well. You will also probably want to use the -S option to stop the status output every second.

tzap -r -a 3 -S 'SBS digital 1'

You can then copy the stream to a file or view it with mplayer, for example:

cp /dev/dvb/adapter0/dvr0 foo

or

mplayer /dev/dvb/adapter0/dvr0

or distribute via network with nc (nc has more options)

#Server
cat /dev/dvb/adapter0/dvr0 | nc -l -p $PortNum
#Client
nc $ServerName $PortNum | mplayer -

Exiting after tuning

The -x option tells tzap to exit once it has tuned the tuner. This is only of interest if you don't want to do anything more; when tzap exits, the connection to the tuner also goes away.


There are 2 processes running where recording DVB:-

  • zap drives the device output stream.
  • the other process writes to a file.

It is best to run from a script which runs zap in the background while waiting for the record interval to expire. The following example accepts channel name, record time, and exits cleanly.

#!/bin/bash
# record ATSC transport stream
# tested with HVR-1950, UHF antenna, and Sabayon Linux
#e.g. ./tv2.sh WIVB-HD 3600

echo "[ ./tv2.sh channel=$1 seconds=$2 ]"
PREFIX=`date +%F-%H-%M` # part of filename
FNAME=~/Videos/${PREFIX}_$1.ts
   echo "..Selecting the DVB-T channel"
   ( azap -r $1 > /dev/null 2>&1 )&
   ps1=$!
   echo "..Starting record of ${FNAME}"
   ( cat /dev/dvb/adapter0/dvr0 > ${FNAME} )&
   ps2=$!
   echo ..Waiting $2 seconds before kill of $ps1 and $ps2
   sleep $2
   kill $ps2 $ps1
   echo Bye..
#

Footnote

For users in North America note that szap uses an LO of 10000 for the STANDARD Ku lnb definition. To make szap work with a standard Ku band lnb in North America you can either edit the source code replacing 10000 with 10750 for the STANDARD lnb or run szap like so .....

 szap -l 10750 -r CHANNEL