APNG Disassembler: Extract Frames and Metadata from Animated PNGs
What it is
- A tool (script or application) that reads APNG files and splits them into individual PNG frames while extracting timing, frame-control flags, and other metadata.
Key features
- Frame extraction: exports each frame as a standalone PNG (preserving alpha).
- Metadata extraction: reads acTL, fcTL, fdAT chunks and outputs frame durations, sequence numbers, disposal/blend operations.
- Timing accuracy: converts frame delay units to milliseconds and reports total animation duration and per-frame delays.
- Lossless handling: preserves original compression and color/alpha data when possible.
- Reassembly support: optional output of a JSON/INI manifest to allow rebuilding the APNG in the same order with original metadata.
- Batch processing: handle multiple APNGs in a folder and generate uniform output structure.
- Validation: detects malformed APNG chunks, missing sequence numbers, or nonstandard chunk ordering.
Common uses
- Animation debugging and QA.
- Converting APNG to sprite sheets or video.
- Extracting frames for editing or analysis.
- Reverse-engineering frame timing and disposal/blend behavior.
- Creating fallback static PNGs or GIF conversions.
Inputs and outputs
- Input: .png file containing APNG chunks.
- Outputs: frame_N.png files, a manifest (JSON/CSV) with per-frame metadata (delay_ms, sequence, width/height, blend_op, dispose_op), and an optional rebuilt .apng.
Implementation notes (practical)
- Parse PNG chunks sequentially; identify acTL (animation control), then fcTL/fdAT for frames.
- fcTL contains width/height/x_offset/y_offset, delay_num/delay_den (compute ms = 1000delay_num / delay_den), dispose_op, blend_op.
- fdAT chunks carry frame image data with a sequence number; combine fdAT/IDAT data appropriately.
- Preserve IHDR/color/chunk ordering for standalone frames; reconstruct valid PNGs by inserting fcTL-derived dimensions into IHDR if different.
- Handle missing delay_den (treat as 100) and very small delays (floor to 1–20 ms depending on target).
- Consider using existing libraries (libpng, pngcrush, apngdis, apngasm) where available to avoid reimplementing low-level PNG parsing.
Output manifest example (fields)
- frame_index, filename, delay_ms, seq_num, width, height, x_offset, y_offset, blend_op, dispose_op
Limitations and gotchas
- Some APNGs use nonstandard or corrupted chunks—tool should warn and skip or attempt repair.
- Accurate timing depends on delay_den; some creators omit it or use unconventional values.
- Reconstructed frames may differ visually if ancillary chunks (sRGB, gamma) are dropped—preserve relevant chunks when exporting.
If you want, I can:
- Provide a short Python script that extracts frames and writes a JSON manifest.
- Recommend existing open-source APNG disassembler tools.
Leave a Reply