Restoring the Doctor Who Specials

The production of Doctor Who moved to HD with the making of Planet of the Dead, the second of five special episodes (the "Specials") that saw the end of David Tennant's tenure as our favourite Time Lord. Inevitably this led to the first Blu-ray release in Doctor Who history.

Unfortunately 2entertain, the company behind the release, made a money-saving decision to only master one set of discs for release all around the world, which meant (for largely historical reasons) converting the episodes from their original PAL frame rate (exactly 50Hz) to the NTSC frame rate (approximately 59.94Hz).

Both PAL and NTSC (or in this case, their digital HD equivalents) utilise interlacing - each frame consists of two fields, comprised of the odd and even lines respectively. PAL uses 25 frames (50 fields) a second, while NTSC uses - almost - 30 frames (60 fields) a second. These two fields may be captured from a single moment in time, in which case you get a "film-look" to your video, and is how films and most modern drama is broadcast, or they can be separated in time, in which case you get the so-called "soap opera" look. The difference between the two is probably most familiar to you from classic episodes of Doctor Who when the action moved from inside the studio (shot with video cameras) to a location (shot on film).

If you think of the invididual images from a video as letters of the alphabet, a Doctor Who episode is natively broadcast (or placed on DVD) in the following manner:

Broadcast frame (25 per second)0123456...
Top (even) fieldABCDEFG...
Bottom (odd) fieldABCDEFG...
A nice straightforward pattern that's easy to watch. But to pad those 25 frames per second out to reach 60 fields per second for NTSC broadcast some of those fields have to be repeated, and this results in a stuttering sequence that can be harder on the eye. The pattern used on the Specials Blu-rays alternates between runs of the two following sub-patterns:
...a'b'c'd'e'f'g'...
...ABCDDEF...
...ABCDEFF...
...a'b'c'd'e'f'g'...
...ABCCDEF...
...ABCDEFF...
Luckily, it turns out that the pattern is predictable, and therefore the relationship between the original frames (capital letters, X) and the frames on the Blu-ray (lower case letters, x') can be calculated. In the patterns above, for example, if one wants to retrieve original frame E, one can calculate that E's bottom field can be found in the bottom field of e', and its top field in the top field of f'.

To undo this I wrote an AviSynth filter which begin by calculating the inverse of the above - i.e., for every NTSC frame on the Blu-ray, it calculates which PAL frames it contains. From this, a table was built linking each PAL frame to at least 2, and at most 3, NTSC frames. For example, taking the second sub-pattern above:

...a'b'c'd'e'f'g'...
...ABCCDEF...
...ABCDEFF...
TopBottomTopBottom
Aa'a'
Bb'b'
Cc'c'd'
Dd'e'
Ee'f'
Ff'g'g'
Using that table, each original PAL frame can be restored in full. Or it could be, if it wasn't for...

The chroma problem

Unfortunately 2entertain made a second error during encoding. In each of the "mixed" interlaced NTSC frames (those where the two capital letters differ), only the luminance (brightness) information is separated between the even and odd lines as it should be. The colour information (chrominance, or chroma) for both PAL frames has been blended together into the NTSC frame, which results in the following sort of nastiness:

Let's take another look at that pattern:

...a'b'c'd'e'f'g'...
...ABCCDEF...
...ABCDEFF...

It can be seen that restoring the chroma for frames C and F won't be a problem - each has one NTSC frame fully associated with it, in this case c' and g', and both contain full chroma information. Restoring D and E poses more of a problem - NTSC frames d', e' and f' all have averaged chroma of their constituent PAL frames. But as just noted, we do have a clean version of the chroma from one of those PAL frames - so this can be subtracted from the blended chroma, leaving just the remaining chroma:

Dchroma = 2*d'chroma − c'chroma
Echroma = 2*f'chroma − g'chroma

There is some loss of accuracy, but as the human brain is not as sensitive to the chroma information as it is to the luma information, this goes unnoticed. With the first sub-pattern we looked at:

...a'b'c'd'e'f'g'...
...ABCDDEF...
...ABCDEFF...

...the missing chroma can be calculated in two different ways, as the clean neighbours are closer:

Echroma = 2*e'chroma − d'chroma
Echroma = 2*g'chroma − f'chroma

So an average of these can be taken.

Further problems

After all that, a few problems still remain:

Planet of the Dead

The conversion of Planet of the Dead took a different approach altogether. In this case fields weren't simply repeated - they were instead blended, naively, to create "in-between frames" to pad out the sequence, so it looks even blurrier than the rest of the episodes. A typical section may look something like this:

...a'b'c'd'e'f'g'...
...ABB+CC+DD+EEF...
...A+BB+CCDD+EE+FF+G...

with one or two blended frames between each clean one. While no PAL frame is fully represented (with both clean even and clean odd fields), there appears to always be at least one clean field for each. After running the video through a deinterlacer to intelligently create full frames from each field, the Avisynth filter srestore can do a pretty good job of "blindly" working out which are the unmixed frames, but for a more accurate restoration there is another source of information we can refer to - the PAL DVD of the same episode. This has all the clean frames, albeit at SD resolution, so with another video filter a comparison can be made between the two, and the matching frames can be extracted from the NTSC video.

So, all fixed? Not quite. Like the other Specials, Planet of the Dead has a blended chroma problem. The difference is that it isn't always a 50/50 mix:

You can see a ghost image of the light in the upper right, at the same position it was at in the previous frame (in other cases, the next frame). Once again the DVD comes to the rescue, since this has clean chroma that we can compare the Blu-ray video to. By calculating a number of test "unblends" of the form:

testchroma = currentchroma*(1+x) − nextchroma*x        where 0 ≤ x ≤ 1
testchroma = currentchroma*(1+x) − prevchroma*x        where 0 ≤ x ≤ 1

and comparing each of these in turn to the original frame's DVD chroma, a "least difference" result can be identified and the chroma can be restored: