# tivodecode with TS support



## moyekj (Jan 24, 2006)

I have tivodecode sourceforge project on my sourceforge watch list and yesterday got an email about a patch to tivodecode. The original source code of patch can be found at:
http://sourceforge.net/tracker/?group_id=183716&atid=906362

This apparently adds mpeg2 Transport Stream (TS) support to tivodecode. Previously tivodecode only supported decrypt of TiVo files in mpeg2 Program Stream format.

This should be useful for the folks in Australia & New Zealand that have option to download TiVo files in Transport Stream format. If USA series 3 or beyond TiVo units ever get that option with a software update (I hope we do since TS downloads are much faster than PS downloads) then hopefully it will work here as well.

I had to make a couple of changes to tivodecode.c to make it work properly with metadata dumper from TiVo files used by kmttg but other than that seems to work fine for metadata dumping & decrypting for PS TiVo files. Supposedly should work for TS TiVo files as well but I can't test that.

For lack of better place to put it as part of kmttg project I've made this patched version of tivodecode available:
Source
Win32 binary


----------



## wmcbrine (Aug 2, 2003)

Sweet. I was worried that the tivodecode project was dead. I made a half-hearted attempt to understand it myself, and gave up... but I'd been thinking of getting serious about it and trying again, because we need the TS support.

Could you please outline your changes? I'm not finding them in the ChangeLog. But I did find that your version wouldn't build on Ubuntu -- 'unrecognized command line option "-mno-cygwin"'.

On a US TiVo, you can add "&System=ts" to the download URL for a recording, and get something that the old tivodecode can't handle -- though I can't be sure it's a transport stream, since it doesn't decode. Unfortunately it still doesn't work with "0.3pre1", either (segfaults).


----------



## moyekj (Jan 24, 2006)

wmcbrine said:


> Sweet. I was worried that the tivodecode project was dead. I made a half-hearted attempt to understand it myself, and gave up... but I'd been thinking of getting serious about it and trying again, because we need the TS support.
> 
> Could you please outline your changes? I'm not finding them in the ChangeLog. But I did find that your version wouldn't build on Ubuntu -- 'unrecognized command line option "-mno-cygwin"'.
> 
> On a US TiVo, you can add "&System=ts" to the download URL for a recording, and get something that the old tivodecode can't handle -- though I can't be sure it's a transport stream, since it doesn't decode. Unfortunately it still doesn't work with "0.3pre1", either (segfaults).


For making your own build you should 1st run ./configure before make. That should setup proper Makefile to build on your system.
There is no Changelog. I grabbed the source code that was posted by some gracious anonymous user and just made a couple of changes to tivodecode.c to get the "-D" option working properly. Since the code was just a patch posted by anonymous user there is no source code changelog available or description of all changes that were made. Running diff on several files reveals quite a lot of changes though.

The "&System=ts" does not generate a usable TS TiVo file. This version of tivodecode I believe will work for Aus/NZ systems with the "&Format=video/x-tivo-mpeg-ts" url option. For current 11.x software for USA systems adding that option does not produce TS TiVo files, but hopefully in a future Series 3 update and/or upcoming new hardware/software from TiVo it will.


----------



## moyekj (Jan 24, 2006)

FYI, was able to build from source on a Red Hat Enterprise 4 Linux system, so should compile on other Linux systems very easily as well. The stupid zip file maker I used messed up permissions, so you have to make configure executable, but very simply to make on Linux (or Mac OS for that matter):
chmod +x configure
./configure
make


----------



## wmcbrine (Aug 2, 2003)

Ah, it does have a configure script, doesn't it.  I guess I just expect a "make distclean" before archiving, so it throws me off when there's already a Makefile.

Re: the ChangeLog, it's not much, but there is this, in the "0.3pre1" version:


```
0.3pre1:
        * add support for TS files.

        * known bug :
        Packet N of PID XX starts a new series of PES headers, which spill over into
        packet N+1 of PID XX, which has an encrypted payload.  The problem is how to
        cleanly make that "continuation" from packet N to N+1, such that the offset
        into Packet N+1 can be determined where the decrypt needs to start.
```
But I was looking for a description of the differences between "0.3pre1" and your "0.3pre2". I ended up doing a diff -- basically you're reversing a few unexplained changes in 0.3pre1 that didn't seem to make sense. :up:


----------



## moyekj (Jan 24, 2006)

I noticed the windows stdin/stdout piping patches were not part of this distribution so I applied those to make 0.3pre3. I updated the links in 1st post of this thread accordingly. The source now preserves proper permissions and was tarred up after make distclean for a clean start.

I suppose at some point I should post my changes as a patch back at sourceforge along with some comments of changes I made for continuity sake.
EDIT: Just added my source code changes as patch to sourceforge site.


----------



## scop (Jan 21, 2010)

Hi, I am an Australian Tivo HD user and have just started using TTG. This caught my attention as I just noticed that tivodecode was choking on the TS file that is the default download here. Unfortunately, I tried testing this patched version but it is still not working.  Thanks for the heads up anyway, if I can do any more testing to help fix it I am happy to do so.


----------



## scop (Jan 21, 2010)

Sorry, I had placed the patched files in the wrong place! It is working.


----------



## scop (Jan 21, 2010)

More news, the resulting mpg file is frozen at the first frame and refuses to play!  This is using VLC Player.


----------



## moyekj (Jan 24, 2006)

What does mediainfo report for both the TiVo file & the decrypted TS file? Have you tried a player besides VLC?


----------



## scop (Jan 21, 2010)

Mediainfo reports the following:

*Tivo File:*

General
ID : 1
Complete name : D:\Tim\My Documents\My Videos\TiVo Recordings\Paul Merton in China (Recorded Jan 10, 2010, ABC HD).TiVo
Format : MPEG-TS
File size : 4.21 GiB

Video
ID : 2314 (0x90A)
Menu ID : 1 (0x1)
Format : MPEG Video
Encryption : Encrypted

Audio
ID : 2315 (0x90B)
Menu ID : 1 (0x1)
Format : AC-3
Format/Info : Audio Coding 3
Encryption : Encrypted

*
Decrypted mpeg file:*

General
ID : 1
Complete name : D:\Tim\My Documents\My Videos\kmttg\Paul Merton in China (Recorded Jan 10, 2010, ABC HD).mpg
Format : MPEG-TS
File size : 4.21 GiB
Duration : 1h 0mn
Overall bit rate : 10.0 Mbps

Video
ID : 2314 (0x90A)
Menu ID : 1 (0x1)
Format : MPEG Video
Format version : Version 2
Format profile : [email protected]
Format settings, BVOP : Yes
Format settings, Matrix : Default
Duration : 1h 0mn
Bit rate mode : Variable
Bit rate : 8 889 Kbps
Nominal bit rate : 90.0 Mbps
Width : 1 280 pixels
Height : 720 pixels
Display aspect ratio : 16:9
Frame rate : 50.000 fps
Standard : Component
Resolution : 8 bits
Colorimetry : 4:2:0
Bits/(Pixel*Frame) : 0.193
Stream size : 3.73 GiB (89%)

Audio
ID : 2315 (0x90B)
Menu ID : 1 (0x1)
Format : AC-3
Format/Info : Audio Coding 3
Duration : 1h 0mn
Bit rate mode : Constant
Bit rate : 448 Kbps
Channel(s) : 2 channels
Channel positions : L R
Sampling rate : 48.0 KHz
Video delay : -806ms
Stream size : 192 MiB (4%)

*I have now tested this on 3 media players:*

VLC Player - frozen at the first frame
WIndows Media Player 11 - nothing, just a black box and an error message
Media Player Classic Home Cinema - interesting, it works, but it is riddled with an annoying wave of blocky pixellation every couple of seconds or so.

HTH, Tim.


----------



## wmcbrine (Aug 2, 2003)

scop said:


> More news, the resulting mpg file is frozen at the first frame and refuses to play!  This is using VLC Player.


I've seen this myself on regular old program streams. If I manually skip past the beginning, they work, IIRC. But mostly I just feed them through ffmpeg and/or back to a TiVo, and there hasn't been a problem there, so I haven't worried much about the freezing.


----------



## scop (Jan 21, 2010)

wmcbrine said:


> I've seen this myself on regular old program streams. If I manually skip past the beginning, they work, IIRC. But mostly I just feed them through ffmpeg and/or back to a TiVo, and there hasn't been a problem there, so I haven't worried much about the freezing.


In my case it is not possible (using VLC) to skip past it, it just stays stuck on the first frame.

I just tried an ffmpeg based media player (SMPlayer) and it has the same effect as MPC, it plays with good audio but the video is ruined with regular pixellation (if that's the right word).

I'll send it back to the TiVo to see what happens there.


----------



## moyekj (Jan 24, 2006)

scop said:


> In my case it is not possible (using VLC) to skip past it, it just stays stuck on the first frame.
> 
> I just tried an ffmpeg based media player (SMPlayer) and it has the same effect as MPC, it plays with good audio but the video is ruined with regular pixellation (if that's the right word).
> 
> I'll send it back to the TiVo to see what happens there.


 You may be running into the issue described by the anonymous poster about 1 remaining problem:


> The only apparent problem :
> Packet N of PID XX starts a new series of PES headers, which spill over
> into packet N+1 of PID XX, which has an encrypted payload.
> The problem is how to cleanly make that "continuation" from packet N to
> ...


 i.e. It may not be properly decrypting all the packets as a result. Probably someone familiar with TS and coding could figure out a solution for that issue. The description probably doesn't make much sense until one digs into the code.

Any others reading this thread from NZ or Australia had any luck with this? It sounds like the TiVo Premiere units at least could benefit from this, so will be interesting to see if it works for them when released.


----------



## moyekj (Jan 24, 2006)

The previous version of source code still had version set to "0.2pre4" so it was confusing when running "tivodecode --version" to get that version printed out. I updated the code to correspond to version "0.3pre4" and updated the source code and win32 links in the first post of this thread.

NOTE: The TiVo Premiere units have option to download in TS format which gives good speedup over PS format, so this version of tivodecode is useful for more than just Australia/NZ units now. The next release of kmttg will package in this version for windows & mac binaries to go along with the already built in support for TS format downloads.


----------



## orangeboy (Apr 19, 2004)

moyekj said:


> NOTE: The TiVo Premiere units have option to download in TS format which gives good speedup over PS format, so this version of tivodecode is useful for more than just Australia/NZ units now. The next release of kmttg will package in this version for windows & mac binaries to go along with the already built in support for TS format downloads.


Hurry! My Premiere could be shipping soon!


----------



## philhu (Apr 11, 2001)

scop said:


> Media Player Classic Home Cinema - interesting, it works, but it is riddled with an annoying wave of blocky pixellation every couple of seconds or so.
> 
> HTH, Tim.


This is what I am seeing on TS files downloaded from a Premiere Tivo with TS download turned on.


----------



## philhu (Apr 11, 2001)

moyekj said:


> The previous version of source code still had version set to "0.2pre4" so it was confusing when running "tivodecode --version" to get that version printed out. I updated the code to correspond to version "0.3pre4" and updated the source code and win32 links in the first post of this thread.
> 
> NOTE: The TiVo Premiere units have option to download in TS format which gives good speedup over PS format, so this version of tivodecode is useful for more than just Australia/NZ units now. The next release of kmttg will package in this version for windows & mac binaries to go along with the already built in support for TS format downloads.


Kevin, did you ever package in this new version of TivoDecode to kmttg?

I tried some downloads using TS format. The download speed is 50%+ percent faster! But the output, almost works. I get blocky pixelization every 4-5 seconds or so, converted to MP4

Is there a windows version of the newer TivoDecode?

Does anyone know if VideoRedo 4 H.264 program can handle TS Streams?


----------



## moyekj (Jan 24, 2006)

philhu said:


> Kevin, did you ever package in this new version of TivoDecode to kmttg?
> 
> I tried some downloads using TS format. The download speed is 50%+ percent faster! But the output, almost works. I get blocky pixelization every 4-5 seconds or so, converted to MP4
> 
> ...


 I did package in A version of tivodecode with TS support, but there are still some bugs in the program when dealing with certain TS streams where it will not fully decrypt all packets properly, so the pixelization you see are improperly decrypted blocks.
The person who did all the work on adding TS support prefers to remain anonymous and is aware of the remaining issues but hasn't had the time to work on them further last I heard.
So there is no version that I am aware of that works with all TS streams. i.e. For now you are better off either sticking with PS streams or use Windows TiVoDirectShow.dll (which VRD uses for example) instead for decrypting TS streams.


----------



## muerte33 (Jul 4, 2008)

Has anyone tried the March 2013 version of tivodecode to see if it works properly with TS container files?
http://sourceforge.net/tracker/?func=detail&aid=3607690&group_id=183716&atid=906362

UPDATE 3/18/2013
I tried it with KMTTG current version under windows 8 64bit, and I could not get it to work on the TS files.
Maybe Moyekj can give it a shot.
I would love use TS files because they download so fast.


----------



## Agent86 (Jan 18, 2002)

I tried to download and compile the source release on my Mac, but I'm not having much luck.

Out of box the configure script doesn't want to run. This is because the configure script, and some of the other scripts it uses, are not in Unix format. Re-saving the following files to Unix format will allow configure to cleanly run.

configure
depcomp
missing
Makefile.in
install-sh

Unfortunately, once that is tackled the compiler starts throwing "implicit declaration of function" errors in the hexlib.c file and then fails to build.

Someone should be able to grab the Windows binary and take it for a spin through.


----------



## FourOhFour (Apr 4, 2001)

Agent86 said:


> I tried to download and compile the source release on my Mac, but I'm not having much luck.
> 
> Out of box the configure script doesn't want to run. This is because the configure script, and some of the other scripts it uses, are not in Unix format.


I compiled it on my Linux ARM box. It compiled fine after I ran dos2unix *. It appears to be working fine on the PS files I have, but on a TS file it errors out. ("TiVo Private Data : Unmatched Stream ID: Success")


----------



## brimimc (Aug 7, 2008)

I also had problems on the mac and couldn't solve them by just changing the line endings. I had to take the 0.3pre4 download and apply the code changes from 0.3pre6. 

After that I ran into the "TiVo Private Data : Unmatched Stream ID" error in ts_handle_tivo_private_data which I 'solved' by adding the if (pid == 0xffff) block below:

while ( stream_bytes > 0 )
{
pid = portable_ntohs( pPtr );
stream_bytes -= 2;
pPtr += 2;	// advance past pid

if (pid == 0xffff) {
pPtr += stream_bytes; // I don't think this matters
stream_bytes = 0; // I don't think this matters
break;
}

But after all that, I am also seeing the pixelation ever 4-5 seconds as described above but just don't understand the code well enough to know where to look next.


----------



## arantius (Jul 25, 2009)

I just ran into trouble after updating to a 64 bit linux system (always instant segfault). I couldn't find a good place that this source was cleanly accessible, as the SourceForge project looks dead.

So I gathered all the patches I could see above and threw them on github:
https://github.com/arantius/tivodecode

The result totally works for me. No visual glitches (after watching the first ~60 seconds of one test file).


----------



## arantius (Jul 25, 2009)

I take it back. Some streams do definitely have the aforementioned periodic corruption, just not those I tested with earlier.


----------



## moyekj (Jan 24, 2006)

Yup, unless the remaining problems with the tivodecode source are fixed, the only reliable/glitch free way to decrypt TS streams is using TiVoDirectShowFilter.dll that is part of TiVo Desktop.


----------



## rboy (Jan 18, 2014)

Since I couldn't get TiVODecode to work on Fast TiVO trasnfers, I found another tool that uses TiVO Desktop DirectShow filters to decode Fast TiVO trasnfers and remux it into a TS file.
With the latest version of MCEBuddy (2.3.15) (mcebuddy2x.codeplex.com) there is a command line tool called MCEBuddy.RemuxTiVOStreams.exe
This is a command line tool that can remux Fast TiVO (and regular TiVO) using TiVO Desktop DirectShow filters and falls back to TiVO decode if that doesn't work.
Pretty easy to use:
Usage: RemuxTiVOStreams <TiVOFile> <TempPath> <MAK> <AudioLanguage>


----------



## rboy (Jan 18, 2014)

rboy said:


> Since I couldn't get TiVODecode to work on Fast TiVO trasnfers, I found another tool that uses TiVO Desktop DirectShow filters to decode Fast TiVO trasnfers and remux it into a TS file.
> With the latest version of MCEBuddy (2.3.15) (mcebuddy2x.codeplex.com) there is a command line tool called MCEBuddy.RemuxTiVOStreams.exe
> This is a command line tool that can remux Fast TiVO (and regular TiVO) using TiVO Desktop DirectShow filters and falls back to TiVO decode if that doesn't work.
> Pretty easy to use:
> Usage: RemuxTiVOStreams <TiVOFile> <TempPath> <MAK> <AudioLanguage>


This program uses TiVODirectShowFilter.dll to decode the TiVO files FYI to make sure you have TiVO desktop installed and your MAK entered. It falls back to TiVODecode is the DirectShow dll has issues.


----------



## rboy (Jan 18, 2014)

I'm trying to see if I can put it together into a zip file


----------



## rboy (Jan 18, 2014)

I hope everyone knows that the DirectShow dll only works on 32bit programs (so don't use 64 bit of mcebuddy)


----------



## rboy (Jan 18, 2014)




----------



## rboy (Jan 18, 2014)

Okay you can download the standalone zip from here: (it's taken from the 32bit MCEBuddy installation, core files required)

https://www.mediafire.com/?5s5fazttg0995it


----------



## ejonesss (Aug 13, 2007)

@rboy is your post something i can double click and run without any comman line or compiling?


----------

