Skip to content

fix: enumerate V4L2 formats without frame sizes or frame intervals - #187

Merged
kekyo merged 2 commits into
kekyo:developfrom
Roman3349:fix/v4l2-frame-intervals
Nov 9, 2026
Merged

kekyo merged 2 commits into
kekyo:developfrom
Roman3349:fix/v4l2-frame-intervals

Conversation

@Roman3349

Copy link
Copy Markdown
Contributor

Some V4L2 drivers, such as the ones of analog video grabbers (EasyCAP and similar, em28xx, stk1160, usbtv), don't implement VIDIOC_ENUM_FRAMEINTERVALS, and some don't implement VIDIOC_ENUM_FRAMESIZES either. Their frame rate follows the video standard (PAL, NTSC) instead. FlashCap builds the video characteristics only from these enumerations, so such a device is listed with no characteristics and cannot be opened.

Fixes #148

@marakhand, could you try this branch with your grabber? It would confirm the fix on a real device, since I could only test it with the vivid test driver.

Changes

V4L2Devices falls back when an enumeration returns nothing:

  • Frame intervals: the current frame rate from VIDIOC_G_PARM (timeperframe). When that is not available either, the frame rate of the video standard from VIDIOC_G_STD: 25 fps for the 625/50 standards (PAL, SECAM), 30000/1001 fps for the 525/60 ones (NTSC, PAL-M).
  • Frame sizes: the size the driver adjusts a format to with VIDIOC_TRY_FMT, for each pixel format.

The ioctl numbers are already in the generated per-architecture interop. v4l2_streamparm and v4l2_std_id are passed as byte arrays with fixed offsets, because their layout is the same on all architectures, so the existing ioctl<T> can pin them and no generated code changes.

V4L2Device selects the format with VIDIOC_S_FMT and does not set the frame rate, so the fallback frame rate is only reported in VideoCharacteristics.

Drivers which do enumerate sizes and intervals behave as before.

Testing

  • Builds for all target frameworks (net35 ... net10.0) without warnings.
  • FlashCap.Core.Tests pass.
  • vivid on Linux x86_64, .NET 10:
    • Without changes to the driver behavior, the same 750 characteristics as before are listed and capturing works.
    • vivid does enumerate frame intervals for its TV and S-Video inputs on current kernels, so it doesn't reproduce the issue by itself. To test the fallback, I locally forced both enumerations to return nothing (not part of the PR):
      • VIDIOC_G_PARM gave 25 fps for PAL and 29.97 fps (30000/1001) for NTSC, on the S-Video and the TV input.
      • With VIDIOC_G_PARM skipped as well, VIDIOC_G_STD gave the same frame rates.
      • Capturing from a fallback characteristic gave 25 and 30 frames per second.

@Roman3349
Roman3349 force-pushed the fix/v4l2-frame-intervals branch from 9305478 to e30c55c Compare November 6, 2026 15:36
@kekyo
kekyo self-requested a review November 9, 2026 02:24
@kekyo kekyo linked an issue Nov 9, 2026 that may be closed by this pull request
Drivers such as stk1160 require more buffers than the requested two. Track the count returned by VIDIOC_REQBUFS so mapping and cleanup cover every allocated buffer.
@kekyo

kekyo commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Thanks, although I can't test it on actual analog devices, I think the code is good. I will merge it.

@kekyo
kekyo merged commit 09c66d4 into kekyo:develop Nov 9, 2026
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.

Support for AV to USB

2 participants