Skip to content

Fix capture frame interval handling#50

Open
grawis wants to merge 1 commit into
sysprog21:masterfrom
grawis:fix-frame-interval
Open

Fix capture frame interval handling#50
grawis wants to merge 1 commit into
sysprog21:masterfrom
grawis:fix-frame-interval

Conversation

@grawis

@grawis grawis commented Jun 9, 2026

Copy link
Copy Markdown

Summary

Fix the mismatch between the frame interval reported through
VIDIOC_G_PARM and the actual capture timing.

The previous implementation calculated:

denominator / numerator

For the default 1001/30000 time-per-frame value, this produces about
29.97, which represents frames per second, but was treated as milliseconds.

The new implementation calculates:

frame interval in jiffies = numerator * HZ / denominator

It then subtracts the frame processing time before sleeping, so the actual
capture period follows the configured V4L2 time-per-frame value.

Other changes:

  • Rename output_fps to frame_interval because it stores seconds per
    frame, not frames per second.

  • Clamp VIDIOC_S_PARM values to the range advertised by
    VIDIOC_ENUM_FRAMEINTERVALS.

  • Reuse the same interval definitions for enumeration, initialization,
    setting, reporting, and frame pacing.

Test results

Before:

Frame interval: reported=33.367 ms measured=29.989 ms
error=10.1% [FAIL]

After:

Frame interval: reported=33.367 ms measured=33.997 ms
error=1.9% [PASS]

Additional tests:

25 FPS: reported=40.000 ms measured=41.008 ms error=2.5% [PASS]
YUYV: reported=33.367 ms measured=34.012 ms error=1.9% [PASS]

Fixes #49


Summary by cubic

Fixes incorrect frame pacing by computing and applying the V4L2 time-per-frame correctly. Reported and actual intervals now align, reducing timing error from ~10% to ~2%.

  • Bug Fixes
    • Compute frame interval in jiffies: numerator * HZ / denominator.
    • Subtract processing time before sleeping to keep the configured period.
    • Rename output_fps to frame_interval (seconds per frame).
    • Clamp VIDIOC_S_PARM to the range from VIDIOC_ENUM_FRAMEINTERVALS.
    • Define shared min/max/default intervals and reuse them for enum/init/get/set/pacing.

Written for commit ef4fd9e. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

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.

Actual capture frame interval differs from VIDIOC_G_PARM

1 participant