Tuesday, May 20, 2014

Super-simple way to tune HdHomerun tuners and record their output

Rev 7/4/22 (see Notes)


This article describes a simple, dirt-cheap system for using a basic HDHomerun tuner to record OTA broadcasts "on the fly" in their native format to a PC running Ubuntu or one of its derivatives. (I prefer Kubuntu for my PVR, partly because, as of this writing, using Kubuntu 22.04, the KDEnlive video editor can be installed on it with a download of only about 57MB, which is small for a video editor with its capabilities.) I've used this system for years without feeling that it needs to be improved. It consists of a set of shell scripts which can be launched by clicking on them, and thus act as buttons, each of which sets a particular HDHR tuner (0,1, etc.) of an HDHR unit to a particular channel and subchannel ("program"), then requests a name for the .ts file to be used for storing the program, which ends up in the directory which conains the scripts. When a script is launched, the corresponding tuner-section (0,1, etc) is set to the corresponding channel and subchannel, and a terminal window appears and requests a name for a file to contain the tuner's output. Then, when a name is entered and Enter is pressed, the tuner's output is stored in the designated file, until the terminal is closed. I've created a directory for the shell scripts for each tuner-section (0,1, etc), and the files produced by the corresponding tuner are stored in the same directory.

Another name for "shell script" is "bash script," where BASH is an interpreter which sequentially converts each command in the script to a lower-level language and sends it to the OS. The first line in a bash script is always "#!/bin/bash," which declares it to be a bash script and launches the bash interpreter. To run the script, it's necessary to give it execute-permission (right-click on the file, select Properties, then Permissions, and then the execute-permission box), which can also be done with the 'chmod 700 <path/filename>' command. It's also sometimes necessary to tell the computer how to run the script, such as by telling it to open it with bash and to run it in a terminal (this is done once, after which any bash script would be launched by simply clicking on it).

Here's an example script, named 4-1_KVOA.sh (avoid spaces in file names, in case they end up getting used in commands). It's for recording Tucson station KVOA [1] with HDHomerun s/n 1038702F Tuner 0:

#!/bin/bash
hdhomerun_config 1038702F set /tuner0/channel auto:23
hdhomerun_config 1038702F set /tuner0/program 1
echo "Enter desired name for ts file"
read filename
hdhomerun_config 1038702F save /tuner0 $filename.ts

"Echo" just displays the specified prompt on the command line, "read" assigns whatever is subsequently entered to the variable "filename," and $filename is the value of the variable 'filename.' The HDHomerun commands can be found in hdhomerun-config "manpage," or by entering "hdhomerun-config -h" after installing hdhomerun-config. You'll also need hdhomerun-config-gui to gather information for the scripts. As far as I've been able to determine, the GUI is available only for Ubuntu and its derivatives.  

