banner
Previous Page
PCLinuxOS Magazine
PCLinuxOS
Article List
Disclaimer
Next Page

LC Channel Scan For USB TV Tuner ... Simplified


by Paul Arnote (parnote)

I have an older (as in, no longer manufactured) USB TV tuner that is capable of receiving ATSC broadcasts. In the U.S., ATSC is the format for the over-the-air (OTA) HD broadcasts. It's a KWorld KW-UB435-Q V3. Ironically, while this specific tuner is no longer made/available, it's a trivial task to find a picture of the item on various retailer websites. The broadcast format will be different for different areas around the world. If I'm not mistaken, most of Europe uses DVB as the broadcast format for their HD broadcasts.



Even if you are in an area that uses a different format, the process will be similar to discover the frequencies necessary to make the USB tuner "spring to life" under VLC. I'll attempt to point out the differences the best that I can. Keep in mind that my "frame of reference" is using the ATSC broadcast standard, since I'm in the U.S., so I'm quite unfamiliar with other broadcast standards.

Most likely due to the explosion of online streaming platforms, computer-based (particularly USB based) TV tuners are a bit harder to find these days. But, there are still users out there who either already have these devices, or who have a need for these devices.

In my particular case, we recently purchased a RV/camping trailer, and I can use the USB TV tuner to tune in the OTA broadcasts on my laptop in the areas we visit with the trailer in tow. This will be perfect for those times when it's rainy or too dark to do the things we want to do, and allow us to help keep ourselves informed of the latest happenings in the world while we're out and about. It also increases our entertainment options considerably to be able to receive OTA TV broadcasts.

To enable VLC to playback OTA broadcasts from a compatible TV tuner card, you first have to tell VLC what broadcast stations are in your area, along with the frequencies for those stations. Your solution is to install w_scan (a simple command line program) from the PCLinuxOS repository.

While I routinely rescan my OTA channels on a regular basis (every month or two), I still have difficulty remembering the exact command line switches to use to perform the channel scan. Every. Single. Time. I have to look up the help information for w_scan to apply the proper/appropriate command line switches.

Plus, when visiting different areas with different broadcaster stations, I also needed a way to keep the channel listings unique for each area. Otherwise, I'd be doing the channel scans more than I need to as they get overwritten by subsequent channel scans. So, I created a bash script to automate the process. That process also ensures that each channel scan is given a unique name, where the location for that set of channel data and the date of the scan is specified in the filename where the channel information is stored. That way, not only can I tell at a glance what area any channel list is for, but I can also tell when that last scan was done. In the latter case, if the list is too old, it serves as a reminder for me to rescan for any new or changed broadcast stations.


The Script

Without further delay, below is the script that I created to handle the issues I spelled out above. Line numbers are included to make it easier to recognize each line of the script.



The script is a short 12 lines (subtracting out the 4 blank lines inserted to aid readability). Line 1, of course, is the bash shebang that starts all bash scripts.

Line 3 sets an integer to the value of "1". We'll use this integer to break out of the while loop later in the script.



Line 5 asks the user for the locale for the channel scan list. Since I live in the Kansas City area, I enter "KC" for my channel list at home. And yes, you can even enter spaces in the locale name, so "Des Moines" and "Los Angeles" are all perfectly acceptable. Just keep in mind that spaces in Linux filenames isn't the best idea in the world. If I had my druthers, I'd just skip the space and run the two words of the name together (e.g., DesMoines or LosAngeles … or even just LA).

Lines 6 through 8 check to see if the end user selected the "Cancel" button, and allows the script to exit gracefully if they did make that selection.

Line 10 sets up the "while" loop to proceed so long as "n" equals "1". Line 11 sets up the command(s) to execute if the conditions in the "while" loop are met (is true). Line 12 executes the w_scan command, applies a unique filename (location and date included), and outputs the information to the VLC *.xspf file.

Line 13 sets "n" to "0" (zero), allowing us to break out of the "while" loop and allow the script to complete.



Line 14 marks the end of the "while" loop, and displays a pulsating progress dialog box. This way, the end user has a visual reminder that something is actually happening "under the hood." Otherwise, it would just be a big guess about when the script actually finishes. As the text in the zenity dialog box states, the dialog box will automatically close when the task is complete. On my computer and in my area, w_scan typically takes about five minutes to run to completion.

Line 16 allows the script to exit cleanly when everything is finished.

To use the script, save the script to your hard drive (I hope you store your custom scripts in a directory that's in your PATH statement). Mark it as executable, and then just enter the script name at a command line prompt. I call the script vlc-channel-scan.sh. You will be prompted for the ONLY data you need to provide, which is the location/locale. If you're in another part of the world, you may need to alter the command line switches used in the script's implementation of w_scan (which we'll cover next). You can also download the script from the magazine website. Save the script to your favored place to store your scripts, remove the ".txt" file extension, and make sure the script is made to be executable.


