Skip to content

fix(cli): measure picks more than 100 frames on ffmpeg 8 - #7071

Merged
WaterrrForever merged 2 commits into
mainfrom
miao/select-depth-ffmpeg8
Nov 3, 2026
Merged

WaterrrForever merged 2 commits into
mainfrom
miao/select-depth-ffmpeg8

Conversation

@WaterrrForever

Copy link
Copy Markdown
Collaborator

What

ffmpeg 8 refuses a flat sum of more than 100 terms (Error while parsing expression 'eq(n,0)+eq(n,6)+…'). Every frame pick in measure, diff and snapshot was one flat sum of eq(n\,k), and the ffmpeg HyperFrames downloads is 8.1.2. So measure frames, diff, measure face, person and drawn-box reads, and snapshot failed once they picked more than 100 frames. ffmpeg 6 accepts it, which is why this didn't show up on our machines.

PostHog (CLI project, since 0.9.3): all of these cli_errors came from Windows agents on ffmpeg 8, for example measure frames with -frames:v 237.

sumOf in measure/media.ts keeps a sum of up to 100 terms flat (so today's filters and their tests are unchanged) and nests a longer one in halves. All six builders use it.

Test plan

fails without the fix: measure/media.test.ts "decodes all 237 picked frames" (on ffmpeg 8)

  • Bisected on ffmpeg 8.1.2: 100 terms pass, 101 fail. With sumOf, 101 / 237 / 1000 / 5000 picks return exactly that many frames.
  • With ffmpeg 8.1.2 first on PATH, the new test passes with the fix and fails without it. CI's ffmpeg may be older, so there it only checks that the filter decodes.
  • src/measure and snapshot tests (186), typecheck, bun run lint.

ffmpeg 8 refuses a flat sum of more than 100 terms ("Error while parsing
expression"), and every frame pick in measure, diff and snapshot was one flat
sum of eq(n,k). The ffmpeg HyperFrames downloads is 8.1.2, so measure frames,
diff, face, person, drawn boxes and snapshot all failed past 100 frames.
PostHog: every such cli_error since 0.9.3 came from Windows agents on ffmpeg 8.

sumOf keeps a sum of up to 100 terms flat and nests a longer one in halves.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 82a94cd28544c3854fca3905e2ae82e56b0c908d.

Important — the 100-term leaf limit still exceeds ffmpeg 8.1.2's parser budget once wrapped (packages/cli/src/measure/media.ts:37–39; snapshot's deeper terms at commands/snapshot.ts:722–725). All production builders use the helper, but grouping and the surrounding functions consume depth too. The 237-pick test happens to split into safe leaves of 59/60.

I reproduced with the cached ffmpeg 8.1.2, reading the exact helper from this head: equation selectors with 199, 200, 201, 399, 400 and 401 terms fail with Error while parsing expression; snapshot's actual select=gt(...)/gte/gt/if term shape also fails at 97–100 offsets and those larger counts. The same input contexts pass with only the leaf limit changed to 50 in an isolated control. 237 passes at this head. Our system ffmpeg 8.0.1 accepts the old flat expressions, so that build alone cannot establish the reported regression.

Fix: reserve parser-depth headroom in the helper, for example use 50-term leaves, and add actual ffmpeg regressions for 199/200 picks and snapshot 97/100 offsets. Test the full expression context, not only occurrence counts or the friendly 237 split. This closes the same partial-fix class across the shared callers.

Validation: full workspace build succeeds; CLI bun run test src/measure src/commands/snapshot.test.ts → 186 passed / 16 files on the system toolchain. The new media file also passes all 3 tests with cached ffmpeg 8.1.2 first on PATH, illustrating why the lone 237 decode misses the boundary failure. Independent ffmpeg 8.1.2 parser controls reproduce the failures above and the smaller-leaf control passes all tested 95–101, 199–201, 237, 399–401 and 1000 counts in both contexts. Script/log archived locally; no production source mutation for these controls. No Windows agent or bug-bash film rerun claimed.

Need: yes · Size: ok · Reuse: shared sumOf is the right boundary · Simpler: retain the helper with a conservative leaf budget · Structure: fine
Risk: medium — ordinary frame counts still fail in the ffmpeg version this fixes.

Verdict: REQUEST CHANGES
Reasoning: The helper fixes 237 picks but leaves other common counts and snapshot expressions broken on ffmpeg 8.1.2. Reduce leaf depth and pin the missing boundaries.

— hf-review

Review (hf-review): 100-term leaves still failed on ffmpeg 8.1.2 once nested,
at 199-201 eq() picks, and snapshot's deeper terms failed at 97-100 times.
ffmpeg 8 limits how deep an expression nests, and a flat sum counts a level
a term. Leaves of 50 pass every count from 1 to 1000 in both shapes, and
1500-5000. Tests decode 199/200/237/401 picks and 97/100/199 snapshot times.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at e75e00b6e5ae4e31093887a3c9086e01a776ca31, delta from my earlier change request at 82a94cd28.

The parser-depth blocker is fixed (packages/cli/src/measure/media.ts:39–42): sums split above 50 terms, leaving room for snapshot's surrounding calls. All six frame-selection builders keep using the shared helper. The new decode regressions include the previously failing 199/200/401 eq selections and 97/100/199 snapshot selections (media.test.ts:46–53).

Validation: full root bun run build, CLI typecheck and lint of the eight changed files passed. With FFmpeg 8.1.2, bun run --cwd packages/cli test src/measure src/commands/snapshot.test.ts reports 192 passed across 16 files. Separate independent exact-source probes, also rerun by me with node review-artifacts/7071-r2/adversarial.mjs in the review workspace, pass 83/83: 69 parser cases across eq/between/snapshot shapes through 5,000 terms, plus 14 full-byte frame-selection comparisons across uneven runs and snapshot offsets. Restoring the old 100-term leaf in the probe produces 31 parser failures, so this evidence distinguishes the earlier bug. The probe is review scratch, outside the committed suite.

Nit: the PR body's implementation paragraph still says sums remain flat through 100 terms; update it to 50.

Scope: re-reviewed the helper/test delta and its measure/diff/snapshot callers. No Windows host or affected user's original clip was run; the parser/semantic checks used the actual Linux FFmpeg 8.1.2 binary. The author's exhaustive 1–1,000 sweep was not repeated. Large parser probes use FFmpeg filter scripts and do not establish operating-system command-line length limits.

Need: yes · Size: ok · Reuse: shared sumOf across frame selectors · Simpler: smaller leaves in the existing balanced expression · Structure: fine
Risk: low — bounded expression construction with discriminating decoder coverage.

Verdict: APPROVE
Reasoning: The old nested-expression failures now pass on FFmpeg 8.1.2 with frame bytes preserved, and no new blocking defect was found in the delta.

— hf-review

@WaterrrForever
WaterrrForever added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit e9de593 Nov 3, 2026
68 of 69 checks passed
@WaterrrForever
WaterrrForever deleted the miao/select-depth-ffmpeg8 branch November 3, 2026 10:31
@WaterrrForever WaterrrForever mentioned this pull request Nov 3, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants