Skip to content

Ripple shift, trim and swap

rereel patch <reel_dir> <op> makes deterministic edits that would be error-prone by hand. Every op prints one JSON line and only rewrites JSON and SRT files.

Insert or remove time at a point, and move everything after it.

Terminal window
# Remove 0.5 s at 12.0 s (e.g. after deleting a pause)
npx @mathrunet/rereel patch reels/ep01 ripple-shift --at-sec 12.0 --delta-sec -0.5
# Insert 1.2 s at 30 s
npx @mathrunet/rereel patch reels/ep01 ripple-shift --at-sec 30 --delta-sec 1.2
{"status":"patched","atSec":12,"deltaSec":-0.5,"filesUpdated":["props.json","mix_plan.json","timing.json","captions.srt"]}

filesUpdated lists the files that existed and were rewritten. The same rules apply to all four files.

The patcher walks every object recursively and applies these rules (with a 1 µs tolerance):

Field Shifted when
start_sec, at_sec value ≥ at-sec
end_sec value > at-sec
fromFrame, atFrame, startFrame value ≥ round(at-sec × fps)
endFrame value > round(at-sec × fps)
top-level duration_sec (props, mix_plan, timing) always
top-level durationInFrames (props) always, minimum 1
mix_plan.speech[[a, b]] a ≥ at-sec / b > at-sec
captions.srt cue start / end same as start_sec / end_sec

Seconds are rounded to 0.1 ms and clamped at 0. Frame deltas use round(delta-sec × fps) with fps from rereel.json.

An item that spans the shift point keeps its start, and its end moves, so it grows or shrinks. Objects under keys named anchor or end_anchor are not traversed.

  • src_start_sec, duration_sec and durationInFrames on individual items (source offsets and per-item lengths are not timeline positions)
  • startSec/endSec (camelCase) fields
  • any field not listed above

Adjust one narration segment in mix_plan.json by id:

Terminal window
npx @mathrunet/rereel patch reels/ep01 trim-segment --id seg_004 \
--src-start-sec 12.38 --duration-sec 2.10 --start-sec 9.6 --gain-db -1.5
{"status":"patched","segmentId":"seg_004"}
Flag Field set Notes
--src-start-sec src_start_sec offset in the source file
--duration-sec duration_sec minimum 0.01
--start-sec start_sec timeline position
--gain-db gain_db added after loudness normalization

Only the flags you pass are changed. An unknown --id exits with code 2. trim-segment does not ripple: if the segment gets longer or shorter, follow up with ripple-shift at its end.

Replace every string in props.json and mix_plan.json that exactly equals --old with --new:

Terminal window
npx @mathrunet/rereel patch reels/ep01 swap-asset \
--old media/bgm_lofi_0d4e1f20.mp3 --new incoming/bgm_upbeat.mp3
{"status":"patched","replacements":2}

swap-asset does not touch rereel.lock.json, timing.json or captions.srt. When the new reference is a fresh file, re-run freeze on the reel so the file is hashed, stored and locked, and the reference rewritten to media/...:

Terminal window
npx @mathrunet/rereel freeze reels/ep01 --props reels/ep01/props.json --mix-plan reels/ep01/mix_plan.json
npx @mathrunet/rereel validate reels/ep01

Swapping to a reference that is already in the lockfile needs no re-freeze.

Terminal window
rereel inspect reels/ep01 # find the IDs and times
rereel patch reels/ep01 ripple-shift ... # or trim-segment / swap-asset
rereel validate reels/ep01 # must be "valid": true
rereel build reels/ep01 # check chunksRendered
git diff reels/ep01 # review the JSON diff

See the patch reference for all flags.