Playitsam: Play, Edit & Export TiVo TyStreams

Version 1.43, January 2002. (c) Warren Toomey, GPL license.

This release of Playitsam (v 1.43) is considered experimental. Please see the section on `TYSTREAMS AND MPEG-2 OUTPUT' below.

This program allows you to play a video stream on your TiVo, to edit out unwanted sections (e.g ads), and to export the stream to an external storage area. From there, you can use Playitsam to play the stream back again.

The program was inspired by an executable-only program called Playback which was released by `the Doctor' in the Dealdatabase TiVo Hacks Forum. I wanted an open-source version, so I wrote Playitsam.

Features of Playitsam:

Playitsam is based on the vplay program written by Andrew Tridgell; in fact, I have converted his MFS routines into a library. Because of this, Playitsam is released under the GPL license. The on-screen display routines come from tivovbi by Embeem.

INSTALLATION ON TIVO

Playitsam comes as a gzipped tarball which contains the source code, this documentation and a TiVo binary called tplayitsam. I've only called it this so that if you accidentally type make to make the non-TiVo version of the program, it won't overwrite the TiVo version.

You should copy tplayitsam over to your TiVo to wherever you have installed other binary tools, and rename it to be playitsam. Remember to chmod it 755 so that it is executable.

INSTALLATION ON UNIX

If you want the non-TiVo version of Playitsam, simply type make. This will produce a binary called playitsam which you can copy to /usr/local/bin on your system. The make will also make the tyserver program, which allows you to make your Unix box into a TiVo stream server. Again, copy it into /usr/local/bin. Make sure both are executable with a chmod 755 on both.

Note: The make will try to compile tplayitsam, and will fail if you don't have a TiVo cross-compiler installed. This isn't a problem because I have provided the tplayitsam binary. At present, I am using mmap() in the tyserver program to speed up I/O across the network. If your Unix system doesn't support mmap(), then edit or remote the first line in tyserver.c to turn off the use of mmap().

To run Playitsam on a non-TiVo system, you will need the mp2 audio playback tool Amp, and the MPEG video playback tool Mpeg2dec. You could use mpg123 instead of Amp, but you would need to edit the playitsam.h file.

Help: Apart from mmap(), the tyserver.c code should be easily ported to a Win32 platform. Could someone do this, and return the diffs and the resulting tyserver.exe program so I can include it in future releases?

RUNNING THE PROGRAM

Playitsam is run on both TiVo and non-TiVo systems as follows:

% playitsam [-v] [-n] [-p] [-M] [-D] inputsource [outputsource]
If you are using Playitsam on the TiVo, then before you run it, you should make sure that there is no writing on the screen. Either go to Live TV and clear the green bar, or start playing an existing recording. If you don't, then you will have to put up with writing on the screen!

The input source follows this naming convention:

Here are some examples:

% playitsam -                       # Standard input

% playitsam 45887                   # TiVo FSID for stream

% playitsam 10.10.1.1:the_bill      # Stream from a tyserver

% playitsam ../my_hero              # Unix file

The output source is optional, and will only be used if you go into Record mode (see below). The options here follow the same naming conventions as above:

The run-time options are:

-v   Be verbose when running. It's only really useful for debugging Playitsam.

-n  Don't play the stream using the audio/video device. Just print out details of the editing.

-p  Only play the stream back, don't go into editing mode. Obviously, -n and -p are mutually exclusive.

-M  On the TiVo, restart MyWorld when Playitsam ends normally.

-D  On the TiVo, disable on-screen feedback of the editing process.

When Playitsam starts up, it will firstly try to kill off the EventSwitcher on the TiVo, which gives it exclusive use of the audio/video devices. So, it's a good idea to use the -M switch to restart them when Playitsam is finished. If you chose -p, then Playitsam will go straight into Play mode and play the stream. Otherwise, Playitsam will go into Edit mode. If you chose -n, then the EventSwitcher won't be killed.

EDIT MODE

In edit mode, you can go forwards and backwards through the stream, and mark cuts to make. Then, when you go into Play or Record mode, the sections of the recording that you have cut will be skipped. If you are playing from standard input or from the tyserver, then you cannot edit the input stream.

The original input source is not altered by your editing operations; only the playback of the stream, or the exporting (recording) of the stream will be affected.

Edit mode starts by playing the input stream. A cut is marked starting at the first chunk, but with no end yet. This assumes that your program starts with something you don't want. If not, it's easy to clear this pending cut.

You can edit the stream using the Unix keyboard, or the TiVo remote. Here are the commands available on the keyboard:

KeystrokeOperation
spaceToggle pause & playback
fGo forwards 1 chunk
1,2,3Go forwards 5, 25, 125 chunks
4,5,6Go forwards 500, 2500, 12500 chunks
0Go to the last chunk and pause
bGo backwards 1 chunk
!,@,#Go backwards 5, 25, 125 chunks
$,%,Go backwards 500, 2500, 12500 chunks
)Go to the first chunk
c, sMake a cut starting at this chunk
eEnd the current cut at this chunk
kKill (delete) the current cut
KKill all the cuts made so far
lList the cuts made so far
PGo into Play mode to play the edited stream
RGo into Record mode, and export the edited stream
q,Q,ctrl-CQuit Playitsam

If you are using Playitsam on the TiVo, then you can also use the TiVo remote control to do most of the above editing operations. Here is the mapping of TiVo remote buttons to operations:

remote_usage.gif

When you pause on the TiVo, and assuming that you haven't selected -D, then you will see the chunk number that you are up to. If you start or end a cut in pause mode, then this will be announced on the screen for you.

Information about the chunk numbers and the cuts you make are also shown on the login/telnet connection.

RECORD MODE

