Skip to content

Add unlimited reference-driven MXF repair and reindexing - #294

Open
jpooley-hearst wants to merge 4 commits into
anthwlock:masterfrom
jpooley-hearst:codex/mxf-reference-repair-proposal
Open

Add unlimited reference-driven MXF repair and reindexing#294
jpooley-hearst wants to merge 4 commits into
anthwlock:masterfrom
jpooley-hearst:codex/mxf-reference-repair-proposal

Conversation

@jpooley-hearst

@jpooley-hearst jpooley-hearst commented Aug 5, 2026

Copy link
Copy Markdown

What changed

  • adds -mxf repair using a compatible known-good MXF reference
  • scans arbitrarily large recordings with fixed-size windows and 64-bit offsets
  • validates Operational Pattern, BodySID, IndexSID, stream count, codecs, raster, sample formats/rates, time bases, and codec configuration
  • copies only reference header metadata and preserves damaged-file essence
  • rewrites the recovered partition chain and removes stale random-index data
  • demuxes every recoverable packet and remuxes through FFmpeg's MXF/OP-Atom muxer
  • regenerates edit-unit indexes, durations, partition offsets, footer metadata, KAG layout, and RIP from recovered packets
  • removes structural intermediates and partial output on failure

Why

Interrupted broadcast and camera MXF recordings can retain usable essence while losing header, footer, index, or RIP metadata. MXF is KLV-based rather than atom-based, so this introduces a separate bounded streaming repair path while retaining untrunc's known-good-reference workflow.

Validation

  • make -j2
  • UNTRUNC=./untrunc tests/test-mxf-reference-repair.sh
  • real FFmpeg-generated OP-1a MPEG-2 video plus PCM audio fixture
  • 100 recovered/reindexed packets verified with ffprobe
  • destroyed-header recovery
  • reference-essence substitution guard
  • temporary-file cleanup check
  • Operational Pattern mismatch rejection
  • same-OP incompatible raster-profile rejection

@jpooley-hearst jpooley-hearst changed the title Add reference-driven MXF partition repair Add unlimited reference-driven MXF repair and reindexing Aug 5, 2026
@jpooley-hearst
jpooley-hearst marked this pull request as ready for review August 5, 2026 18:23
@anthwlock

Copy link
Copy Markdown
Owner

Hi, thank you for the PR. Could you please follow the coding style of the project in mxf.cpp? And it would be nice if you could merge the docs from ‎MXF_REFERENCE_REPAIR_PROPOSAL.md into mxf.cpp. Optimally documenting the code too. Perhaps at the top of the file a longer comment could be placed giving some "meta info".

Are there any references you used to figure out the file format? If so it would be nice to mention them (e.g. URLs etc). If you figured them out yourself, would also be worth noting IMO.

@jpooley-hearst

Copy link
Copy Markdown
Author

Addressed in 9137314.

  • Reworked src/mxf.cpp to match the project’s formatting/style more closely.
  • Merged the useful material from MXF_REFERENCE_REPAIR_PROPOSAL.md into a top-of-file overview and removed the now-redundant document.
  • Added comments around the KLV/BER parsing, Partition Pack fields and rebasing, profile validation, remuxing, and cleanup paths.
  • Documented the published MXF/KLV references (SMPTE ST 377-1 and ST 336), FFmpeg’s MXF implementation, and the relevant HVLC/libavformat integration. The comments also distinguish that reference material from the Untrunc-specific recovery procedure inferred from fixtures and damaged recordings.

Validation run locally:

  • make -j2
  • UNTRUNC=./untrunc tests/test-mxf-reference-repair.sh — recovered/reindexed 100 packets and rejected the deliberate Operational Pattern and raster-profile mismatches.
  • An additional destroyed-header repair using a real MXF fixture under M:\ClaudeLocal recovered the original 144 MPEG-2 packets, produced output distinct from the reference, and removed the temporary structural file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants