Skip to content

How do I cut a reproducible half-open frame interval for a swap test?

Define the excerpt as an inclusive starting frame and an exclusive ending frame, decode the intended video track, then verify the output count and boundary pictures. Frame-indexed extraction makes a reproducible test segment; typing a start second into different tools may not. Keep the source's original identity and distinguish this frame-count contract from a promise that a generated result preserves every source frame.

FRAME PREPARATION: REPRODUCIBLE CUTS AND GEOMETRYAISwapLab team · Editorial methodPublished 4 min read
See the recorded exampleExplore 67 Image SkillsIndependent finishing · Check the actual file
Editorial worksheet excerpt: Source interval; Expected frame count; Boundary pictures; Audio policy. See the complete table and sources below.
Editorial worksheet excerpt: Source interval; Expected frame count; Boundary pictures; Audio policy. See the complete table and sources below.

Frame-interval handoff

An editor might approve source frames 30 through 179 rather than an approximate five-second interval. That half-open range is [30,180), containing 150 decoded frames. Frame positions here are zero-based positions in the chosen decoded sequence, not packet indices or timeline timecode labels. A variable-frame-rate source may give those 150 frames a duration that is not exactly five seconds. The recipe deliberately extracts picture only so audio boundary choices remain explicit rather than being silently mismatched.

Build the evidence

  1. 01

    Agree on the coordinate system

    Record the file hash, moving video stream and zero-based frame convention. Mark the desired first and last actual pictures in an external editor. The end value means the first discarded frame, so one must be added when an editor supplies an inclusive last frame. Write that translation in the handoff instead of asking another operator to infer whether the last number is included.

  2. 02

    Trim and reset the local presentation origin

    The trim filter selects the frame interval and setpts rebases the first retained presentation time to zero. Re-encoding is necessary because selecting arbitrary decoded frames is not a pure stream-copy operation. The example's H.264 settings create a compatible test copy but do not prescribe the only valid delivery encoder. Do not add a new frame rate unless there is an explicit cadence requirement; that could duplicate or drop frames. Explicit passthrough output prevents the default synchronization policy from duplicating or dropping selected frames. The encoder uses the filter time base in this recipe. Container time-scale quantization or unsupported timestamp behavior still needs verification; frame membership and exact display-duration preservation are separate acceptance claims.

  3. 03

    Verify count, boundaries and actual duration

    The ffprobe query requests a decoded frame count on the exported moving stream. Compare that count with end minus start, then inspect the first and last saved pictures against the source approval. Measure actual output duration as a separate field. Before AISwapLab upload, confirm this particular copy meets the existing-video route's supported duration and size, and add an intentionally synchronized soundtrack only when required.

A bounded example

Local executed example: the test source had 180 frames at 30 fps. Applying start_frame=30 and end_frame=180 produced a 150-frame, five-second picture-only output under FFmpeg 7.1. The execution log reports the resulting frame count. That validates this constant-rate synthetic fixture; it does not establish the duration of an arbitrary variable-rate excerpt. The independent ffprobe count command was not run locally because ffprobe was unavailable. A reproducible excerpt also records whether source rotation or another interpretation transform was applied before the frame selection. Additional local VFR evidence used a synthetic irregularly sampled sequence and selected frames [30,90). With passthrough and the filter time base, a lossless H.264 verification variant produced 60 pictures whose decoded payload hashes matched the selected input pictures in order. That test does not promise identical samples from the ordinary lossy recipe or arbitrary muxer/time-base support.

Local diagnostic commands

Local FFmpeg 7.1 synthetic tests covered the original constant-rate interval and a VFR interval [30,90). The VFR verification used a lossless H.264 variant: 60 selected picture hashes matched in order. The published ordinary encode remains lossy; ffprobe was unavailable. No paid generation was performed.

shell
ffmpeg -n -i source.mp4 -map 0:V:0 -vf "trim=start_frame=30:end_frame=180,setpts=PTS-STARTPTS" -fps_mode passthrough -enc_time_base filter -an -c:v libx264 -pix_fmt yuv420p excerpt.mp4
ffprobe -v error -select_streams V:0 -count_frames -show_entries stream=nb_read_frames,duration -of json excerpt.mp4

Frame-interval handoff

FieldExampleVerification
Source interval[30,180)Zero-based and end-exclusive
Expected frame count150Decoded output count
Boundary picturesSource 30 and 179Side-by-side first/last pictures
Audio policyExcluded in this recipeAdd only with deliberate alignment

Acceptance evidence

  • The interval states zero-based indexing and exclusive end explicitly.
  • The exported frame count equals the approved interval length before any rate conversion.
  • Boundary pictures, not just duration, match the approved excerpt.
  • Audio and upload eligibility remain independent acceptance decisions.

Stop condition

Stop if the approving editor and the extraction tool cannot identify the same frame sequence. Do not keep adjusting endpoint numbers until a visually convenient result appears. Resolve source version, stream selection and indexing first. If exact decoded-frame membership is unnecessary, a simpler timed excerpt may be the more appropriate workflow.

Sources

Review the result in context.

Compare the recorded example and its documented limitations.

See the recorded example