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.

20 comments:

lefty.crupps said...

Brilliant concept and yet a very simple script, well done. What TV Capture Card do you have? are you using over-the-air broadcasts or Cable television? In the USA we now have digital broadcasts over the air, so a 2yr old card probably wouldn't work here any longer...

xiao_haozi said...

What tv tuner card are you using?

bjb1959 said...

I use Mythtv it is a little harder to set up but has great how-tos out there and it isn't rocket sciene. It can be set to any geometry by default through the setup screens or can be started in windowed mode with a simple mythfrontend -w -geometry 800x600 as an example. It can be used as a simple TV or as a complete PVR or DVR to record your favorite shows. here is a screenshot of windowed mode http://bartburroughs.hopto.org/mythtv-windowed.png

bjb1959 said...

forgot to mention, you can use the up and down arrows or number pad for channels. You can Pause live tv, you can use the left arrow to go backwards in live tv if you missed something that was said etc. It's a great program.

dandart said...

Tried Kaffeine? The first few paragraphs seemed to describe it. As long as you have dvb, it works pretty well.

Rms-Mit said...

This will be very useful for my little project. It's my 1st attempt at C++ and QT (I don't want it dependent on KDE thought because I want it desktop neutral).

I'm trying to write a little TV daemon. The idea being that the daemon would run regardless of what desktop or user or even if no desktop or user logged in yet and just handle the TV Schedule recordings and viewing etc . .

This would mean a any GUI app could talk to it by D-bus and set a schedule recording and even if that user logs of and another user logs in it would still record as scheduled. If you want to just watch TV it would just record it to a temp file and the GUI app could launch a player to play the file as it's being written too (or embed it's own player).

I only intend this to be a proff of concept as I don't want to be too ambitious on my 1st project but your scripts should help me out a great deal.

Thanks

Rms-Mit said...

Just been reading through your script. Are you using a analog card? with the audio coming in on a separate sound card (through a loop back cable or something)?

Azerthoth said...

Question answering time.

Using a kworld plustv HD120, so it is capable of ATSC. Sadly as there is no broadcast TV here, and as the script shows I am using composite video run out of a cable box.

As for Kaffeine, I hate to break this to you, that project died with KDE 3.x.

To the audio question, I am running that separately into line-in and have that set in alsa as the audio capture device.

Azerthoth said...

p.s. for those who commented and got deleted, be constructive not derisive.

diddy1234 said...

Good idea

I also use a script to record tv (not for watching tv) and this schedules recordings using at command.

The script will schedule a recording to start at a set time and then transcode on the fly into mpeg4 and store the video in the users home/video folder.

The file generated saves with the channel name and time and date of the recording.

more details here :-

http://ubuntuforums.org/showthread.php?t=1259274

Greg said...

Kaffeine works fine, and works well as a PVR or as a simple a viewer. Kaffeine also has it's own channel scanner that is much simpler than creating channels.conf. Changing channels is as easy as clicking on a list. It also contains all the normal recording functions of PVR, making it an easy VCR replacement.

I run Kaffeine under KDE 4.3.4 and the latest version of Kaffeine from SVN.

It did not die with KDE 3.5 as suggested above, and continues advancing. If you do not want a full Myth TV setup Kaffeine is great, and will work under Gnome as well.

Me-TV is also an option. It also has it's own scanner and recorder functions.

I use mine (digital TV only) with a Winfast DTV2000-H and also a Gigabyte U7000 USB dongle. The Gigabyte needs firmware added manually on Debian distros, Ubuntu supply it in their non-free firmware package (so just grab it out of there for other distros).

There are many ways to run TV under Linux - take your pick.

Ak Sağlık said...

I am happy to find this very useful for me, as it contains lot of information. I always prefer to read the quality content
TüpBebek

alene12378 said...

Can I make a suggestion? I think youve got something good here. But what if you added a couple links to a page that backs up what youre saying? Or maybe you could give us something to look at, something that would connect what youre saying to something tangible? beachbody coach Just a suggestion.

Karlo tagalog said...
This comment has been removed by the author.
Maddox said...

I happily like most things in Linux. Application for watching TV on Linux is great.
Snoring Remedies
Insomnia in Early Pregnancy

Maddox said...

I like what you guys are up also. Such clever work and reporting!
Snoring Help

hiumeshSINGH said...

Impressive publish, I never thought about it by doing this. Stumbled!
Web Designing
Property in Noida

Deon Eve said...
This comment has been removed by the author.
Deon Eve said...

I like program for watching TV with your linux box.
Home Energy

Hair Transplant in turkey said...

Comments made ??about the issues impressed me. I like your site.
fue Saç Ekimi Fiyatları