Video tokenizers convert raw pixel volumes into a small set of discrete tokens that a downstream generative model operates on. Two dominant designs differ in how they carve up the video: a spatial tokenizer processes each frame independently using 2D patches, while a spatiotemporal tokenizer uses 3D cubes that span a fixed number of frames in time. The choice directly affects how many tokens a clip produces and how well fast motion is preserved after reconstruction.
In this task, you will implement a simplified video tokenizer that can operate in either mode and measures the information each mode retains. Given a video of shape (T, H, W, C), partition it into non-overlapping patches and replace every pixel in a patch with the per-channel mean of that patch. This mean-pool-then-broadcast procedure is the reconstruction you would get from a tokenizer whose codebook is collapsed to a single scalar per channel per patch -- it exposes exactly what information each tokenization scheme throws away.
Implement video_tokenizer_reconstruct(video, patch_t, patch_h, patch_w, mode) where:
video is a 4D array of shape (T, H, W, C) with T, H, W divisible by patch_t, patch_h, patch_w respectively.mode is either 'spatial' or 'spatiotemporal'. In 'spatial' mode, the temporal patch dimension is forced to 1 regardless of patch_t; each frame is tokenized independently. In 'spatiotemporal' mode, patches span patch_t frames in time.Return the reconstructed video as a nested Python list with the same shape as the input.