Thursday, May 13, 2021

Short tutorial: Digital Television with GStreamer (ATSC setup)

GStreamer support for Digital Television (DTV) is still working. If you follow a few very simple steps you can get DTV signals tuned-to, captured, decoded and displayed with your computer and a few accessories. 

This short article presents basic instructions for a working DTV setup. I use ATSC in the US as an example, but the short process should work equally well for other terrestrial delivery systems and countries.

What hardware do you need?

Beyond a computer, you will need an antenna and a capture device. I recently tested a Hauppauge WinTV-dualHD (ATSC/QAM) USB dongle with a 5-years old Amazon basics flat indoor antenna (that looks pretty much like this one) and it worked quite well at roughly 60km from the repeater station.


The hardware setup is simple. Install the antenna pointing to your repeater station and as high as you can. Your local telecommunications and/or broadcasting association should have data about repeaters near you. You can get this information by ZIP code from the Federal Communications Commission (FCC) if you are in the US.

Don't stress about the "as high as you can" part of the antenna installation. It's great to have a uninterrupted and direct line of sight to the repeating station's antenna, but this is hard to accomplish in urban areas. My current test system is indoors, on a first floor, and it works fine for a few channels.


You will need GStreamer. I'm building it from the master branch with gst-build but the DTV code hasn't changed much in the last few years so any recently-packaged version should work for you. You will also need dvbv5-scan from DVBv5 tools.


Build a channels.conf configuration file by scanning an initial set of frequencies for your area with dvbv5-scan. You can get initial-frequencies files from the the dtv-scan-tables repository. Here I'm using my Mountain View, California file as an example:

$ dvbv5-scan -o channels.conf ./dtv-scan-tables/atsc/us-CA-Mountain-View

The scanning can take several minutes.

If you grep the resulting file you can see what channels were detected:

$ grep "\\[" channels.conf

The output should look something like this:

[Hai Le]

If you get no channels, and you have reasons to believe your hardware is working correctly, try repositioning your antenna and rescanning till you get some. Small direction and position changes can have big effects on VHF/UHF reception with semi-directional antennas like the flat one I'm using for this example.

To playback a channel with GStreamer you can use the generated channels.conf configuration file and any of the scanned-channel names to let playbin/dvbbasebin figure out all necessary parameters at runtime

$ GST_DVB_CHANNELS_CONF=channels.conf gst-play-1.0 dvb://KNTV-HD

And that's it.

There are lots of details, pitfalls and options I don't write about in this short tutorial but if there's some interest I will try to discuss the subject in more depth in future ones.

I leave you with two screenshot of the HD feed by KNTV in the bay area







stuaxo said...

Can it handle getting more channel from a multiplex at once ?

I used to have a set-top box with two tuners, but you could record two channels and watch a third as long as it was within a multiplex being used by one of the two recorders.

I bought 4 dual USB Digital TV tuners, which is more than enough to cover UK TV, any idea how I can set this up to record every channel to a buffer, but then also be able to extract any program from that buffer ?

reynaldo said...

Hi Stuaxo. For each tuner/demod (adapter) in your setup you can capture an entire channel transport stream with all its virtual/sub channels with something like this:

gst-launch-1.0 dvbsrc frequency=503000000 delsys=atsc modulation=8vsb bandwidth=AUTO ! filesink location=capture.ts

You can specify what adapter to use by passing a number to dvbsrc:

gst-launch-1.0 dvbsrc adapter=0 ...

You can get the necessary tuning parameters from the channels.conf file you created with dvbv5-scan.

This example is again using ATSC but you get the idea.

Hope it helps!

stuaxo said...

Thanks, I'll definitely give it a try - my idea is to have something like a buffer of for each tuner (not sure if this can be split into something like 1GB files automatically).

Then somehow, for watching channels (or grabbing programs that are still in the buffer), they would be fetched out of the buffer into their own files.