Skip to content

Movi Architecture Documentation โ€‹

Comprehensive Technical Overview


Table of Contents โ€‹

  1. System Overview
  2. Core Principles
  3. Component Architecture
  4. Data Flow
  5. Technology Stack
  6. Module System
  7. Memory Management
  8. Performance Optimization
  9. Standards Compliance
  10. Future Roadmap

System Overview โ€‹

Movi is a modular streaming video library for browsers that provides:

  • Pull-based streaming for efficient memory usage
  • Hardware-first decoding with automatic software fallback
  • HDR support with proper color space handling
  • Multi-track audio/video/subtitle selection
  • Professional UI via custom HTML element

Design Philosophy โ€‹

  1. Modular by Default: Three export levels (demuxer, player, full element)
  2. Standards-First: ISO/ITU-T compliance for interoperability
  3. Performance-Critical: Zero-copy I/O, hardware acceleration
  4. User-Friendly: Drop-in <video> replacement with enhanced features

Core Principles โ€‹

1. Pull-Based Streaming โ€‹

Traditional Push Model:

Server โ†’ [Full File] โ†’ Client Memory โ†’ Play

Problems: High memory, slow start, no seeking until fully loaded

Movi Pull Model:

Client โ†’ [Request Chunk] โ†’ Server
       โ† [Chunk Data]    โ†
Client โ†’ Demux โ†’ Decode โ†’ Render

Benefits: Low memory, instant start, random access

2. Hardware-First Decoding โ€‹

Decision Tree:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Video Packet    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚
    Try WebCodecs (Hardware)
         โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”
    โ”‚Success? โ”‚
    โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜
         โ”‚
    Yes  โ”‚  No
    โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ Render  โ”‚  โ”‚ Try WASM  โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚ (Software)โ”‚
                 โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
                   โ”Œโ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”
                   โ”‚ Render โ”‚
                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

3. Audio-Master Synchronization โ€‹

Why Audio-Master?

  • Audio glitches are highly noticeable (pops/clicks)
  • Video frame drops are less noticeable (motion blur)
  • Web Audio API provides precise timing

Implementation:

typescript
// Audio renderer is the master clock
const audioTime = audioRenderer.getAudioClock();

// Video syncs to audio
if (videoFrame.timestamp <= audioTime) {
  renderFrame(videoFrame);
} else {
  waitForAudio(); // Video ahead, pause until audio catches up
}

Component Architecture โ€‹

High-Level View โ€‹

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     Movi Library                            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚              Export Level 1: Demuxer                  โ”‚  โ”‚
โ”‚  โ”‚                 (movi/demuxer)                        โ”‚  โ”‚
โ”‚  โ”‚                    ~45KB                              โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
โ”‚  โ”‚  โ€ข FFmpeg WASM (libavformat)                          โ”‚  โ”‚
โ”‚  โ”‚  โ€ข Container parsing (MP4, MKV, WebM, etc.)           โ”‚  โ”‚
โ”‚  โ”‚  โ€ข Packet extraction                                  โ”‚  โ”‚
โ”‚  โ”‚  โ€ข Metadata reading                                   โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚              Export Level 2: Player                   โ”‚  โ”‚
โ”‚  โ”‚                 (movi/player)                         โ”‚  โ”‚
โ”‚  โ”‚                   ~180KB                              โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
โ”‚  โ”‚  โ€ข Demuxer +                                          โ”‚  โ”‚
โ”‚  โ”‚  โ€ข Decoders (Video, Audio, Subtitle)                  โ”‚  โ”‚
โ”‚  โ”‚  โ€ข Renderers (Canvas, Audio)                          โ”‚  โ”‚
โ”‚  โ”‚  โ€ข State management                                   โ”‚  โ”‚
โ”‚  โ”‚  โ€ข A/V synchronization                                โ”‚  โ”‚
โ”‚  โ”‚  โ€ข Track management                                   โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚              Export Level 3: Element                  โ”‚  โ”‚
โ”‚  โ”‚                   (movi)                              โ”‚  โ”‚
โ”‚  โ”‚                   ~410KB                              โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
โ”‚  โ”‚  โ€ข Player +                                           โ”‚  โ”‚
โ”‚  โ”‚  โ€ข Custom HTML element (<movi-player>)                โ”‚  โ”‚
โ”‚  โ”‚  โ€ข UI controls                                        โ”‚  โ”‚
โ”‚  โ”‚  โ€ข Gestures (tap, swipe, pinch)                       โ”‚  โ”‚
โ”‚  โ”‚  โ€ข Theme system                                       โ”‚  โ”‚
โ”‚  โ”‚  โ€ข Ambient mode                                       โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Component Dependency Graph โ€‹

                    MoviElement (Web Component)
                           โ”‚
                           โ–ผ
                      MoviPlayer
                     โ•ฑ     โ”‚     โ•ฒ
                    โ•ฑ      โ”‚      โ•ฒ
                   โ•ฑ       โ”‚       โ•ฒ
                  โ–ผ        โ–ผ        โ–ผ
            Demuxer   TrackManager  Clock
                โ”‚          โ”‚         โ”‚
                โ–ผ          โ–ผ         โ–ผ
           WasmBindings  Decoders  Renderers
                โ”‚          โ”‚         โ”‚
                โ–ผ          โ–ผ         โ–ผ
           FFmpeg WASM  WebCodecs  WebGL2/WebAudio

