Repository navigation
Description
Motivation
The examples/Fx/FxSdCard/ sketch is the canonical reference for "play a video off the SD card." It demonstrates exactly the problem the FLED container format solves: every user has to ship three loose files (video.rgb + color_line_bubbles.rgb + screenmap.json) and keep them in sync. Mismatched files silently break the mapping; the hardcoded MATRIX_WIDTH × MATRIX_HEIGHT has to match total_bytes / (led_count * 3) or the frame slicing is wrong with no diagnostic.
The FLED container (spec, generator zackees/ledmapper#122) packs the screenmap directly into the video file. Converting this sketch to load a single .fled makes it the reference for the new format and lets us delete the entire sidecar-mismatch failure mode.
Companion / dependency: FastLED/FastLED#3063 — the consumer-side FLED parser plus the embeddedScreenMapJson() accessor on Video / PixelStream. This sketch change lands on top of that PR; it's the demo for the new API.
Scope
Convert examples/Fx/FxSdCard/FxSdCard.ino to load .fled files instead of .rgb + screenmap.json sidecars. Two open decisions for the maintainer (calling them out, not pre-deciding):
- Replace vs. add-alongside. Replace the existing example (cleaner endgame; legacy sidecar pattern is deprecated) or ship a new
examples/Fx/FxSdCardFled/next to it (preserves the legacy reference). The remaining proposal assumes replace; flip if you prefer the parallel. - Hardcode
NUM_LEDSvs. derive from embedded JSON. A hardware sketch can't dynamically resizeCRGB leds[](it needs a compile-time size for theaddLedspin binding), soNUM_LEDSstays a#define. The proposal asserts the embedded screenmap's LED count matchesNUM_LEDSat setup and bails with a clear error otherwise — best of both worlds.
Code sketch (proposed FxSdCard.ino diff)
// Before:
// video = filesystem.openVideo("data/video.rgb", NUM_LEDS, FPS, 2);
// video2 = filesystem.openVideo("data/color_line_bubbles.rgb", NUM_LEDS, FPS, 2);
// fl::ScreenMap screenMap;
// bool ok = filesystem.readScreenMap("data/screenmap.json", "strip1", &screenMap);
// After:
video = filesystem.openVideo("data/video.fled", NUM_LEDS, FPS, 2);
if (!video) { FL_WARN("Failed to open video.fled"); gError = true; return; }
video2 = filesystem.openVideo("data/color_line_bubbles.fled", NUM_LEDS, FPS, 2);
if (!video2) { FL_WARN("Failed to open color_line_bubbles.fled"); gError = true; return; }
// New API from #3063: pull the screenmap out of the video file itself.
fl::ScreenMap screenMap;
{
fl::string err;
const fl::string& json = video.embeddedScreenMapJson();
if (json.empty()) {
FL_WARN("video.fled has no embedded screenmap");
gError = true; return;
}
if (!fl::ScreenMap::ParseJson(json.c_str(), "strip1", &screenMap, &err)) {
FL_WARN(err.c_str());
gError = true; return;
}
if (screenMap.getLength() != NUM_LEDS) {
FL_WARN("embedded screenmap LED count does not match NUM_LEDS");
gError = true; return;
}
}
// addLeds() / setScreenMap unchanged.The filesystem.readScreenMap("data/screenmap.json", ...) call disappears entirely.
Sample data conversion
The two .rgb payloads (data/video.rgb, data/color_line_bubbles.rgb) need to be wrapped in the FLED header along with the existing data/screenmap.json. Either:
-
Generate fresh
.fledfiles from the Mapped Video Maker at ledmapper.com (re-record), or -
Run a one-liner Node script in the FastLED repo's
dev/directory:// dev/wrap-fled.mjs import fs from 'node:fs'; const [, , rgbPath, jsonPath, outPath] = process.argv; const rgb = fs.readFileSync(rgbPath); const jsonBytes = fs.readFileSync(jsonPath); const header = Buffer.alloc(12); header.write('FLED', 0, 'ascii'); header[4] = 1; // version header[5] = 0; // pixel_format = rgb8 header.writeUInt32LE(jsonBytes.length, 8); fs.writeFileSync(outPath, Buffer.concat([header, jsonBytes, rgb]));
Run twice (one per video). Then
git rm data/*.rgb data/screenmap.json && git add data/*.fled.
The ledmapper repo also ships scripts/inspect-fled.mjs which verifies a .fled file is well-formed; use it to sanity-check the conversion.
Documentation
Update data/readme.txt:
video.fled — FLED v1 container (32x32 mapped video, ~10s)
color_line_bubbles.fled — FLED v1 container (32x32 mapped video, looping)
Both files carry the screenmap embedded in their header — no sidecar
.json needed. Spec: https://github.com/zackees/ledmapper/blob/main/docs/fled-format.md
Created with Mapped Video Maker at https://www.ledmapper.com/
Add 2–3 lines of header comment to FxSdCard.ino pointing at the spec link.
Acceptance
-
examples/Fx/FxSdCard/data/ships two files (the two.fledvideos), not four. The.rgbandscreenmap.jsonfiles are deleted. -
FxSdCard.inono longer callsfilesystem.readScreenMapand no longer referencesscreenmap.json. - Sketch compiles cleanly for at least one supported board (ESP32 or Teensy) and runs on the FastLED web compiler (
fastledcommand) with both videos selectable viawhichVideoUI control. - If the embedded JSON parses to a different LED count than the hardcoded
NUM_LEDS, the sketch surfaces a clearFL_WARNand bails — no silent frame-slicing corruption. -
data/readme.txtdescribes the new format and links the spec.
Files involved
examples/Fx/FxSdCard/FxSdCard.ino— sketch sourceexamples/Fx/FxSdCard/data/video.rgb→video.fledexamples/Fx/FxSdCard/data/color_line_bubbles.rgb→color_line_bubbles.fledexamples/Fx/FxSdCard/data/screenmap.json→ deleted (embedded in both.fledfiles)examples/Fx/FxSdCard/data/readme.txt— short rewrite- (Optional)
dev/wrap-fled.mjs— one-time conversion helper
Out of scope
- Adding new pixel formats (
gray8,rgba8, etc.) to this sketch — keep itrgb8for the canonical demo. - WASM integration — covered by Phase 4 of Parse embedded screenmap.json from .rgb / MPEG1 / MP4 videos + WASM screenmap import binding #3063.
- MPEG1 / MP4 variants — separate sketches, separate FastLED-side phases.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Jun 15, 2026
Attaching the FLED v1 spec inline so FastLED contributors don't need to cross-repo navigate. The canonical, kept-up-to-date copy lives at https://github.com/zackees/ledmapper/blob/main/docs/fled-format.md.
FLED Video Container Format — v1
A self-describing container for LED-data video files. A
.fledfile holdsraw pixel frames for an LED layout alongside the screenmap that drove the
recording, so a video and its display geometry stay paired in one file.
This document is the canonical spec. The generator lives at
ledmapper and the consumer lives at
FastLED.
Status
.fledapplication/vnd.fastled.videoFLED(0x46 0x4C 0x45 0x44)File layout
magicFLEDversionu8, currently1pixel_formatu8enum (see below)reservedjson_lengthu32LE — length of JSON in bytesjson_bytespayloadledCount × bytesPerLed[format]The fixed header is 12 bytes.
json_lengthis variable (typically 100–2000bytes). Total payload size is
frame_count × ledCount × bytesPerLed.Pixel format enum
0x00rgb80x01gray80x02rgba80x03rgbw80x04rgb565le0x05–0xFFConsumers must reject unknown
pixel_formatvalues with a clear error("video format
0xNNis not supported by this player"). They must notattempt to fall back to
rgb8on unknown values.JSON payload
A superset of the existing screenmap.json. The pixel format is
deliberately not carried in JSON — it lives in the binary header so
consumers can slice frames without parsing JSON at all.
{ "map": { "strip1": { "x": [0.0, 1.0], "y": [0.0, 0.0], "diameter": 0.25 } }, "video": { "fps": 60 } }mapScreenMapschema. LED count derives from the total point count across all strips.video.fpsAuthors must not write
video.format— it would be a redundant secondsource of truth. Consumers must ignore any
video.formatkey ifpresent (a v1 reader cannot trust JSON over the header).
Versioning
versionstarts at1. A bump is required for any breaking change to:pixel_formatenum is not a versionbump — unknown values already have a defined rejection behavior, so
forward-compatibility is free.
version> 1 file must reject it with"format version
Nis not supported".Backwards compatibility with legacy
.rgbFiles without the
FLEDmagic in the first 4 bytes are not FLED files.Tools that previously read raw headerless
.rgb(the legacy formatproduced before this spec) should magic-check before assuming the format:
re-record with the current Mapped Video Maker to get an embedded
screenmap.
.fledfiles going forward.Legacy headerless
.rgbis never written again.Test vectors
The canonical reference vectors live in
tests/unit/rgb-video.test.ts(ledmapper) and the equivalent FastLEDtests. A minimal valid file is:
46 4C 45 44 01 00 00 00 <json_length_u32_LE>{"map":{"a":{"x":[0],"y":[0]}}}(31 bytes UTF-8)FF 00 00(one frame, one LED, pure red)A "metadata-only"
.fledwith zero frames (12 + 31 = 43 bytes) is validand useful as a screenmap-only carrier.
See also
fixup: address CodeRabbit review (#3072)
feat(video): FLED v1 container support + FxSdCard accepts both formats (