If you choose to go into Record mode from Edit mode, then the stream minus the cut material is exported to the named output source. I've found that TCP data transfers off the TiVo are much faster than with NFS, so if you do want to export to a remote device, I would recommend that you set up a tyserver.

Every 100th chunk, some information is displayed to let you know that the recording is actually working. When the edited stream is finally exported, Playitsam will exit normally, and will restart MyWorld if you specified the -M option.

PLAY MODE

If you choose to go into Play mode from Edit mode, then Playitsam will go back to the first chunk. It will pause for 10 seconds before starting the playback; this is so that you can get your VCR ready to record the program. Hint: if you are recording to VCR, then before you go into Play mode, find a black chunk and pause on it in Edit mode. This will start you off with a blank screen before the playback begins.

During the 10 second initial delay, Playitsam will print out a countdown, so you can work out when the playback will start.

RUNNING THE TYSERVER

It is only useful to run the tyserver if you have a TiVoNet connection from the TiVo to a Unix box. On the Unix box, run tyserver and name the directory where you keep your exported streams, e.g:

% tyserver /usr/local/streams &
The directory should exist, and obviously should be writable by you if you want to export streams from the TiVo to the directory. The tyserver will open up TCP port 1150, and wait for commands from the TiVo. There are only 3 commands at the moment. LIST will get a list of files from this directory, and Playitsam doesn't use this at present. SAVE is sent by Playitsam when it goes into Record mode, and names the new stream's filename. Straight after that, the stream is sent down the TCP connection. Finally, the PLAY command is sent when Playitsam goes into Play mode; an existing file is named, and the tyserver sends this file back to Playitsam for playback.You can of course nominate a read-only directory like /cdrom, but you will only be able to play streams back from this directory.

For security reasons, only run the tyserver on a private network which is not accessible from elsewhere. There is no authentication with the tyserver, and a malicious person could fill up your hard disk with streams!

REMOVING TYSERVER STUTTERING

You might find that playback from the tyserver has a lot of stuttering. I have found that there are at least two reasons for this:

Firstly, you need to tune the TCP options on your Unix box so as to increase the TCP receive window and the TCP send window; this helps to keep the TCP stack transmitting and receiving data in the face of the inevitable LAN collisions. On my FreeBSD box, I run these sysctl commands at boot-time:

/sbin/sysctl -w net.inet.tcp.recvspace=65536
/sbin/sysctl -w net.inet.tcp.delayed_ack=0
/sbin/sysctl -w net.inet.tcp.sendspace=131072
I don't have a Linux or Windows box, so I can't tell you how to do the same tweaking on these systems. if you can supply details, I would be grateful.

Secondly, you need to get a decent CD-ROM drive, if you are going to play streams back from CD-ROM. I was initially using an 20x ATAPI CD-ROM drive and playback was awful. I found that the drive was continually speeding up & slowing down, and this was causing the stuttering. I now have a 16x SCSI-2 CD-ROM drive, and now I rarely get any stutters on playback.

However, to really get rid of the stutters, use the tyserver and not NFS or SMB, tweak your TCP options, and copy the stream to hard disk instead of playing from CD-ROM.

TYSTREAMS AND MPEG-2 OUTPUT

The TiVo native video stream format (aka tystream) is a proprietary multiplexed MPEG-2 stream. If you use Playitsam to extract a tystream intact (i.e without making any cuts), then you should be able to use the other TiVo stream tools (vsplit which is included, tyc, splitstream, TyConvert etc.) to convert this into a standard MPEG-2 file.

This release of Playitsam (v 1.43) is considered experimental. I have altered the method of making cuts in the tystream as follows. I try to find MPEG-2 Group of Pictures (GOP) markers in the tystream chunks. If you wish to make a cut start or cut end, then you can only do this to a chunk that has a GOP marker; not all tystream chunks have these markers. If you did a cut start, then I remove the video data from the GOP marker onwards in that chunk. If you did a cut end, then I remove the video data before the GOP marker, but not including the GOP marker.

I believe that this is still too simplistic a method of cutting sections out of a tystream. However, the program code is now more modular, and if there is a more knowledgeable MPEG-2 person out there, they should find it relatively easy to fix the cut mechanism. I also don't think I'm getting the synchronisation between audio and video correct, either.

In the long term, I want Playitsam to correctly cut so as to maintain the MPEG-2 audio and video streams, and also to do the MPEG-2 multiplexing on record, so that you can export valid MPEG-2 streams directly after editing, as well as the tystreams.

BUGS AND OMISSIONS

Firstly, treat this as beta quality software. It seems to work for me fine, but then I only wrote it a few days ago and there are sure to be bugs lurking in the program. I have a standalone TiVo running version 1.3 of the software, so I have no idea if it will work on other systems. Please BACKUP your system before you run this, as I cannot take any responsibility for lost data or a damaged system.

The TiVo video stream is a proprietary MPEG-2 stream. Because of the way it is structured, you will find what looks like blocky or corrupted images when you go forward or backward frames. This is normal, and is due to the fact that MPEG-2 streams encode differential images as well as full images. So when you skip data, or play stuff back in the wrong order, then you will get artifacts like this.

Hint: if you are in pause mode and are going backwards, go backwards more chunks than you need to, and then come forwards. This helps to bring the video back into `sync' so that it is uncorrupted again.

The Mpeg2dec program on a non-TiVo often dumps core when you jump chunks or go backwards; this is because it doesn't expect an MPEG-2 stream which is jumbled as much. I might try to fix it so that it doesn't dump core, but tries to resync on the jumbled input.

If you have any questions or comments, please e-mail me at wkt@tuhs.org.

Warren Toomey, January 2002.


File translated from TEX by TTH, version 2.78.
On 26 Jan 2002, 09:56.