X11 Forwarding

A few days, I moved my desktop computer out into the living room. The computer has a tuner card that can receive digital broadcasts. I don’t own a TV, so this is the closest I’ve got to one. I still have to set up lircd before I can use a remote, but I wanted something a bit easier

Today, I discovered a new trick … SSH X11 Forwarding. Now, I can play video on my desktop right from my netbook. It’s wonderful and very simple!

In the following instructions, the “A” refers to the computer playing the video and “B” refers to any other computer.

  1. Make sure “X11Forwarding Yes” is in your sshd_config file on computer A. Restart sshd if you had to uncomment/add it.
  2. On B, run `ssh -XC A`
  3. In the ssh session, type `DISPLAY=:0.0`.
  4. Now run mplayer or any other video player in the  ssh session and it will play on computer A.

If you want  to have a program run on computer A and use the screen on computer B, the process is very similar:

  1. Make sure “X11Forwarding Yes” is in your sshd_config file on computer A. Restart sshd if you had to uncomment/add it.
  2. On B, run `xhost A`
  3. On B, run `ssh -XC A`
  4. Now run mplayer or any other video player in the  ssh session and it will play on computer A.

Step 2 authorizes use of the current display by computer A and only needs to be run once. Also, note that the display variable doesn’t need to be set when using B‘s screen.

Mplayer works wonderfully when playing on my desktop, plus I control it via the ssh session. It has tons of keyboard shortcuts. The ones I use the most are space for pause and the arrow keys for skipping around.

PVR Update

In anticipation of TV shows coming back on, I’ve been tweaking my PVR scripts. These record shows from the digital airwaves right onto my computer. I’ve separated the script into two parts: recording and encoding. Each is a simple one line shell script that can be called easily from the command line or from a cron. The record.sh script is:

/usr/bin/mencoder dvb://$1 -ovc copy -oac copy -o "$2.mpeg" -endpos $3

All this does is copy the video and audio streams directly to the disk. The three parameters are  the station name, as stated in ~/.mplayer/channels.conf, the filename and the end position. This end position can be the number or seconds to record, or a time format of hh:mm:ss. This makes recording fairly simple within the cron.

The encode.sh script contains:

/usr/bin/mencoder -vf scale=640:-2 -ovc xvid -xvidencopts bitrate=1700:threads=2 \
 -oac copy "$1" -o "$1.avi"

This, slightly more complex use of mencoder, will scale the video to 640 wide, the height calculated to keep the aspect ratio. The video is encoded into xvid at 1700kbps using 2 threads. To speed up the encoding process, the audio is not re-encoded, but copied as is.

You will need to play with the number of xvid threads to find the best fps. I have a dual-core and it encodes the fastest with 2 threads. It does need to be an integer, and most dual-cores will work best at 2.

Then, two lines are required in the cron to record and encode the program:

59 19 * * 1 /dvr/record.sh WAGTNBC /dvr/shows/heroes 01:03:00
05 20 * * 1 /dvr/encode.sh /dvr/shows/heroes.mpeg

ffmpeg Cheat Sheet

ffmpeg is a video encoder for linux. This tool is very versatile and can do pretty much any kind of video processing all from the console.

As with any linux tool, there a tons of bells and whistles. This makes the learning curve kind of steep, but with a bit of determination anyone can make sense of it. Without further ado, here’s the cheat sheet:

