WebM is Matroska with a shorter codec list. Both are trees of EBML elements, each written as an ID, a variable-length size and a payload. A recorder that streams as it goes can mark sizes as “unknown” and leave out the duration and the seek index. That is why WebM files saved by browsers often show no length and can’t be scrubbed. Below, this page records such a file with MediaRecorder, walks every element, then rebuilds it with sizes, Duration, SeekHead and Cues, without re-encoding, and asks your browser to play both versions.
The rebuilt copy keeps every block byte for byte. Only the wrapper changes: Segment and Cluster get real sizes, Info gets a Duration worked out from the last block’s timestamp, a SeekHead at the front points to Info, Tracks and Cues, and Cues lists the first keyframe of every cluster. Then both files are loaded into a hidden video element, and each is seeked to its midpoint.
The number of leading zero bits, plus one, gives the length: 1xxxxxxx is one byte, 01xxxxxx xxxxxxxx is two, and so on up to eight. The remaining bits hold the value. If every value bit is 1, the size is “unknown”, which is how a live recorder says “I don’t know yet”. Element IDs use the same scheme but keep the marker bits, so the Cluster ID is written as 1F 43 B6 75, marker and all.