A Closer Examination Of The w_scan Command

First, let's take a look at the options available for use with the w_scan command.

Below is the w_scan command as I used it in the script. Let's dissect it to gain a better understanding of what's going on, and what you might need to do to tailor the script for use in your part of the world.

w_scan -f a -A 1 -L > "$LOC-Channels-$(date "+%F").vlc.xspf"

The -f a part tells w_scan what type of information I'm seeking. In my case, I want ATSC data, since I'm in the U.S. Users in other parts of the world may want to use "t" instead of "a" as the type.

The -A 1 part tells w_scan what type of ATSC data I'm searching for. The choices are terrestrial (1), cable (2), or both (3).

The -L part tells w_scan to output the channel list as a VLC xspf playlist file. As you can see, there are other options for mplayer, xine, and dvb. Even though the VLC output is listed as "experimental," I've found that it works exceptionally well.

You can also optionally specify the country code for the area you are in. For me, that would be -c US. To see a list of all of the country codes for w_scan, simply enter w_scan -c ? on the command line.

Then, the output is redirected (">") to the file that is named as follows: the location/locale, the words "Channels-", then the date (YYYY-mm-dd), then "vlc" to remind the user that this is formatted specifically for VLC, and finishing up with the xspf file extension that's unique to VLC playlists. The xspf file is placed in the current working directory where you started the script. So, you will need to either cd to the directory you want to store your channel lists in, or move them there later, or just leave them wherever they end up.


VLC Using The Playlist

Below is the channel playlist displayed in the Playlist window of VLC.



And below is the VLC playback window.



(Trust me … it's X-Files, not Buffy The Vampire Slayer (as the VLC title bar says), of which I've never seen a single episode).

As you can see from the playback list, I have 53 OTA channels to choose from. Granted, there are several of them I'd never watch (really? Home Shopping Network?). Honestly, there are a lot more OTA channels than I thought there would be in my area. Of course, I can remember when I was a kid, and there were a grand total of six channels to choose from … ABC, CBS, NBC, two independent stations, and a PBS station.

Depending on your area, you may have more or fewer OTA channels in your playback list.


Equipment

So, you will need a TV tuner card or adapter that is supported by Linux. There are a LOT of Windows-only tuner cards and tuner adapters out there, so not every tuner card/adapter you find will necessarily work under Linux. To get an idea about whether a specific card will work under Linux, check out the Linux TV Wiki. Search for the card/adapter you're thinking of getting (or have found) and see what the reports are on it. Surprisingly, there are way more adapters/cards reported as working with Linux than I originally thought.

You can find some USB TV tuner adapters around, but you will have to dig a bit. Of course, you'll look on sites like Amazon and Newegg, but don't discount Ebay. On the latter, you can find "used" adapters for next to nothing. You can also find "new old stock" for adapters that, even though they aren't manufactured any longer, are "new and in the box." I recently picked up a second KWorld USB TV tuner adapter identical to the one I already possess for just $25. It was "new old stock." I picked up a second one, simply because I know it already works under Linux.

You will also need a HDTV antenna to plug into the card or adapter. While the older style of "rabbit ears" antenna will work, you'll get a far better quality image with a HDTV antenna. You can find these just about anywhere, and can usually be found as inexpensive as $15 (U.S.). Expect to pay more for antennae that have extra features, like signal boosting, signal filtering, and whatnot.

Aside from that, you'll just need VLC and w_scan from the PCLinuxOS repository.


Summary

It can be handy being able to watch OTA broadcasts right on your Linux desktop. On the night of June 7, we had severe thunderstorms roll through town around 1:30 in the morning. Those severe storms were complete with tornadic activity, torrential downpours, and very high winds. Our NOAA weather alert radio woke us with the alerts. Since my wife had to work early in the morning, I got up to monitor the situation. Instead of turning on the TV and risking waking the kids, I watched the live weather coverage on one of the local stations on my PCLinuxOS desktop until the storms had safely passed through my area.

Plus, once we get the RV camper ready to roll (we have a few things we need to do to it), it'll be nice (and fun) to watch OTA broadcasts from the different areas we go to. And, I can do it all on my laptop running PCLinuxOS, if I choose.

In an upcoming article, we'll take a look at how to do something similar in MPlayer. There are pluses and minuses to using the versatile media toolkit to play live OTA TV broadcasts … and lots of caveats, potholes, and pitfalls that might leave "less technical users" convinced that MPlayer is not up to the task. But … more on that in that future article.



Previous Page              Top              Next Page