The first content cue in the old SRT still starts at 00:00:05,000:

2 00:00:05,000 --> 00:00:07,400 Open the project root and look at package.json. 

On the edited file, after a 3-second intro has been removed, that same line is spoken at 00:00:02,000. The caption does not appear until 00:00:05,000, so it lands three seconds late, on top of whatever is said next.

The rest of this post uses a short, constructed SRT to reproduce that bug, measure whether the slip is a single fixed offset, shift the cues, and check the result for negative times, inverted cues, and timestamps that run past the end of the video. The sample is not a caption file from a published lesson.

Confirm the offset at both ends

A single shift is only safe if the timing change is the same throughout the file, such as one intro cut or one title card added at the start. If later chapters were trimmed or rearranged, the last caption will slip by a different amount from the first.

To check that, take one cue near the start of the remaining picture and one cue near the end. Play the edited video, note when each line is actually spoken, and subtract:

offset = time in the old SRT - time in the edited video

In this sample, the first remaining line is late by 00:00:05,000 - 00:00:02,000 = 3.000s. The last line in the old SRT starts at 00:01:01,200; on the edited video it is spoken at 00:00:58,200. That is also 3.000s. The two ends agree, so a fixed shift of -3 seconds is the right repair for this file.

If those two measurements had disagreed, a global shift would make part of the file worse. That case is covered in the last section.

A minimal SRT and a timing checker

Here is the constructed file, sample-original.srt. Cue 1 is the intro that was cut. Cues 2-4 are the lines that should remain. The edited video is 61.5 seconds long (a 64.5-second original minus the 3-second intro).

1 00:00:00,400 --> 00:00:02,800 Thanks for watching. I'll cut this intro in the edit. 2 00:00:05,000 --> 00:00:07,400 Open the project root and look at package.json. 3 00:00:18,200 --> 00:00:21,000 Install the dependencies, then start the dev server. 4 00:01:01,200 --> 00:01:03,800 That's the complete setup. I'll see you in the next video. 

The script below parses the file, applies a fixed offset, and then checks three timing bounds: no negative timestamp, start earlier than end, and no cue ending after the video duration. Pass the offset with an equals sign, --shift=-3s, so the leading minus is not read as a new flag.

#!/usr/bin/env python3 """Shift SRT cues by a fixed offset and check timing bounds. The checker flags negative timestamps, cues whose start is at or after their end, and cues that run past the video duration. It does not check whether the words still match the picture; that still needs a playback spot-check. """ from __future__ import annotations import argparse import re import sys from dataclasses import dataclass from pathlib import Path TS_RE = re.compile( r"(\d{2}):(\d{2}):(\d{2}),(\d{3})\s-->\s(\d{2}):(\d{2}):(\d{2}),(\d{3})" ) def ts_to_ms(h: str, m: str, s: str, ms: str) -> int: return (((int(h) * 60 + int(m)) * 60) + int(s)) * 1000 + int(ms) def ms_to_ts(ms: int) -> str: sign = "-" if ms < 0 else "" ms = abs(ms) hours, rem = divmod(ms, 3_600_000) minutes, rem = divmod(rem, 60_000) seconds, millis = divmod(rem, 1_000) return f"{sign}{hours:02d}:{minutes:02d}:{seconds:02d},{millis:03d}" def parse_offset(value: str) -> int: """Accept 3s, -3.5s, 3000ms, or -00:00:03,000.""" text = value.strip().lower() if re.fullmatch(r"-?\d{2}:\d{2}:\d{2},\d{3}", text): sign = -1 if text.startswith("-") else 1 match = re.search(r"(\d{2}):(\d{2}):(\d{2}),(\d{3})", text) assert match is not None return sign * ts_to_ms(*match.groups()) if text.endswith("ms"): return int(float(text[:-2])) if text.endswith("s"): return int(round(float(text[:-1]) * 1000)) return int(float(text)) @dataclass class Cue: index: int start_ms: int end_ms: int text: str def parse_srt(raw: str) -> list[Cue]: chunks = re.split(r"\n\s*\n", raw.strip()) cues: list[Cue] = [] for chunk in chunks: lines = [line for line in chunk.splitlines() if line.strip() != ""] if len(lines) < 2: continue timing_i = 0 index = len(cues) + 1 if TS_RE.search(lines[0]) is None: try: index = int(lines[0].strip()) except ValueError: raise SystemExit(f"Could not parse cue index in block:\n{chunk}") timing_i = 1 if timing_i >= len(lines): raise SystemExit(f"Missing timing line in block:\n{chunk}") match = TS_RE.search(lines[timing_i]) if not match: raise SystemExit(f"Could not parse timing in block:\n{chunk}") start_ms = ts_to_ms(*match.groups()[0:4]) end_ms = ts_to_ms(*match.groups()[4:8]) text = "\n".join(lines[timing_i + 1 :]).strip() cues.append(Cue(index, start_ms, end_ms, text)) return cues def format_srt(cues: list[Cue]) -> str: blocks = [] for i, cue in enumerate(cues, start=1): blocks.append( f"{i}\n{ms_to_ts(cue.start_ms)} --> {ms_to_ts(cue.end_ms)}\n{cue.text}" ) return "\n\n".join(blocks) + "\n" def shift_cues(cues: list[Cue], offset_ms: int) -> list[Cue]: return [ Cue(cue.index, cue.start_ms + offset_ms, cue.end_ms + offset_ms, cue.text) for cue in cues ] def check_cues(cues: list[Cue], duration_ms: int | None) -> list[str]: issues: list[str] = [] for i, cue in enumerate(cues, start=1): label = f"cue {i} ({ms_to_ts(cue.start_ms)} --> {ms_to_ts(cue.end_ms)})" if cue.start_ms < 0 or cue.end_ms < 0: issues.append(f"{label}: negative timestamp") if cue.start_ms >= cue.end_ms: issues.append(f"{label}: start is at or after end") if duration_ms is not None and cue.end_ms > duration_ms: issues.append( f"{label}: ends after video duration {ms_to_ts(duration_ms)}" ) return issues def main(argv: list[str] | None = None) -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("srt_path", help="Path to an .srt file") parser.add_argument( "--shift", default="0s", help="Offset to apply, such as -3s, 3000ms, or -00:00:03,000", ) parser.add_argument( "--duration", default=None, help="Edited video duration, such as 61.5s or 00:01:01,500", ) parser.add_argument( "--drop-before-zero", action="store_true", help="Drop cues that end at or before 00:00:00,000 after the shift", ) parser.add_argument( "--write", default=None, help="Optional path to write the shifted SRT", ) args = parser.parse_args(argv) raw = Path(args.srt_path).read_text(encoding="utf-8") original = parse_srt(raw) if not original: raise SystemExit("No cues found in the SRT file") offset_ms = parse_offset(args.shift) duration_ms = parse_offset(args.duration) if args.duration else None shifted = shift_cues(original, offset_ms) dropped = 0 if args.drop_before_zero: kept = [cue for cue in shifted if cue.end_ms > 0] dropped = len(shifted) - len(kept) shifted = kept print(f"Cues read: {len(original)}") print(f"Shift: {ms_to_ts(offset_ms)} ({offset_ms} ms)") if duration_ms is not None: print(f"Duration: {ms_to_ts(duration_ms)}") if args.drop_before_zero: print(f"Dropped cues ending at or before zero: {dropped}") print(f"Cues after drop: {len(shifted)}") print() print("Before After") # When cues were dropped, pair by original index where possible after_by_index = {cue.index: cue for cue in shifted} for before in original: after = after_by_index.get(before.index) before_span = f"{ms_to_ts(before.start_ms)} --> {ms_to_ts(before.end_ms)}" if after is None: after_span = "(dropped)" else: after_span = f"{ms_to_ts(after.start_ms)} --> {ms_to_ts(after.end_ms)}" print(f"{before_span:<24} {after_span}") print(f" {before.text.replace(chr(10), ' / ')}") print() issues = check_cues(shifted, duration_ms) if issues: print(f"Check: {len(issues)} issue(s)") for issue in issues: print(f" - {issue}") if args.write: print("Did not write output because the check found issues.", file=sys.stderr) return 1 print("Check: no timing-bound issues") if args.write: Path(args.write).write_text(format_srt(shifted), encoding="utf-8") print(f"Wrote {args.write}") return 0 if __name__ == "__main__": sys.exit(main()) 

Save it as check_srt.py and run it on the original file first, without dropping any cues:

python3 check_srt.py sample-original.srt --shift=-3s --duration=61.5s 

This is the output from that run:

Cues read: 4 Shift: -00:00:03,000 (-3000 ms) Duration: 00:01:01,500 Before After 00:00:00,400 --> 00:00:02,800 -00:00:02,600 --> -00:00:00,200 Thanks for watching. I'll cut this intro in the edit. 00:00:05,000 --> 00:00:07,400 00:00:02,000 --> 00:00:04,400 Open the project root and look at package.json. 00:00:18,200 --> 00:00:21,000 00:00:15,200 --> 00:00:18,000 Install the dependencies, then start the dev server. 00:01:01,200 --> 00:01:03,800 00:00:58,200 --> 00:01:00,800 That's the complete setup. I'll see you in the next video. Check: 1 issue(s) - cue 1 (-00:00:02,600 --> -00:00:00,200): negative timestamp 

Cue 2 has moved to 00:00:02,000, which is the expected time. Cue 4 has moved to 00:00:58,200, which matches the end-point measurement. Cue 1, the intro, now starts before zero, and the checker flags it.

Drop that cue and write the repaired file:

python3 check_srt.py sample-original.srt --shift=-3s --duration=61.5s --drop-before-zero --write sample-shifted.srt 
Cues read: 4 Shift: -00:00:03,000 (-3000 ms) Duration: 00:01:01,500 Dropped cues ending at or before zero: 1 Cues after drop: 3 Before After 00:00:00,400 --> 00:00:02,800 (dropped) Thanks for watching. I'll cut this intro in the edit. 00:00:05,000 --> 00:00:07,400 00:00:02,000 --> 00:00:04,400 Open the project root and look at package.json. 00:00:18,200 --> 00:00:21,000 00:00:15,200 --> 00:00:18,000 Install the dependencies, then start the dev server. 00:01:01,200 --> 00:01:03,800 00:00:58,200 --> 00:01:00,800 That's the complete setup. I'll see you in the next video. Check: no timing-bound issues Wrote sample-shifted.srt 

The repaired file is:

1 00:00:02,000 --> 00:00:04,400 Open the project root and look at package.json. 2 00:00:15,200 --> 00:00:18,000 Install the dependencies, then start the dev server. 3 00:00:58,200 --> 00:01:00,800 That's the complete setup. I'll see you in the next video. 

The same checker can catch two other problems. These outputs are from separate runs of the same script.

An inverted cue, with the end earlier than the start:

python3 check_srt.py sample-inverted.srt 
Cues read: 1 Shift: 00:00:00,000 (0 ms) Before After 00:00:09,400 --> 00:00:09,100 00:00:09,400 --> 00:00:09,100 This cue is inverted: the end is earlier than the start. Check: 1 issue(s) - cue 1 (00:00:09,400 --> 00:00:09,100): start is at or after end 

A duration mismatch, using the repaired shift but a 55-second duration that is shorter than the last cue:

python3 check_srt.py sample-original.srt --shift=-3s --duration=55s --drop-before-zero 
Check: 1 issue(s) - cue 3 (00:00:58,200 --> 00:01:00,800): ends after video duration 00:00:55,000 

A wrong offset can still pass these checks. If the same file is shifted by -8 seconds and cues that fall before zero are dropped, the first content line is dropped as well, and the two cues that remain still sit inside the 61.5-second duration. The bound check reports no issues, but the words no longer line up with the picture. The script can tell you whether the timestamps are legal. It cannot tell you whether the speech still matches. After a shift, play two or three cues, including one near the end, and confirm they land on the right line.

When a single shift is not enough

If the edit was more than one trim at the start or end - for example, if several chapters were removed or reordered - the offset at the start and the offset at the end will not agree. In that case, do not force a global shift. Build a new caption file from the finished video, then run the same checker on that file.

One way to export an SRT from the edited MP4 is to upload the finished file and download the subtitle file it returns. A video to text converter that accepts a video upload can produce a timestamped transcript and an SRT from the final cut. Treat that file as a first draft: run the duration and inversion checks, then spot-check playback, especially on names, numbers, and any place where the picture was cut tightly.

This post was drafted with AI assistance. The sample SRT files and the command output above come from a local run of the script, not from invented numbers. I'm involved with the transcription tool linked in the previous section.