Repository navigation
feat: add camera controls for DirectShow and V4L2 - #185
Merged
Merged
Conversation
Signed-off-by: Roman Ondráček <[email protected]>
Signed-off-by: Roman Ondráček <[email protected]>
Roman3349
force-pushed
the
feature/camera-controls
branch
from
November 4, 2026 22:43
bbe124c to
3cc38d0
Compare
Owner
|
@Roman3349 Thank you - this is a great new feature! |
kekyo
self-requested a review
November 6, 2026 06:23
Owner
|
@Roman3349 Thanks for the PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an API to read and set camera controls such as brightness, zoom, exposure, focus and white balance, including their automatic modes. It is implemented for DirectShow and V4L2, and the Avalonia, WPF and Windows Forms samples get a window with the controls.
Related: #14, #112, #118, #122, #64
API
CaptureDeviceControlTypes: Brightness, Contrast, Hue, Saturation, Sharpness, Gamma, WhiteBalance, BacklightCompensation, Gain, PowerLineFrequency, Pan, Tilt, Zoom, Exposure, Focus.CaptureDeviceControl:Type,Minimum,Maximum,Step,DefaultValue,SupportsAuto.CaptureDeviceControlValue:Value,IsAuto.getControls,getControlValue(returns an option) andsetControlValue.The values are raw device values, so FlashCap does no unit conversion. For example, the exposure is the binary logarithm of seconds on DirectShow and the time in 100 µs units on V4L2. This is documented on the enum and in the README.
The calls follow the pattern of
ShowPropertyPageAsync: a virtualOn...Asyncmethod onCaptureDevice, called under the device lock, with extension methods inFlashCap.Implementation
DirectShow
IAMVideoProcAmp(brightness ... gain) andIAMCameraControl(pan, tilt, zoom, exposure, focus) are queried from the capture source filter the device already holds in its graph.Auto/Manualflags.PowerLineFrequencyis not exposed by these interfaces, so it is not offered on DirectShow.V4L2
VIDIOC_QUERYCTRL/VIDIOC_G_CTRL/VIDIOC_S_CTRL.v4l2_queryctrlandv4l2_controlare declared by hand inNativeMethods_V4L2, because their layout is the same on all architectures. They are blittable classes, so the existingioctl<T>can pin them.V4L2_CID_AUTO_WHITE_BALANCE,V4L2_CID_AUTOGAIN,V4L2_CID_HUE_AUTO,V4L2_CID_FOCUS_AUTOandV4L2_CID_EXPOSURE_AUTO.Other backends
Video for Windows, Media Foundation and AVFoundation return no controls.
GetControlValueAsyncreturnsnullandSetControlValueAsyncreturnsfalsefor them, as for any control a device does not offer.Samples
The Avalonia, WPF and Windows Forms samples have a "Camera controls" button which opens a window with the controls of the opened device:
After each change the samples read the value back, since setting a value turns the automatic mode off. The Windows Forms window and its rows are made with the designer, only the rows for the device's controls are added in code.
The last commit fixes a typo in a comment of the Avalonia sample.
Testing
FlashCap.Core.Testspass.null/false.Notes
#64 adds
IAMCameraControlfor DirectShow only. This PR covers both interfaces and V4L2 behind one API. I am happy to adjust the API or to build on #64 if you prefer.