Data Flow โ€‹

Playback Pipeline โ€‹

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ 1. SOURCE LAYER                                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  HttpSource (Range Requests) โ”‚ FileSource (LRU Cache)        โ”‚
โ”‚  โ€ข SharedArrayBuffer mode     โ”‚ โ€ข 1MB chunks                 โ”‚
โ”‚  โ€ข Zero-copy transfer         โ”‚ โ€ข 64-chunk cache             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                 โ”‚ read(offset, size) โ†’ ArrayBuffer
                 โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ 2. DEMUX LAYER                                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Demuxer โ†’ WasmBindings โ†’ FFmpeg WASM (Asyncify)             โ”‚
โ”‚  โ€ข Container parsing (ISO BMFF, Matroska)                    โ”‚
โ”‚  โ€ข Track enumeration (codec, resolution, bitrate)            โ”‚
โ”‚  โ€ข Packet extraction (PTS, DTS, keyframe flag)               โ”‚
โ”‚  โ€ข Seeking (keyframe index)                                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                 โ”‚ readPacket() โ†’ Packet { data, timestamp, ... }
                 โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ 3. TRACK SELECTION LAYER                                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  TrackManager                                                โ”‚
โ”‚  โ€ข Filters packets by stream index                           โ”‚
โ”‚  โ€ข Handles track switching                                   โ”‚
โ”‚  โ€ข Language/quality selection                                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
          โ”‚ Video           โ”‚ Audio           โ”‚ Subtitle
          โ–ผ                 โ–ผ                 โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ 4. DECODE LAYER โ”‚ โ”‚                 โ”‚ โ”‚                  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ MoviVideoDecoderโ”‚ โ”‚MoviAudioDecoder โ”‚ โ”‚ SubtitleDecoder  โ”‚
โ”‚                 โ”‚ โ”‚                 โ”‚ โ”‚                  โ”‚
โ”‚ Try WebCodecs   โ”‚ โ”‚ Try WebCodecs   โ”‚ โ”‚ Text/Image parse โ”‚
โ”‚   โ†“ (Fail)      โ”‚ โ”‚   โ†“ (Fail)      โ”‚ โ”‚                  โ”‚
โ”‚ WASM Fallback   โ”‚ โ”‚ WASM Fallback   โ”‚ โ”‚                  โ”‚
โ”‚                 โ”‚ โ”‚                 โ”‚ โ”‚                  โ”‚
โ”‚ โ†’ VideoFrame    โ”‚ โ”‚ โ†’ AudioData     โ”‚ โ”‚ โ†’ SubtitleCue    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                   โ”‚                   โ”‚
         โ–ผ                   โ–ผ                   โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ 5. SYNCHRONIZATION LAYER                                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Clock (Audio-Master)                                        โ”‚
