feat: add --sample-frames N preview/sample mode#157
feat: add --sample-frames N preview/sample mode#157shezmic wants to merge 2 commits intonikopueringer:mainfrom
Conversation
Adds `--sample-frames N` to `run-inference`. When set, N evenly-spaced
frames are selected across the clip timeline, processed with full
inference, and written to `Output/Sample/{FG,Matte,Comp,Processed}/`
— never polluting the real render output.
- `_compute_sample_indices(n, total)` helper produces evenly-spaced
indices via floating-point step; a set deduplicates rounding ties
- Sequential `VideoCapture` caps are only opened in normal mode;
sample mode uses per-frame seeking via `read_video_frame_at()`
- Output filenames use the actual source frame index (e.g. `00125.exr`)
for direct correlation back to the source clip
- Comp video stitch is skipped in sample mode (non-sequential frame
names break ffmpeg's glob pattern); a log line explains this
- `--sample-frames` Typer option added to `run-inference` subcommand
- Tests: help flag assertion extended; passthrough kwarg test added
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The output-dir redirect and index computation both guard with `sample_frames is not None and sample_frames > 0`, but the stitch guard used only `sample_frames is not None`. With `--sample-frames 0` this caused all frames to be processed into Output/ (not Output/Sample/), while the video stitch was still skipped — silently producing an incomplete real render in the main output dir. Aligning the stitch guard to `sample_frames is not None and sample_frames > 0` makes all three checks consistent: --sample-frames 0 is now treated identically to omitting the flag (no sampling, normal stitch behaviour). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
If the user wants to sample fewer frames, I feel that they should implement that by simply exporting a sequence form their editing program that contains less frames. Likewise, I don't think using the source file number for the output file number is necessarily a desired action. I'm sure for some power users it would be nice to maintain timecode through file name, but for most users I think they're going to find themselves with messy filenames, as opposed to a clean readable sequence. I'm in favor of fewer, focused features, and a simpler code base, personally. |
|
That's a fair point — the NLE export workflow already handles this cleanly, and adding a sampling layer inside CorridorKey duplicates something the artist's editing software does better. The timecode-based filename concern is also valid; a clean sequential output is more predictable for most users. Closing this one. Happy to keep contributing in areas that align with the simpler codebase direction. |
Summary
--sample-frames Nflag torun-inference. Picks N evenly-spaced frames across the clip timeline, runs full inference on those only, and writes output toOutput/Sample/— never mingles with a real render._compute_sample_indices(n, total)helper: floating-point step, set deduplication for rounding ties, edge cases forn=1andn≥totalVideoCapturepath is untouched — caps are only opened in normal mode; sample mode usesread_video_frame_at()for per-frame seeking (already existed inbackend/frame_io.py)00125.exrnot00001.exr) for direct correlation back to the clip timeline%05dglob pattern); a log message explains this--sample-framespassthrough kwarg; 1 extended: help flag assertion)Why it was needed
Running full inference on a 500-frame clip to validate despill or colorspace settings wastes significant time.
--max-framesonly covers the first N frames, missing midpoint/end conditions. Sample mode lets users validate settings quickly across the whole clip, then drop the flag for the full render.How to verify
uv run pytest --tb=short -q uv run corridorkey run-inference --help # --sample-frames appears in outputManual (with clips present):
Fix (added post-review)
Stitch guard inconsistency —
clip_manager.pyline 837The output-dir redirect (line 652) and index computation (line 669) both guard with
sample_frames is not None and sample_frames > 0. The stitch guard used onlysample_frames is not None.With
--sample-frames 0this caused all frames to run intoOutput/(notOutput/Sample/) while the video stitch was still skipped — silently producing an incomplete render in the main output directory rather than the sample subdirectory.Fixed by aligning the stitch guard to
sample_frames is not None and sample_frames > 0, making all three guards consistent.--sample-frames 0now behaves identically to omitting the flag entirely (normal mode, stitch runs).Commit:
cc4d906