Looking at RoQ

Recently The (Multimedia) Mike contacted me and asked if I can look what’s wrong with Clandestiny videos. I did.

First of all it’s worth mentioning that the format obviously originates from Trilobyte as it’d been used in its games years before Quake III was released, it has more features and the decoder in open-sourced Q3 engine still calls it trFMV.

Then I should mention that RoQ support in Libav is not great (and in FFmpeg it’s exactly the same) as the demuxer lacks support for some packet types (like 0x1030 used to signal that it’s a good time to prefetch data), there’s no support for JPEG frames and it goes crazy on files extracted from Clandestiny demo because of all that.

Thus I decided to quickly hack my own decoder for it based on the original description by Dr. Tim Ferguson (yet another forgotten researcher who REd several VQ-based video formats) and played with it to see what’s going wrong.

And it seems the problem was mostly in motion compensation. In some conditions you should double the motion vectors (I think it’s when the first chunk size is zero instead of minus one); also some files have alpha information in the codebook (this is detected by video properties chunk argument being set to one) as it’s apparent from ScummVM code. In either case it’s just the minor details that make things complicated (and I was lucky not to encounter interlaced mode files).

It was a nice distraction but I guess it’s time to do something else.

6 Responses to “Looking at RoQ”

  1. Seems that the ScummVM folks managed to reverse engineer the same information concurrently. They have a commit that allegedly makes the Clandestiny files play correctly:


  2. Kostya says:

    Indeed, though their solution is a hack dependent on the game and filename and mine is a different hack (that may fail on some files but I’ve not tested it thoroughly).

  3. madmoose says:

    > though their solution is a hack dependent on the game

    We only recreated the hack that was in the original game 🙂

  4. Kostya says:

    Indeed, your solution is correct (BTW in demo it also checks for trailer.rnr in addition to door* and act*), I just picked whatever worked for me.

    Still, this is rather stupid on their side.

  5. Tim Ferguson says:

    Wow… Received a message from Mike about this posting. That was very much a different life ago… Fun to hear this kind of work still continues today!

  6. Kostya says:

    There’s still some interest in game formats (mostly for the future ScummVM engines) and sometimes people look at other formats.

    If you think some format should be reverse engineered—don’t hesitate to say that, maybe it’ll be done one day.