Nodes/ComfyUI-CustomNodePacks/Metadata Writer (MEC)
ComfyUI Node

Metadata Writer (MEC)

Drop a JSON sidecar next to your image without breaking the wire

By Code2Collapse·Created 6 months ago·Updated a day ago· 52
Metadata Writer (MEC)
  • image
  • image
  • written_path
sidecar_path
metadata_json{}
merge_existingfalse

Simple job, quietly important: Metadata Writer (MEC) writes a JSON sidecar file to disk and passes your image straight through. You drop it in the middle of a wire - image in, image out, file written on the side - and suddenly every render can carry provenance, prompt text, version tags, or whatever structured data you want, without touching the pixels or the PNG header.

It's an output node (OUTPUT_NODE = True), so it counts as a graph endpoint the same way Save Image does. This is the "you'll be glad you had it when you're hunting through 400 renders for the one with seed 12345" node.

How it works

Three inputs:

  • image - passed through untouched.
  • sidecar_path - a filesystem path for the .json file. Required; the node raises if it's empty. The directory is created automatically.
  • metadata_json - the payload as a JSON string (multiline widget, default {}). If it isn't valid JSON, the node raises and tells you - a strictness that saves you from silently corrupt sidecars.

One optional: merge_existing. When on and the target file already exists, it reads the old JSON and merges the new payload into it (new keys win). That's the mode for accumulating metadata across passes instead of overwriting. Outputs: image and written_path (the path with forward slashes, handy for logging or wiring downstream).

The patterns worth stealing

  • Provenance per render. Wire a text node with the prompt, seed, sampler, and version string from this pack's Folder Incrementer, and every render gets a sidecar you can grep. This is the lightweight alternative to embedding metadata in PNG chunks, and it survives formats that strip PNG metadata (looking at you, video codecs).
  • Pass labels. Set merge_existing on and each stage appends its stage info, building up a full history next to the file.
  • Batch logging. Because it passes the image through, you can splice it into a video frame batch and write per-batch metadata without restructuring anything.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/Code2Collapse/ComfyUI-CustomNodePacks.git

or ComfyUI Manager → search "CustomNodePacks", restart, confirm [MEC] Loaded .... No dependencies - it's stdlib json/os. The two errors you'll hit are both self-explanatory: empty sidecar_path, or invalid metadata_json. If the file isn't appearing, remember ComfyUI's working directory is the base it resolves relative paths against - use an absolute path and the mystery goes away.

CategoryMaskEditControl/Metadata

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
sidecar_pathSTRING
metadata_jsonSTRING{}
merge_existingoptBOOLEANfalse

Outputs (2)

NameTypeDescription
imageIMAGE
written_pathSTRING