DVR



index.png

Resume

Essays

Resources



nav.png

Home
Up


Turning a beige mac into a DVR.


After I change to a mac Dual G5, I decided to conserve the old beige mac because this equipment have this ‘legacy’ technologies such as floppy, serial ports, Zip, SCSI and can boot with MacOS 9, nevertheless I wanted to continue using it and not simply store it, so I decided to turn the mac into a DVR, this was easier since the machine had been improved with several previous updates:

  • G4 533Mhz
  • 288MB
  • disk 40GB
  • Firewire 400 card
  • USB-1 card
  • VGA Adapter
  • Combo DVD/CD-RW
Only the disk seemed very little, so I change to a 80GB disk, using XPostFacto is possible to run 10.3.

I was thinking using HackTV carbon as a capture program, this is Apple’s example program, this program nevertheless have two deficiencies:
  • Don’t auto-renumber the capture files
  • It’s not Applescript enabled

I started using a mini-DV videocamera as the capture hardware, using the connection Firewire and HackTV recording in format DV (720x480) used 12GB/hour, similar to which iMovie uses.

I tested several formats of compression in the end I decided to use MPEG-4 for video and AAC for audio, codec 3ivx gave the best results, with a size of 320x240 the video have a similar quality to VHS and used about 700MB/hour.

The as an alternative to the use of the videocam,I buy the XLR8 Interview 3,0 adapter, which is a USB-1 device, which captures video, but no audio, it’s necesary to use the audio-in port to capture the sound. This device captures 320x240 wich was the size that I wanted.

The XLR8 comes with a the program USBVision, this program seems to be an extended version of HackTV, in fact it shares the preferences, and it solves both problems of HackTV, it’s possible to control the recording with Applescript and has the option of auto-renumber the captured archives.

In spite of the name, USBVision also can capture from the videocamera using Firewire, another reason to think that this based on HackTV. As a capture codec the program brings a codec also called USBVision, using this codec the movie used about 4GB/hour.

Because now the mac is going to be used with a TV, I added the AVerKey100 Pro box, which convert the VGA output to Composite Video or S-Video. I found the program cscreen wich allows to change the resolution to 640x480, which is seen well in TV.

Reviewing information in the Internet about similar systems I found MythTV, which is much ambitious system that what I wanted, nevertheless have a link to a Perl program wich allow to control a DirecTV box, since I am a subscriber of DirecTV, I decided to test the program called Sony.pl, preferring Python to Perl, I converted the program to one called setDTV.py.

Once I conected all the devices I have:
../esp/dvr1.jpg


For the videocamera, it is connected to the Firewire instead of the USB and Audio-In is not needed.

My DirecTV box uses a standart DB-9 connector for the serial port, so I need a mini-DIN to DB-9 adapter:
../esp/dvr2.jpg


At first I used a few applets of Applescript to control the recording, I needed to put the applet as a Startup Item and set the correct time to power on the mac, that was a lot of manual work, so I decided to create a program to control the different applications with Applescript.

I decided to create the program with Applescript Studio, being an opportunity to learn it, since it was the first time that I used this environment, although I already have experience with simple applets created with Script Editor.

An extra objective was to try to automatically power on/off the devices (mac and DirecTV) , since the mac uses near 40W, and the DirecTV like 24W, is clear that I do not need to maintain them always active, neither equipment has a modality of ‘sleep’ that could have been the alternative. For this I put a cable connected to the power output of the monitor of the mac, the I connected the power adapter of the AverKey box and an extra plug to connect the DirecTV box, therefore now whenever the mac power on, the other boxes are also power on.

Reviewing the Apple’s documentation, I created a program called powerOn to schedule power on events to the mac.

So the program TV Cron handles:
  • USBVision, to capture video
  • cscreen, to change the resolution to 640x480
  • powerOn (through the shell script setPowerOn) , to schedule power on events
  • setDTV.py, to change channels of the DirecTV
  • date (through the shell script setDate) to synchronize the hour

Two shell scripts are used, setPowerOn and setDate, because powerOn and date needed a administrative password to run, this password need to be put in the shells, these programs must be copied to /usr/local/bin where they are protected (I hope) by the mode, this avoid to have to put the password in the main program, which is a greater security risk.

The other programs, cscreen, powerOn and setDTV.py also must be copied to the directory /usr/local/bin, the program seek them in that directory.

In the end the program TV Cron perform:
  • at the start, setting screen with cscreen, normally 640x480 so we can read in TV using AverKey box
  • at the start, load from Preferences a table with dateTime, task, channel and repeat, sorted by dateTime
  • at the start, if flagDirecTV, sync clock of the mac with the clock of DirecTV using setDTV.py
  • start/stop application "USBVision Capture" for recording
  • reload repeat events to next oportunity
  • when a change in tasks, save the tasks in Preferences
  • when idle for 2 minutes, shut down the mac
  • when quitting, use powerOn to schedule the next automatic power on of the mac

And only use about 900 lines to obtain the 10 objectives!

But additionally you need to edit the captured archives, also I found a problem when compressing the archives, the sound was unsynchronized to about a second each hour, this gave rise to a group of applescripts, to be used from the Script Menu with QuickTime Player Pro, I use the most:
  • split, allows to cut the movie in the present position, a new file is created in the beginning
  • split rest, similar to split, but the new file is the rest
  • set interval, allows to mark start/end of selection, is easy to me to use this script that the tiny controls of QT Player
  • sync sound auto, to resincronize the sound
  • merge to folder, to merge several archives


Plus two applets:
  • comp files&halt, compresses archives and the power off the mac (using cron)
  • stop halt, cancels the power off of the mac


These two last ones, are used while I decide how add compression within TV Cron, in tests apparently is possible to capture while simultaneously a movie is compressed, although the mac only run at 533MHz.




N.B.: The graphs of this page were created using SqueakLand.org, which is a pre-loaded Squeak package for use of schools, it is used like a normal application, publishing projects (archives with extension .pr) locally or in the network, besides of drawing tools and presentation, comes with a graphical form of programing called EToys, useful to teach programming to children.