03:00:0050% OFFClaim

Hands-on recipe

Validate SRT cue overlap, duration and media boundaries

Reject ambiguous cue order, zero-length captions, overlap and past-end timing before rendering. This recipe only covers the declared simple SRT subset and a supplied two-second media boundary.

Includes executed local fixtures, scripts and receipts. These checks do not represent a video-generation service run.

Original task-specific local-fixture diagram
Original SRT text fixtures, actual parsed cue table and a unique timing-lane diagram. No subtitle rendering or model generation was performed.

01Prepare environment and inputs

  1. Use Node.js without any third-party package or FFmpeg. The duration.json fixture explicitly supplies a 2,000-millisecond media boundary.
  2. Read valid.srt: cue 1 spans 0–700 ms, cue 2 spans 700–1,400 ms and cue 3 spans 1,500–2,000 ms. Adjacent cues and a final end equal to media duration are allowed.
  3. Keep the strict format HH:MM:SS,mmm --> HH:MM:SS,mmm, sequential cue indices and nonempty text. The fixture is plain text and makes no font or burn-in claim.

02Run the recipe

Run command

node run-recipe.mjs --out ./my-run
  1. Define the timing policy before parsing

    The fixture uses integer milliseconds, sequential indices starting at one, no overlap and end > start. The media boundary is an explicit input; the script does not discover a video’s real duration. The one-hundred-millisecond gap before cue 3 is intentional.

  2. Parse the accepted cues

    Run the command and inspect cue-table.json. It contains the three actual parsed start/end values. A cue starting exactly at the previous cue’s end is accepted, and the last cue may end exactly at 2,000 ms.

  3. Replay six invalid subtitle files

    The runner writes and tests overlapping, zero-duration, past-boundary, wrong-index, malformed-millisecond and invalid-minute variants. Each expected rejection records its concrete validation error. A correctly shaped timestamp with a minute component of 60 is still invalid.

  4. Hand off validated timing for a separate render

    Check all nine assertions and retain the cue table beside the original SRT. Font coverage, line layout, reading speed, HTML extensions and rendered appearance remain separate tasks. This download contains no CJK font inventory or burned subtitle video.

03Check the result

  • The supplied valid.srt parses into exactly three cue rows with integer milliseconds.
  • Cue 2 starting at cue 1’s 700-ms end is accepted.
  • The final cue ending exactly at the 2,000-ms media boundary is accepted.
  • Overlap and zero-length cue variants are rejected with different recorded reasons.
  • A cue ending at 2,001 ms and nonsequential numbering are rejected.
  • Malformed milliseconds and a minute component of 60 are rejected; all nine checks pass.

04Troubleshoot and deliver

Adjacent captions are incorrectly flagged as overlap.

Use start >= previousEnd for the no-overlap rule and rerun the 700-ms boundary case.

The last cue is rejected at the video end.

Verify the supplied durationMilliseconds first. If it is correct, allow end equal to that boundary while still rejecting 2,001 ms.

A well-formatted cue has no visible time.

Change only end so it is strictly later than start, then recheck overlap against the next cue. Do not delete the zero-duration rule.

Validated timings are a handoff input for a render stage. They do not prove a particular font displays, captions fit the frame or viewers can comfortably read the text.

05Download scripts and fixtures