Video: Part 1 – Time Shifting (Recording) TV Programs

by Paul Arnote (parnote)

I have to be perfectly honest. I do have a computer with WinXP on it still in the house. It's there for one special reason: to record television programs for later viewing, and to edit videos. Until quite recently, I had not been able to find a suitable Linux application to perform either task. Most "television" applications in Linux, like the popular TVTime, allow you to only watch television programs. Sure, some applications exist to allow you to record television programs, but only after you've earned your PhD in that application are you then able to perform (what should be) this relatively simple task. As for editing those video recordings, the tools are definitely there (and have been all along), but it isn't until you dig deeper into these tools that you uncover their hidden (and often well disguised) capabilities.

While I'm being honest here, the lack of support for video recording (from a TV tuner card, or otherwise) in Linux, along with the lack of adequate video editing software, has been a "sore spot" for me ever since I started with Linux over four years ago. Before I was "enlightened," back when I was a Windows user, I was knee-deep into video recording and editing. When I started with Linux, there was virtually nothing that allowed me to perform these tasks – tasks that I had become accustomed to performing with my computer.

Our Windows counterparts, like it or not, have a much easier time with both of these tasks. There are many, many choices for video recording applications, as well as many, many options for video editing applications. Our OS-X brethren (I call them brethren, since OS-X is somewhat based on BSD, another *nix-like system) also have a lot more choices for well written applications to perform these tasks. Meanwhile, we Linux users are the red-headed step-children of the software world, when it comes to video recording and editing applications.

So, like any self-respecting Linux user, I sought to find solutions to these problems, these, these software omissions. Being the self-respecting Linux user that I am, the kind who cringes and feels "dirty" whenever he has to use a Windows computer in his own home, I did the only thing I could do, after not finding any suitable video recording applications:I made my own. I also have to admit that I was inspired to see this through by Leiche's efforts on his MyMencoder application (which we'll be taking a look at next month, by the way).


Amazingly enough, it wasn't as difficult to make the recording application as I had thought it would be. PCLinuxOS PVR (Personal Video Recorder) is simply a bash script that's been dressed up with a GUI, thanks to gtkdialog. Here is what it looks like:


PCLinuxOS PVR can be installed on your computer running PCLinuxOS, via Synaptic.

Before we can record video from our TV tuner card, we first have to pass some instructions and parameters along to control the resulting video file.

Selecting Video Input Device & Channel


At the top of the window, we select the video recording device. Some users may have web cams attached to their computers, and others won't. Some users may even have two TV tuner cards installed on their computer. Because there is no way to predict the wide variety of hardware configurations a user may have, the user will have to select which V4L or V4L2 (Video For Linux and Video For Linux 2) device they want to use to record from. This also allows the user to record from their web cam (if they choose), since the user has the ability to choose that web cam as the input source for their video recording.

On my system, the TV tuner card is labeled as /dev/video0. If you don't know how the label for your TV tuner card (or any other video output device) on your system, open a terminal and simply type lshal |grep video on the command line. Scroll back through the output, until you find the line linux.device_file =. The information on the right side of the "=" is the label for your video output device.

We also have to tell the TV tuner card what channel to tune to so we can capture our video. In my case, since I'm recording everything from a digital cable converter box, my channel is always set on channel 3. Obviously, if you are recording off-the-air programming using rabbit ear antennae or an external TV antenna, you will need to specify the channel that you wish to record from.

Encoder Settings


In the next section of the PCLinuxOS PVR window, we need to pass along some parameters to control our video recording.

The first entry is "Video Bitrate". Before you go and automatically choose the highest video bitrate you can, a word of caution is in order here. The higher the video bitrate, the higher the quality of the recorded video. But that also means that you will have a MUCH larger file. Higher video bitrates = higher quality video files = larger video file sizes. PCLinuxOS PVR defaults to a video bitrate of 300 kbps. This results in a small file, but also one with quite marginal video quality. Videos recorded at this low video bitrate are suitable if you are recording a television program to view later on your computer monitor, and you're not looking to save it. If you are looking for better quality video (say, you want to record it to DVD later on), video bitrates between 1000 and 2000 kbps typically give pretty good results, and allow you to fit close to 4 hours of video onto a DVD. If you are looking for the best quality video, then video bitrates of 5000 kbps and higher are what you are looking for. You can enter any number you want here, but I definitely would not recommend entering a value less than 300 kbps, nor higher than 8000 kbps. The easiest is to simply select a video bitrate from the drop down list that is provided.

Below is an example of the output of a video recorded with PCLinuxOS PVR, recorded at 2000 kbps video bitrate, played back in the Xfce Parole Media Player.


Under the second entry, "Frames per second (FPS)", you can set the frames per second that is used for your region of the world. In the United States and Japan, NTSC is the standard, and it presents video at 29.97 frames per second. In most of Europe, PAL is the standard, and it presents video at 25 frames per second. Films are typically shot at 24 frames per second. Can you see how confusing this becomes? It gets even worse when you factor in HD recordings. For now, just choose the frame rate that is most suitable for your region of the world.

The next entry, "FourCC", can be skipped for now. It has not yet been fully implemented. The FourCC code is used exclusively by the AVI file format, and identifies the codec used. Once implemented, this will allow users to record video that can be played back on a DVD player that recognizes and plays back DivX encoded AVI files. Many DivX encoded AVI files will fit about 2 hours of decent quality video on a regular CD-R. Also, users who choose to use XviD (an open source alternative to DivX) can "trick" those DVD players into thinking it's a DivX encoded AVI file, merely by changing the FourCC code.

The fourth entry, "MP3 Bitrate", allows you to set the quality level of the sound you record. The default value is 128 kbps, which typically produces acceptable stereo quality sound. Just as with the video bitrate discussion above, the higher the MP3 bitrate you set, the larger amount of space (within the video file) your sound will occupy, but also resulting in a higher sound quality. Fortunately, the sound of a video only occupies a fraction of the space within a video file, compared to the video. This entry field allows you to either select from the preset values in the drop down list (128, 160, 192 or 256), or enter your own MP3 bitrate. Currently, the MP3 sample depth in PCLinuxOS PVR is locked at 41,400 Hz, or 41.4 KHz.

While I'm talking about the audio, let me give you a tip here. My TV tuner card has a stereo patch cord that outputs the audio from the card to the Line In input on the sound card. If you start getting video recordings without sound, check to insure that you have your Line In capture activated in your audio manager.

Under the "Format Container" entry, I recommend (for now) just leaving it set for AVI. I have future plans to include the ability for the user to choose to record video as MPEG 1, MPEG 2 and Ogg-Theora (*.ogv) files. It is not yet fully implemented at this time.

Under the final entry, "Select a recording length (minutes)," you set how manyminutes you want to record from your TV tuner card (or other video output source). Enter ONLY minutes here, and enter ONLY whole numbers. Thus two hours becomes 120 minutes. Four hours becomes 240 minutes. Three hours and 36 minutes becomes 216 minutes. You can either select from the preset recording lengths listed in the drop down list, or enter your own values. Your recording will automatically terminate after the number of minutes you specified has elapsed.

The "button" controls


At the bottom of the PCLinuxOS PVR window are the buttons that control the starting and stopping of a recording, along with exiting the program and getting more information about PCLinuxOS PVR.


The "About" button brings up the dialog shown above.

Selecting the "Record Video" button starts the video recording at the instant that you click it, and using the parameters you specified in the "Encoder Settings" section of the window.

If you want to stop a recording before the specified amount of time has elapsed, simply click the "Stop Recording" button. Your recording will immediately cease.

Selecting the "Exit" button exits the PCLinuxOS PVR application.

Future Plans

I've already revealed some of my future plans for enhancing PCLinuxOS PVR: implementation of the FourCC code, and the ability to record to video file formats other than just AVI. I also want to allow the user to choose the MP3 sample depth (48,000, or 48 kHz audio is typically required for DVD authoring).

The really big thing to add (and most important, at this point) is the ability to set up timer recordings. In its current state, you have to be sitting in front of PCLinuxOS PVR to start the recording. What I want is the ability to set a timer to record a program in the future, without the user sitting in front of the computer, and without any additional user interaction with PCLinuxOS PVR. With this addition, it will be possible for you to set a timer that will automatically record Wheel of Fortune on Friday evening, while you are out having dinner with your family. When you return from dinner with your family, you can sit and watch Wheel of Fortune at your leisure, just as you can with a VCR or DVR. I am beginning to get my head wrapped around all the stuff that is needed to implement this feature (believe it or not).


As you can see, PCLinuxOS PVR has the potential to grow, and I'm currently working on implementing that growth. Still, as it sits today, it gives me something that I never had before: an easy to use, reliable way to record quality video from my TV tuner card, with minimal effort. Sure, it only records in the AVI format at this time, but it gives me more than I had before, which was nothing. That alone is a milestone, at least for this Linux user.

See? There's not much that a self-respecting Linux user can accomplish, once he or she puts their mind to it. Sometimes, it just takes an unwillingness to be shunned by the rest of the computing world to spark those accomplishments.