Restarting the work on TM1 encoder

Back in February I wrote about my failed attempt to write TrueMotion 1 encoder. And since I was bored and really had nothing better to do, I tried my hoof at it again.

Last time it was 24-bit encoding, now I tried to approach 15-bit encoding instead and got some results. I guess the moral of the story is that you should not overthink it and use the simplest approach to coding.

Essentially TM1 encodes deltas from the left and top pixel value (in case of 15-bit video it operates on pixel pairs in order to be able to use SWAR and process two pixels at once), updating luma value (or essentially all components by the same delta value) and red and blue values time from time (depending on the block size; also both pixels in pair for 15-bit mode are updated with the same deltas).

Considering all that I’ve started working with (R-G, G, B-G) pixel values, so that I could look up deltas for each component independently (I just need to check that the resulting RGB pixel values are still in range). And after realizing that I need to work with pixel pairs during prediction stage, I was finally able to encode intra image that was correctly decoded afterwards.

Now for the other realizations: apparently the first two sets of deltas are supposed to be used with 15-bit mode (as they’re small) while the following two sets of deltas are supposed to be used for 24-bit mode (as some of those values exceed 5-bit range). Also out of three Tunstall codebooks it makes sense to use the first one for 15-bit mode and the other two for 24-bit mode (the first codebook can code only 7 deltas and 15-bit mode delta sets have seven distinct deltas, for 24-bit mode all eight deltas are used and only two codebooks can code such deltas). Of course there’s still a question of which delta set (or codebook) to use but I hope to resolve it with a bit of experimenting.

Also initially I tried to be smart and see if I can find the best chroma delta for the whole 2×2, 2×4, 4×2 or 4×4 block but that complicated the encoding process (as the format outputs deltas line by line) so I decided to ignore it and simply calculate deltas for the first pixel pair of the sub-block.

In either case, now I need to implement inter coding for TM1 (which is simply handling skip blocks), add 24-bit mode support (should not be that hard now) and implement all those finer details like selecting delta set, codebook and sub-block size selection. And back to boredom after that.

Comments are closed.