โ”‚  โ€ข Audio renderer = master clock                             โ”‚
โ”‚  โ€ข Video syncs to audio time                                 โ”‚
โ”‚  โ€ข Subtitle syncs to audio time                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚ getTime() โ†’ currentTime
         โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ 6. RENDER LAYER                                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  CanvasRenderer (WebGL2)     AudioRenderer (Web Audio API)   โ”‚
โ”‚  โ€ข Frame queue (120 frames)  โ€ข Audio buffer (2 seconds)      โ”‚
โ”‚  โ€ข 60Hz presentation loop    โ€ข Sample scheduling             โ”‚
โ”‚  โ€ข HDR support (P3 canvas)   โ€ข Volume control                โ”‚
โ”‚  โ€ข Subtitle overlay          โ€ข Clock provider                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                 โ”‚
                 โ–ผ
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ”‚  USER OUTPUT     โ”‚
         โ”‚  Screen + Audio  โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Technology Stack โ€‹

Core Technologies โ€‹

LayerTechnologyPurpose
Container ParsingFFmpeg WASMUniversal format support
Video DecodingWebCodecs APIHardware acceleration
Audio DecodingWebCodecs APIHardware acceleration
Video RenderingWebGL2GPU-accelerated, HDR support
Audio RenderingWeb Audio APIHigh-precision timing
UIWeb ComponentsCustom element, Shadow DOM
Async I/OAsyncify (Emscripten)WASM async operations
LanguageTypeScriptType safety, tooling

FFmpeg WASM Configuration โ€‹

Compilation Flags:

bash
-s ASYNCIFY=1              # Enable async/await in WASM
-s ASYNCIFY_STACK_SIZE=128KB  # Stack for suspended calls
-s ALLOW_MEMORY_GROWTH=1   # Dynamic memory allocation
-s EXPORTED_FUNCTIONS=[...] # Export only needed functions

Enabled FFmpeg Components:

  • libavformat - Container demuxing
  • libavcodec - Software decode (fallback)
  • libswscale - Frame scaling (thumbnails)
  • libswresample - Audio resampling

Disabled Components:

  • Filters (not needed, saves 500KB+)
  • Muxers (read-only library)
  • Encoders (playback only)

Size Optimization:

  • Strip debug symbols: --strip-all
  • Dead code elimination: --gc-sections
  • LTO (Link-Time Optimization): -flto
  • Result: ~4MB WASM (vs ~20MB full FFmpeg)

Module System โ€‹

Export Structure โ€‹

typescript
// movi/demuxer (Minimal - 45KB)
export { Demuxer } from "./demux/Demuxer";
export { HttpSource, FileSource } from "./source";
export type { SourceAdapter, MediaInfo, Track } from "./types";

// movi/player (Core - 180KB)
export { MoviPlayer } from "./core/MoviPlayer";
export { Demuxer } from "./demux/Demuxer";
export { HttpSource, FileSource } from "./source";
export type { PlayerConfig, PlayerState, PlayerEventMap } from "./types";

// movi (Full - 410KB)
export { MoviElement } from "./render/MoviElement";
export { MoviPlayer } from "./core/MoviPlayer";
export { Demuxer } from "./demux/Demuxer";
export * from "./types";

// Auto-register custom element
customElements.define("movi-player", MoviElement);

Tree-Shaking โ€‹

Modern bundlers can tree-shake unused components:

typescript
// Only imports Demuxer (~45KB)
import { Demuxer } from "movi/demuxer";

// Only imports Player (~180KB)
import { MoviPlayer } from "movi/player";

// Imports everything (~410KB)
import { MoviElement } from "movi";

Memory Management โ€‹

WASM Memory Layout โ€‹

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  WASM Heap                          โ”‚
โ”‚                 (Dynamic Growth)                    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  FFmpeg Context (~10MB)                      โ”‚   โ”‚
โ”‚  โ”‚  โ€ข AVFormatContext (demuxer state)           โ”‚   โ”‚
โ”‚  โ”‚  โ€ข AVCodecContext (decoder state)            โ”‚   โ”‚
โ”‚  โ”‚  โ€ข I/O buffers                               โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  Packet Buffers (~10-20MB)                   โ”‚   โ”‚
โ”‚  โ”‚  โ€ข Encoded video/audio packets               โ”‚   โ”‚
โ”‚  โ”‚  โ€ข Temporary decode buffers                  โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  Frame Buffers (Software Decode)             โ”‚   โ”‚
โ”‚  โ”‚  โ€ข Only used for fallback decoding           โ”‚   โ”‚
โ”‚  โ”‚  โ€ข ~50MB for 4K YUV frames                   โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Total WASM: ~50-80MB (varies by video resolution)

JavaScript Memory โ€‹

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               JavaScript Heap                       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  Video Frame Queue (~1.5GB for 4K)           โ”‚   โ”‚
โ”‚  โ”‚  โ€ข 120 VideoFrame objects                    โ”‚   โ”‚
โ”‚  โ”‚  โ€ข Each ~12MB (3840ร—2160 YUV 4:2:0)          โ”‚   โ”‚
โ”‚  โ”‚  โ€ข GPU textures (video memory)               โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  Audio Buffer (~384KB)                       โ”‚   โ”‚
โ”‚  โ”‚  โ€ข 2 seconds ร— 48kHz ร— 2ch ร— 4B              โ”‚   โ”‚
โ”‚  โ”‚  โ€ข Float32Array buffers                      โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  HTTP Cache (64MB default)                   โ”‚   โ”‚
โ”‚  โ”‚  โ€ข Recently fetched chunks                   โ”‚   โ”‚
โ”‚  โ”‚  โ€ข LRU eviction policy                       โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
Total JS: ~1.5-2GB (4K), ~200-400MB (1080p)

Memory Optimization Strategies โ€‹

  1. Frame Queue Adaptive Sizing:

    typescript
    const queueSize = frameRate > 40 ? 120 : 60;
    // 60fps โ†’ 120 frames (~2s buffer)
    // 30fps โ†’ 60 frames (~2s buffer)
  2. VideoFrame Lifecycle:

    typescript
    // Create from decoder
    const frame = decodedFrame;
    
    // Use for rendering
    renderToCanvas(frame);
    
    // CRITICAL: Close when done
    frame.close(); // Frees GPU memory
  3. Packet Pooling:

    typescript
    // Reuse packet buffers instead of allocating new ones
    const packetPool = new PacketPool(maxSize);
    const packet = packetPool.acquire();
    // ... use packet
    packetPool.release(packet);
  4. Lazy Initialization:

    typescript
    // Don't create decoders until needed
    if (!this.videoDecoder && hasVideoPacket) {
      this.videoDecoder = new MoviVideoDecoder();
    }

Performance Optimization โ€‹

Zero-Copy I/O (SharedArrayBuffer Mode) โ€‹

Traditional HTTP Streaming:

Server โ†’ Network โ†’ ArrayBuffer (Copy 1) โ†’ WASM (Copy 2) โ†’ Use

Zero-Copy Mode:

Server โ†’ Network โ†’ SharedArrayBuffer โ†’ WASM (Direct Access)

Implementation:

typescript
class HttpSource {
  private sharedBuffer: SharedArrayBuffer | null = null;

  async read(offset: number, size: number): Promise<ArrayBuffer> {
    if (this.sharedBuffer) {
      // Zero-copy: WASM reads directly from shared memory
      const view = new Uint8Array(this.sharedBuffer, offset, size);
      return view.buffer;
    } else {
      // Fallback: Copy to ArrayBuffer
      const response = await fetch(url, {
        headers: { Range: `bytes=${offset}-${offset + size - 1}` },
      });
      return response.arrayBuffer();
    }
  }
}

Requirements:

  • HTTPS (cross-origin isolation)
  • Headers: Cross-Origin-Opener-Policy: same-origin
  • Headers: Cross-Origin-Embedder-Policy: require-corp

Hardware Acceleration โ€‹

WebCodecs Decision Tree:

typescript
class MoviVideoDecoder {
  async tryHardwareDecode(packet: Packet) {
    try {
      // 1. Check if codec supported
      const config = {
        codec: "hvc1.2.4.L153.B0",
        optimizeForLatency: true,
      };

      const support = await VideoDecoder.isConfigSupported(config);
      if (!support.supported) {
        throw new Error("Codec not supported");
      }

      // 2. Try decode
      const decoder = new VideoDecoder({
        output: (frame) => this.onFrame(frame),
        error: (err) => this.onError(err),
      });

      decoder.configure(config);
      decoder.decode(
        new EncodedVideoChunk({
          type: packet.keyframe ? "key" : "delta",
          timestamp: packet.timestamp * 1e6,
          data: packet.data,
        }),
      );

      return true; // Success
    } catch (error) {
      console.warn("Hardware decode failed, trying software:", error);
      return false;
    }
  }

  async trySoftwareDecode(packet: Packet) {
    // Fallback to FFmpeg WASM
    const frame = await this.wasmDecoder.decode(packet);
    return frame;
  }
}

Intelligent Buffering โ€‹

Back-Pressure Algorithm:

typescript
class MoviPlayer {
  private async demuxLoop() {
    while (this.playing) {
      // Check buffer health
      const videoQueueSize = this.videoRenderer.getQueueSize();
      const audioQueueSize = this.audioRenderer.getQueueSize();

      // Apply back-pressure if buffers full
      if (videoQueueSize > 100 || audioQueueSize > 100) {
        await sleep(50); // Slow down demuxing
        continue;
      }

      // Read next packet
      const packet = await this.demuxer.readPacket();
      if (!packet) break;

      // Route to appropriate decoder
      if (packet.streamIndex === this.selectedVideoTrack) {
        await this.videoDecoder.decode(packet);
      } else if (packet.streamIndex === this.selectedAudioTrack) {
        await this.audioDecoder.decode(packet);
      }
    }
  }
}

Benefits:

  • Prevents memory overflow
  • Reduces decode latency
  • Smooth playback even on slow devices

Standards Compliance โ€‹

ISO/IEC 14496-15: Codec Configuration Parsing โ€‹

Example: HEVC (hvcC box) Parsing

typescript
// Binary structure (ISO/IEC 14496-15 Section 8.3.3.1.2)
class CodecParser {
  static parseHEVC(data: Uint8Array): string {
    const reader = new BitReader(data);

    // Byte 0: configurationVersion
    const version = reader.readBits(8);

    // Byte 1:
    const profileSpace = reader.readBits(2); // general_profile_space
    const tierFlag = reader.readBits(1); // general_tier_flag
    const profileIdc = reader.readBits(5); // general_profile_idc

    // Bytes 2-5: general_profile_compatibility_flags
    const compatFlags = reader.readBits(32);

    // Bytes 6-11: general_constraint_indicator_flags
    const constraints = [];
    for (let i = 0; i < 6; i++) {
      constraints.push(reader.readBits(8));
    }

    // Byte 12: general_level_idc
    const levelIdc = reader.readBits(8);

    // Generate codec string per spec
    const profileSpaceChar = ["", "A", "B", "C"][profileSpace];
    const tierChar = tierFlag ? "H" : "L";

    return `hvc1.${profileSpaceChar}${profileIdc}.${compatFlags.toString(16)}.${tierChar}${levelIdc}`;
  }
}

Standards Reference:

  • ISO/IEC 14496-15:2022 - Carriage of NAL unit structured video in the ISO Base Media File Format
  • Section 8.3.3.1.2: HEVC decoder configuration record

ITU-T H.273: Color Space Identification โ€‹

Mapping Table Implementation:

typescript
// ITU-T Recommendation H.273 (12/2016)
class ColorSpaceMapper {
  // Table 2: Colour primaries
  static readonly COLOR_PRIMARIES = {
    1: "bt709", // Rec. ITU-R BT.709-6
    2: "unspecified",
    4: "bt470m", // Rec. ITU-R BT.470-6 System M
    5: "bt470bg", // Rec. ITU-R BT.470-6 System B, G
    6: "smpte170m", // SMPTE 170M (NTSC)
    7: "smpte240m", // SMPTE 240M
    8: "film", // Film
    9: "bt2020", // Rec. ITU-R BT.2020-2
    10: "smpte428", // SMPTE ST 428-1
    11: "p3dci", // DCI-P3
    12: "p3d65", // Display P3
    22: "ebu3213", // EBU Tech. 3213-E
  };

  // Table 3: Transfer characteristics
  static readonly TRANSFER_CHARACTERISTICS = {
    1: "bt709", // Rec. ITU-R BT.709-6
    4: "gamma22", // Gamma 2.2
    5: "gamma28", // Gamma 2.8
    6: "smpte170m", // SMPTE 170M
    7: "smpte240m", // SMPTE 240M
    8: "linear", // Linear transfer
    13: "iec61966-2-4", // IEC 61966-2-4
    14: "bt1361", // Rec. ITU-R BT.1361-0
    15: "iec61966-2-1", // IEC 61966-2-1 (sRGB)
    16: "bt2020-10", // Rec. ITU-R BT.2020-2 (10-bit)
    17: "bt2020-12", // Rec. ITU-R BT.2020-2 (12-bit)
    18: "pq", // SMPTE ST 2084 (PQ)
    19: "smpte428", // SMPTE ST 428-1
    20: "hlg", // ARIB STD-B67 (HLG)
  };

  // Table 4: Matrix coefficients
  static readonly MATRIX_COEFFICIENTS = {
    0: "identity", // Identity matrix
    1: "bt709", // Rec. ITU-R BT.709-6
    4: "fcc", // FCC
    5: "bt470bg", // Rec. ITU-R BT.470-6 System B, G
    6: "smpte170m", // SMPTE 170M
    7: "smpte240m", // SMPTE 240M
    8: "ycocg", // YCoCg
    9: "bt2020-ncl", // Rec. ITU-R BT.2020-2 (non-constant)
    10: "bt2020-cl", // Rec. ITU-R BT.2020-2 (constant)
  };
}

Future Roadmap โ€‹

Q1 2026 โ€‹

  • [x] ISO standards compliance verification
  • [x] Comprehensive documentation
  • [ ] Unit test coverage (80%+)
  • [ ] Performance benchmarking suite

Q2 2026 โ€‹

  • [ ] Firefox WebCodecs support (when available)
  • [ ] Dolby Vision metadata parsing
  • [ ] AV1 sequence header parsing for advanced color info
  • [ ] Full HEVC SPS VUI parser (optional, low priority)

Q3 2026 โ€‹

  • [ ] Adaptive Bitrate Streaming (ABR) support
  • [ ] Live streaming (DASH, HLS)
  • [ ] DRM support (Widevine, PlayReady)
  • [ ] Chromecast integration

Q4 2026 โ€‹

  • [ ] React/Vue/Svelte wrapper components
  • [ ] Server-side rendering (SSR) compatibility
  • [ ] Advanced analytics (QoE metrics)
  • [ ] Plugin system for custom decoders

Summary โ€‹

Movi's architecture provides:

โœ… Modular Design: Three export levels for different use cases โœ… Standards Compliance: ISO/ITU-T adherence for interoperability โœ… Performance: Zero-copy I/O, hardware acceleration, intelligent buffering โœ… User Experience: Professional UI, gesture support, HDR rendering โœ… Flexibility: Custom element, programmatic API, multi-track support โœ… Reliability: Error recovery, fallback decoding, robust state management

Target Use Cases:

  • Video streaming platforms
  • Media players
  • Video editors (web-based)
  • Live streaming applications
  • Educational platforms
  • Digital signage

Last Updated: February 5, 2026

Released under the Apache-2.0 License.