Repository navigation
Description
Motivation
LED-data videos and their screenmap.json currently ship as two loose files. Users routinely lose the pairing. We're going to embed the screenmap directly into the video container at the generator side (zackees/ledmapper#122) and want the FastLED loader to pick it up automatically.
Companion issue (generator side): zackees/ledmapper#122.
Container spec (shared with ledmapper)
Identical to the generator-side spec. Reproduced here so both repos can implement to the same contract.
offset size field notes
------ ---- ------------- ----------------------------------------
0 4 magic ASCII "FLED"
4 1 version u8 — start at 1
5 3 reserved must be 0
8 4 json_length u32 little-endian (bytes of JSON payload)
12 N json_bytes UTF-8 JSON (no NUL terminator, no BOM)
12+N ... payload format-specific (raw RGB triplets, MPEG1 ES, MP4 boxes...)
- Backwards compat: if the first 4 bytes are not
FLED, treat as legacy headerless data (current behavior). Zero risk to existing files / sketches. - JSON payload is the existing ScreenMap format unchanged:
i.e. exactly what
{ "map": { "strip1": { "x": [...], "y": [...], "diameter": 0.25 } } }ScreenMap::ParseJson(const char*, ...)(src/fl/math/screenmap.cpp.hpp:98) already eats.
Work in this repo
Phase 1 — Raw .rgb (PixelStream)
PixelStream::begin() / readRGB8() (src/fl/video/pixel_stream.cpp.hpp:53) currently treat the file as pure RGB triplets — frame count = total_bytes / (led_count * 3). Wrap the existing logic so it:
- Peeks the first 12 bytes via
filebuf::read. - If magic ==
\"FLED\": readsjson_length, thenjson_lengthbytes of JSON, stashes it, and adjusts the stream's logical "start" so all subsequentreadRGB8()calls are unaware of the header. Frame count math becomes(total_bytes − header_size) / (led_count * 3). - If magic is anything else: rewinds to byte 0 and behaves exactly as today.
New API surface on PixelStream (or on the Video wrapper at FileSystem::openVideo()):
bool hasEmbeddedScreenMap() const;
const fl::string& embeddedScreenMapJson() const; // empty if not presentSketch hook (proposed UX): when a sketch calls setScreenMap(...) without arguments after opening a video with embedded JSON, auto-apply the embedded map. Bikeshed welcome.
Phase 2 — MPEG1 user_data
pl_mpeg (src/third_party/pl_mpeg/) decodes MPEG1 but does not surface user_data_start_code (0x000001B2) blocks. The FastLED-side Mpeg1Info struct (src/fl/codec/mpeg1.h:32) has no metadata fields today.
Two implementation choices:
- (a) Patch pl_mpeg to expose a
user_datacallback. Touches a vendored third-party lib — small change but worth flagging. - (b) Pre-scan the file with our own minimal MPEG1 byte scanner that walks the bitstream looking for
00 00 01 B2and stops once it finds (or fails to find) the FLED-magic'd block, then hands the full file topl_mpegunchanged.
(b) keeps the third-party patch surface zero. Recommended.
Wire the discovered JSON through the same embeddedScreenMapJson() accessor on the Video wrapper.
Phase 3 — MP4 udta (lower priority)
Current parseMp4() (src/fl/codec/mp4_parser.h:10) walks ftyp→moov→trak→mdia→…→avcC for H.264 SPS/PPS only — it doesn't touch moov.udta. Extend it to additionally walk moov.udta, look for our private UUID box, and recover the JSON.
Heads-up: the original brief mentioned "MP4 (parlio HW accel)". Parlio at src/platforms/esp/32/drivers/parlio/ is the parallel-I/O driver for LED output, not a video decoder. There's no MP4 HW decoder in FastLED core today. If there's a separate MP4 decode path I missed, please link it here so the metadata hook lands in the right place.
Phase 4 — WASM screenmap import binding
The current WASM bridge (src/platforms/wasm/js_bindings.cpp.hpp:91) is one-way: C++ exports screenmaps to JS via getScreenMapData(int*). There's no JS → C++ path to load a screenmap. For browser playback of embedded-screenmap videos to "just work", add:
// js_bindings.cpp.hpp
EMSCRIPTEN_KEEPALIVE
extern \"C\" void jsSetScreenMapsFromJson(const char* json, int len);That hands the JSON to ScreenMap::ParseJson(...) and pushes the result into the same registry that _jsSetCanvasSize currently writes to.
Browser flow then becomes:
- JS fetches
video.rgb. - JS peeks the FLED header, extracts embedded JSON.
- JS calls
_jsSetScreenMapsFromJson(jsonPtr, jsonLen). - Sketch wakes up with a populated screenmap; user dropped one file, not two.
Acceptance
- Phase 1: a
.rgbwith the FLED header parses cleanly viaFileSystem::openVideo(), surfacesembeddedScreenMapJson(), and frame math is correct (off-by-12 + json_length errors caught by tests). - Phase 1: legacy headerless
.rgbfiles still play unchanged (no perf or behavior regression). - Phase 4: WASM round-trip with a real ledmapper-recorded file works end-to-end in the browser demo.
- Phases 2 / 3 land as follow-ups once Phase 1 is settled and we've validated the spec end-to-end.
Test plan
- Unit test: synthesize a buffer of
FLED \x01 \x00\x00\x00 + len + json + N frames of RGB, run throughPixelStream, verify JSON and frames recover byte-identical. - Unit test: legacy headerless buffer parses as before,
hasEmbeddedScreenMap() == false. - Unit test: corrupt headers (truncated, bad magic, length > buffer) degrade gracefully — never crash on user input.
- Integration: pair with a ledmapper-recorded
.rgbfrom the companion PR, play on an ESP32 / in WASM, confirm screenmap auto-applies.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Jun 15, 2026
Locked the v1 spec on the generator side. Canonical reference:
docs/fled-format.mdin ledmapper (added in the Phase 1 PR linked from zackees/ledmapper#122). FastLED should consume this exact spec.Locked decisions:
.fled(replaces sidecar.rgb+.jsonpairing)magic[4]="FLED" + version[1]=1 + pixel_format[1] + reserved[2] + json_length[4 u32 LE], then UTF-8 JSON, then payload.bytesPerLed[format]is a 5-entry lookup. Unknown values reject cleanly.0x00 rgb8(Phase 1),0x01 gray8,0x02 rgba8,0x03 rgbw8,0x04 rgb565le.mapblock and adds optionalvideo.fps. Novideo.format(header is authoritative).Reference vector (in the docs and in ledmapper's
tests/unit/rgb-video.test.ts):46 4C 45 44 01 00 00 00 1F 00 00 00{"map":{"a":{"x":[0],"y":[0]}}}(31 bytes)FF 00 00(one frame, one LED, pure red)Both repos should agree on this vector bit-exactly. Suggested FastLED test: synthesize the above 46 bytes in a unit test and verify
PixelStreamrecovers JSON + frame correctly.feat(fled): self-describing video container with embedded screenmap (#…
zackees commentedon Jun 20, 2026
Closing as resolved / superseded — per-phase status
Phase 1 — PixelStream FLED header parsing: ✅ Already shipped independently for issue #3072. The current code at
src/fl/video/pixel_stream.{h,cpp.hpp}parses the FLED v1 header on seekable handles, exposesPixelStream::hasEmbeddedScreenMap()andembeddedScreenMapJson(), and surfaces the same accessors onfl::Video(src/fl/fx/video.h:78-79). Legacy headerless.rgbfiles still work. Phase 1 was the load-bearing piece — done.Phase 4 — WASM JS→C++ screenmap binding: superseded by the
fl::Fledbundle subsystem (#3311), specifically byfl::Fled::loadFromVector(fl::vector<fl::u8>&&)+fl::Fled::loadFromStatic(fl::span<const fl::u8>)and the newfl::FileSystem::wasm()virtual-FS factory. The browser flow becomes:.fledbytesfl::Fled::loadFromVector(...)/fl::Fled::load(fs, ...)FastLED.load(fled)binds the screenmap to controllers, which broadcasts viaEngineEvents::onCanvasUiSet— the JS canvas auto-receives it through the same path JS uses todayNo dedicated
jsSetScreenMapsFromJsonbinding is needed; the buffer-handoff pattern covers it generically.Phases 2 & 3 — MPEG1
user_data/ MP4udtaextraction: deferred indefinitely. These are container-specific format additions (embedding screenmap JSON inside an MPEG1 or MP4 file rather than alongside it). The.fledcontainer (which #3311 generalizes into a full FastLED bundle format with hardware config, scripts, etc.) is the canonical path forward for "ship the screenmap in the same file as the pixel data." MPEG1/MP4 carrying a screenmap is a much smaller niche. If real demand emerges for either, file a focused issue at that point — but don't carry the open ticket here in the meantime.Cross-link
fl::Fledbundle subsystem (umbrella). Captures the v1 design that supersedes Phase 4 and reframes the screenmap-in-container concept as a generalized FastLED deployment unit.fl::PatternPlayerPR; will be retired when feat(fl/fled): create new fl::Fled bundle subsystem (value + runner + section accessors) under src/fl/fled/ #3311 lands.