Wednesday, January 13, 2010

Watching TV and Linux

This all started a couple of weeks ago when I finally got around to putting the tv capture card I had picked up a year or two ago into my computer. Happily like most things in Linux, it just worked, that was a great plus. Sadly the software packages in existence that I ran across were either too much or too little, nothing was just right.

What I wanted was to be able to open up a window, tack it to the desktop in always on top mode, and leave it in the corner taking up some but not all of my screen real estate. I also wanted the ability to pause it, so that I could get up, grab a cup of coffee, hit the head, or what ever. Guess what, this falls into the "good luck with that" category of having had someone scratch that particular coding itch.

For the watching TV in a window, I found several applications, such as tvtime and xawtv. Both are good and configurable. Excellent for what they were designed for which was simply just watching TV, either in a window or fullscreen. Sadly of all of the light weight applications I played with they all lacked the second critical function, the ability to pause. So while I decided to keep tvtime on my system because it is rather a nice piece of software the search must continue.

I decided then to explore mythtv. I had read about it several times over the years and finally had a reason to do more than think about it. I knew that it had the ability to record TV, watch movies, and basically handle being a home theater system. Holy unfriendly overkill batman. By the time I had it compiled (I was doing this on a Funtoo system) I was mildly annoyed at the collection of dependencies that had to be pulled in. That annoyance was nothing compared to trying to configuring it.

Between the documentation, complete and utter lack of editable configuration files, a configuration UI that is among the unfriendliest and unintuitive I have ever seen, and an IRC help channel slightly less friendly than the Spanish Inquisition. I think maybe I would prefer to spend a month at a nudist colony with a porcupine infestation than get near that project again.

OK, enough of a sideline about mythtv, needless to say I did get it up and running. I then decided that while it was not completely unsuited to that task at hand, it was exactly what I did not want. Not to mention it still didn't do exactly what I wanted. Which was simply a window in the corner that I could play/pause.
** It was brought to my attention that mythtv will indeed start in a windowed mode
** thanks for correcting my misstatement Dinotrac. Still it's a level of overkill I do not need.

So I decided to set about doing for myself what I could not find an existing application for. While I had been playing with the capture card and software for it, I found that I could watch TV using mplayer, or record TV using mencoder (part of mplayer). Armed with this dangerous knowledge I figured I could wrap everything up in a script to do what I wanted. I was right too. With one script I can watch TV, play/pause, and as an added bonus, when I close the window I was using to watch TV, it asks me if I want to save the streams I had been watching.

There are only two packages that you need for this script, mplayer and xdialog. Actually xdialog is only if you want it to ask you if you want to save the streams and easy file clean up. Alternately you could just change that portion of the script to : rm $location/$filename.avi to have it clean out all the files when you shut mplayer off.

So here you go:
Click here for the script

UPDATE:
Added file rename when save file is selected. Cleaned up spurious text for those using dialog rather than xdialog. Broke up the mencoder command for easier reading and added deinterlacing to it.

Version 2 of the script

Blogspot mangles code snippets, so its in a pastebin. Personally I dropped the script into /usr/bin/ did chmod 755 on it, and use it as I would any other program. So you could make a desktop shortcut, add it to a menu or do what I did. I mapped it to a spare unused key on my keyboard, so now I have TV at the push of one button.