Hacker News new | ask | show | jobs
by magicalhippo 1771 days ago
We made a mpeg-ish encoder and decoder at uni, and it was surprisingly simple.

Keyframes were just jpegs. Then for intraframes, you first found the motion vectors for each 8x8 block, then generated the predicted intraframe from the keyframe and motion vector. Then you subtracted the prediction off the keyframe. The resulting "prediction error image" was then simply jpeg encoded as the intraframe, and appended to the output after the motion vectors.

Decoding was reverse, reconstruct the predicted intraframe from the previous keyframe and motion vectors, and add back the prediction error image.

Might be glossing over something as it was over a decade ago but should be about the gist of it.

We played with different algorithms for finding motion vectors and such, including accelerating it with GPGPU.

Really fun project, and assuming you use an existing jpeg library, not at all big or difficult.

1 comments

> simply jpeg encoded as the intraframe

In case it wasn't obvious, the error image can of course have negative values which jpeg can't handle. So you add a bias of +128 and clamp the biased error to [0, 255].

During decoding you simply subtract the bias when adding back the error image.