ffmpeg -i clip1.avi -i clip2.avi -vcodec copy -acodec copy new-clip.aviCopies clip1 and clip2 into new-clip.avi
ffmpeg -i clip.avi -vcodec libxvid -b 800000  -acodec libmp3lame -ab 128 new-clip.aviEncodes a clip with the xvid codec at 800Kbps and mp3 audio at 128Kbps.
ffmpeg -i clip.avi -t 00:05:00 -vcodec copy -acodec copy new-clip.aviCopies the first 5 minutes from clip.avi into new-clip.avi
ffmpeg -i clip.avi -t 00:05:00 -ss 60 -vcodec copy -acodec copy new-clip.aviCopies 5 minutes from clip.avi into new-clip.avi, skipping the first minute.
ffmpeg -i clip.avi -s 640:576 -vcodec libxvid -b 1200000 -acodec copy -o new-clip.aviResizes the video to 640×576, then encoding video using xvid at 1200Kbps and copying the audio directly
ffmpeg -i clip.avi -target ntsc-dvd -b 5000000 dvd-clip.mpegEncodes clip.avi into a dvd-compatible mpeg at 5000Kbps

Mencoder Cheat Sheet

Mencoder is a video encoder for linux. It is part of the mplayer package which also includes a video player. This tool is quite versatile and can do pretty much any kind of video processing all from the console.

As with any linux tool, there a tons of bells and whistles. This makes the learning curve kind of steep, but with a bit of determination anyone can make sense of it. Without further ado, here’s the cheat sheet:

mencoder clip1.avi clip2.avi -ovc copy -oac copy -o new-clip.aviCopies clip1 and clip2 into new-clip.avi
mencoder clip.avi -ovc xvid -xvidencopts bitrate=800  -oac lamemp3 -lameopts cb:br=128 -o new-clip.aviEncodes a clip with the xvid codec at 800Kbps and mp3 audio at 128Kbps.
mencoder clip.avi -ovc xvid -xvidencopts bitrate=800:threads=2  -oac lamemp3 -lameopts cbr:br=128 -o new-clip.aviSame as above, but uses 2 threads for the xvid encoding.
mencoder clip.avi -endpos 00:05:00 -ovc copy -oac copy -o new-clip.aviCopies the first 5 minutes from clip.avi into new-clip.avi
mencoder clip.avi -endpos 00:05:00 -ss 00:01:00 -ovc copy -oac copy -o new-clip.aviCopies 5 minutes from clip.avi into new-clip.avi, skipping the first minute.
mencoder dvb://WJBF-DT -endpos 01:0000 -ovc copy -oac copy -o ugly.betty.mpegTunes to WJBF-DT, records 1 hour of that station to ugly.betty.mpeg
mencoder clip.avi -vf scale=640:-2 -ovc xvid -xvidencopts bitrate=1200:threads=2 -oac copy -o new-clip.aviResizes the video to 640 wide, keeping the aspect ration, then encoding video using xvid at 1200Kbps and copying the audio directly
mencoder tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0 -ovc lavc -o >(tee webcam-`date +%Y-%m-%d-%H.%M.%S`.avi | mplayer -cache 128)Records the webcam to “webcam-yyyy-dd-mm-hh.mm.ss.avi”, where that is the date, and display it to the screen while recording.
mencoder -idx clip.avi -ovc copy -oac copy new-clip.aviFixes the AVI index of clip.avi, the output being new-clip.avi
mencoder clip.avi -vf cropdetect -o /dev/nullDetects what cropping is needed
mencoder clip.avi -of mpeg -mpegopts format=dvd -lavcopts vcodec=mpeg2video:vbitrate=5000:acodec=ac3 -o dvd-clip.mpegEncodes clip.avi into a dvd-compatible mpeg at 5000Kbps
mencoder -dvd 2 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o dvd.aviRips a DVD to dvd.avi

Using Subversion for Server Backups

Last month, I lost the template for Barry Bakes. I was ultimately to blame for it for 2 reasons:

  1. I had altered the default template without copying everything to a new folder.
  2. I had no server backups running.

After a few iterations, I came up with an ingenious way to use subversion and rsync to handle my backups and not waste megabytes every day from duplication. Also, this method doesn’t leave you with a folder full of backup folders. There are 2 folders, the svn repository and the rsync folder.

To do this, you must generate dsa  or rsa keys for passwordless logins.

To set it up svn, you must do the following:

svn create /path/to/svn/repository
rsync -azvv --progress server:/path/ /local/path/
cd /parent/of/local/path/
svn import folder file:///path/to/svn/repository -m 'Initial Import'
rm folder -rf
svn co file:///path/to/svn/repository

Note that everything in bold must be replaced with your specific values. Once that is done, run this shell script once a day to commit changes to subversion:

#/bin/sh

/usr/bin/rsync -azvv --delete --progress server:/path/ /local/path/
cd /parent/of/local/path/
/usr/bin/svn status |
	/bin/grep '^?' |
	/bin/sed 's/^?       /svn add "/g' |
	/bin/sed 's/$/"/g' |
	/bin/bash
/usr/bin/svn status |
	/bin/grep '^!' |
	/bin/sed 's/^?       /svn delete "/g' |
	/bin/sed 's/$/"/g' |
	/bin/bash
/usr/bin/svn commit -m '`date +%Y-%m-%d`'
/usr/bin/svn update

That will update and commit the changes to subversion. It comments the date in yyyy-mm-dd format for each commit. Plus, now you can checkout any date (revision) you want!

Happy Backup

Laptop Fn Keys

On a laptop, there are a few keys that have a blue icon on them. These are function keys. They work when you hold down the blue “Fn” key, which is normally next to the Ctrl key.

There are tons of Fn keys. Not all will have the same icons on them. If you want to know what yours do exactly, there should be an easy to read table in your manual. If you don’t have the manual or can’t find it, check the manufacturer’s website.

Standard Fn Keys

There are volume and mute keys . Look for a speaker. One will be crossed through or X’ed out, that’s mute. Volume up will have a lot of sound waves coming out. Volume down will have small sound waves.

Also, there are two brightness keys. These look like a small computer screen with an icon in the middle. To brighten the screen, hold down Fn and press the one with the larger icon. Use the smaller icon to make it darker.

Another key will control the monitor. It should have two screens on it with a slash between. This will flip back and forth between the laptop screen and the monitor.

There’s usually a Number Lock. Sometimes, you’ll get a Scroll Lock or System Request, even though neither of those keys is really used today.

Bonus Fn Keys

There are a few keys that aren’t on all laptops. One is the wifi key. This will look like an antenna with waves coming off either side. It turns the wifi on and off.

You may have a bluetooth key. It will have that trademark bluetooth icon. You can guess what that one does.

Another key is the sleep key. The icon varies greatly. It may be some Z’s on it, but it will definitely remind you of sleep.

Is GHz per Watt the new measure?

We have reached a plateau when it comes to speed limits for CPUs. We may not see anything higher than 4 GHz in the near future.  This doesn’t mean that the computer can’t be better or faster. Multicore processors are fairly common today, allowing more than one section of code to run simultaneously. Computers are also dropping their power requirements, and let’s face it, we all want to be green, especially if it means a small electricity bill and keeping some green in our pocket.

Chip manufacturers are now touting about their CPU’s power consumption. Laptops are where this is the major selling point. Less electricity used means a longer battery life. Also, if it can do the same amount of data processing, you can have the same level of productivity for a longer amount of time. Wouldn’t we all want a laptop that can play 4 flash movies and not stutter a single one?

The desktop market hasn’t seen anything to the point of GHz/Watt. That’s because the folks in marketing think no one really cares how much electricity that computer’s going to use, unless you’re a computer dork like me running around the house with your brand new kill-a-watt.  I found an article on Wikipedia, they’ve listed pretty much every known CPU, their power requirements, speed and MHz/Watt or GHz/Watt.

Sure, there’s more to that computer than a CPU. There’s RAM, a hard drive, monitor, keyboard, mouse, USB ports and devices, network connections, fans, and other chips to support everything from video to audio to that fancy SATA II interface blu-ray burner you just had installed. Where are the power requirements, in Watts, for all these devices? Can it be found? Is it even available?

If the data can be found, could a normal high school graduate understand it? Would they even care? I’m betting most people won’t.

Wipe & Reload Windows Every 6 Months

Most people think a computer runs slower and slower as it ages. This is entirely false. In fact, with updated drivers for your hardware being released, your computer should run slightly faster as it ages. So, why does your computer slow down? There are many reasons:

  • Adware
  • Viruses
  • Startup Programs
  • Uninstalled Programs
  • Hard disk fragmentation

The list just goes on and on. Any computer tech can tell you that all of these problems can be handled without formatting the hard drive and reinstalling everything from scratch. I agree, so long as you are willing to spend days, possibly weeks, tracking down that illusive virus and running all sorts of programs to clean the registry, defragment, etc.

There is a quicker and easier way. Wipe & Reload. It may sound scary, but in fact it’s not. Doing this will guarantee there is no virus left lurking on your computer. On top of that, you’ll have a fresh backup of all your files, so if a disaster happens, you’re prepared.

NOTE: I recommend having another computer connected to the internet and a jump drive, so you can download the network drivers in case Windows doesn’t install them by default.

Prep

The first step is to back up all your data. I do not mean creating a full backup of your hard drive. 99% of the files you will want are in My Documents. If you backup everything under “C:\Documents and Settings”, you should be well covered. DO NOT backup the “temp” or “Temporary Internet Files”, as viruses live there and you don’t need anything in those folders.

NOTE: I take no responsibility for lost files you forgot to back up!

The second step is to look in “Add/Remove Programs” and write down anything you want to reinstall.

The third step is to locate your Windows key. This is a 25 character code. It is usually written on a sticker on your computer.

Reinstalling Windows

Once all your data is backed up and you have a list of programs to install, slide your Windows XP CD into your computer and restart. Press any key when it tells you to. Now, go through step by step.

  1. No, you do not want to recover.
  2. Yes, you agree.
  3. Delete the partition.
  4. Install to the “free space”.
  5. Format using NTFS. NOT QUICK!
  6. Let it do it’s thing. It will reboot do not press any key when prompted.
  7. Enter your code when asked.
  8. Answer any other questions.

That’s it. Windows XP is now reinstalled.

Installing Drivers

Now, to see what drivers need to be installed:

  1. Right click on My Computer.
  2. Click on Manage.
  3. Click on Device Manager.

Anything with a yellow exclamation point needs a driver. Most manufacturers will offer drivers on their website. I recommend going this route instead of installing them off a disc because driver updates are common and you ever knows how old that driver disc is.

Installing Software

  1. Install your anti-virus software.
  2. Install all Windows updates available.
  3. Install any programs you had that you wanted to keep.

The Data

Special attention is required during this step to keep the viruses and other malware off your computer. Put in each backup CD/DVD one at a time for a virus scan. This may take a while, if you have more than 1 disc.

If there is a virus, the software won’t be able to heal/remove/fix it because the CD/DVD is read-only at this point. Make a note of any file containing a virus. Now, just copy over any file that didn’t make the infected list.

OK, your wipe & reload is now complete. Now, do a few more tweaks to get the most performance.

NOTE: I recommend having another computer connected to the internet and a jump drive, so you can download the network driver.

Recycling Your Old Electronics

We all try to be environmentally conscious, but what do you do with that old TV that stopped working? No, there is no recycle symbol on that TV. That doesn’t mean you should put all that plastic, glass, gold, mercury, copper, silicon, etc. in the landfill.

Odds are that there is an electronics recycling day every 6 or 12 months in the closest major city. You can find out by searching the local newspaper’s website. Usually, the TV news will overlook such valuable information. Here in Augusta, GA, there is one on Fort Gordon, an army base, and another downtown at Fort Discovery, a science museum.

They will take TVs, computers, monitors, keyboards, mice, speakers and stereos. Usually, they will not take stoves, ovens, microwaves, refrigerators, or any other large appliances. Make sure to check what they will and won’t take.