I had some trouble finding a way to get the scripts to run in Kubuntu 22.04, so I'll describe my solution: Right click on the file, select "open with other application," then in the box which appears, enter "bash," and enable it to run in the terminal. If that works, you would do it again and make it the default method, although you might not want all shell scripts to run in the terminal, in which case you would create an exception for each script which you don't want to run in a terminal. Then, you can simply click on the file and select "open" in the box which appears ("execute" didn't work for me). A terminal will appear with the prompt "Enter desired name for ts file," and you would enter the name and hit Enter, and the recording process should begin.

Naturally, the HDHomerun "config" software (hdhomerun-config) would have to be installed, which in Linux is done through the package manager if you have a direct 4G or better internet connection. (If you don't have such an internet connection, see AnAptOfflineBlog.blogspot.com.) I doubt that you'll have to update the package index to install just HDHR - you could check the relevant Packages site, such as Ubuntu Packages, to see if there have been any revisions to the HDHR packages or any dependencies since you performed an update.

You might also have to set up the ethernet connection with the connection-management utility, which is typically found in the system-settings section of the main menu. If your tuner is connected directly to your computer, instead of through a network, all you have to do is to turn the tuner on and to set the connection's IPv4/Method option to "Link-local only," and the connection should then set itself up automatically. Then you could launch the hdhomerun-config-gui, scan for channels, and press View in the GUI to view them on VLC.

Notes

Rev 7/4/22 - Rewrote the entire mess, and added some information I've learned since first writing it.

[1] KVOA is virtual channel 4.1, which broadcasts on Tucson physical channel 23, Program 1. Note that the virtual subchannel's number isn't always the program-number, as you probably notice when scanning through the channels and examining the subchannels.

Monday, May 12, 2014

Easy way to grab frames from .ts files in Linux

The VLC player will play .ts files obtained from TV broadcasts (obtained as indicated below, although I now recommend formatting Personal Video Recorder/PVR hdd's with the Ext4 format). However, VLC doesn't do such a good job of stepping through .ts files frame by frame, as you will find if you try it. 

So, I tried OpenShot, but I couldn't find a way to get it to extract frames at full resolution, and it eventually played a dirty trick by replacing itself with an error message. 

OpenShot's dirty trick backfired, because as a result I went on to discover that VLC does an excellent job of stepping through .ts files which have been converted to an mp4 format by Handbrake, with essentially zero effort and little if any loss of resolution. The conversion can take a long time, but you can convert just the sections of interest, one at a time, by specifying the range for each conversion, which you can obtain by "sliding" through the .ts file with the VLC player.

VLC doesn't have a button to step backwards, but you can use the slider to "rewind" the video a bit if you overshoot, and then step forward with the single-step button. Once you find the frame you want, you can save it with the snapshot button.

Monday, July 1, 2013

Fill out scanned forms with GIMP

I don't know what I did wrong when I first tried to use GIMP to insert text into a scanned form, but I came away with the impression that it's designed to add a very limited number of potentially very fancy text-images to a given image, and not a sufficient number of simple text-images to fill out a form. But I just gave it another shot, and found that its text tool makes it a snap: just select the text tool, click on the image where you want to insert text, and enter text in the box that pops up.  When the pop-up box is closed, the text appears right where you told GIMP to put it, and you can adjust its font and size in the text-tool window, and watch the effect on the text just inserted.

Wednesday, June 26, 2013

Startup Disk Creator seems to be sensitive to flash-drive brand (Rev B)

Rev B (see Notes)

After blaming Startup Disk Creator (in the previous post) for its apparent inability to create an AMD 64-bit installation of Ubuntu on a PNY flash drive (although I didn't mention the drive name), it occurred to me the failure, which followed success with another brand of drive (Verbatim Store 'n Go), might not be due to some change in Startup Disk Creator, but due to the change in the brand of the drive, as strange as this seemed. So, I tried installing the 12.04 AMD 64-bit version on another 2GB Verbatim S&G drive, and it worked without any hitch whatsoever. Later, I tried it with a Sandisk Cruzer, and had no problems at all.

I'm not the only one who's noticed this problem with using PNY's for this purpose - go here and search for PNY. One possibility is that Startup Disk Creator might decide to insert defects in the AMD 64-bit installation after realizing that the target drive is a PNY. (Note that the brand is displayed in the Device section of SDC's GUI when you insert the drive.) Although this might seem paranoid, it's the only way I can explain why one of the most popular flash drive brands behaves differently than it does when using Universal USB Installer from PenDriveLinux.com. (It might not be the only one that has this problem, but I'm not about to go out and buy a sample of each variety of flash drive, and try to install the various types of ISO's on each one.) 

Notes
Rev B: Added Sandisk Cruzer to the list of drives with which I succeeded in installing the AMD 64-bit version of 12.04, revised text for clarity, and deleted extraneous statements.

Tuesday, January 29, 2013

Vnstat for internet data metering

To keep track of your internet data consumption, I recommend vnstat.  To install it, log onto the internet, open a terminal-window (CTRL-ALT-T) and enter "sudo apt-get install vnstat." Then, to check your data usage, all you have to do is open a terminal-window and enter "vnstat." At least that's all it took in my case.  Vnstat can do a lot more, too, but it's so compact, and so easy to install and use, that there's no point in searching for something dedicated to monitoring internet data consumption, or something with a graphical interface.