Configure the Video Quality

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

This topic describes how an application can programmatically change the image and camera settings on a video capture device.

ProcAmp Settings

Windows Driver Model (WDM) video cameras can support properties that control the quality of the image:

  • Backlight compensation
  • Brightness
  • Contrast
  • Gain
  • Gamma
  • Hue
  • Saturation
  • Sharpness
  • White balance

These properties are controlled through the IAMVideoProcAmp interface. Use this interface as follows:

  1. Call QueryInterface on the capture filter for the IAMVideoProcAmp interface.
  2. For each property that you want to set, call the IAMVideoProcAmp::GetRange method. Properties are specified by the VideoProcAmpProperty enumeration. If the GetRange method fails, it means the camera does not support that particular property.
  3. If GetRange succeeds, it returns the range of supported values for the property, the default value, and the minimum increment.
  4. To get the current value of a property, call IAMVideoProcAmp::Get.
  5. To set a property, call the IAMVideoProcAmp::Set method. To restore a property to its default value, call GetRange to find the default and pass that value to the Set method.

You do not have to stop the filter graph when you set the properties.

The following code configures a trackbar control so that it can be used to set the brightness. The range of the trackbar corresponds to the brightness range that the device supports, and position of the trackbar corresponds to the device's initial brightness setting.

HWND hTrackbar; // Handle to the trackbar control. 
// Initialize hTrackbar (not shown).

// Query the capture filter for the IAMVideoProcAmp interface.
IAMVideoProcAmp *pProcAmp = 0;
hr = pCap->QueryInterface(IID_IAMVideoProcAmp, (void**)&pProcAmp);
if (FAILED(hr))
{
    // The device does not support IAMVideoProcAmp, so disable the control.
    EnableWindow(hTrackbar, FALSE);
}
else
{
    long Min, Max, Step, Default, Flags, Val;

    // Get the range and default value. 
    hr = m_pProcAmp->GetRange(VideoProcAmp_Brightness, &Min, &Max, &Step,
        &Default, &Flags);
    if (SUCCEEDED(hr))
    {
        // Get the current value.
        hr = m_pProcAmp->Get(VideoProcAmp_Brightness, &Val, &Flags);
    }
    if (SUCCEEDED(hr))
    {
        // Set the trackbar range and position.
        SendMessage(hTrackbar, TBM_SETRANGE, TRUE, MAKELONG(Min, Max));
        SendMessage(hTrackbar, TBM_SETPOS, TRUE, Val);
        EnableWindow(hTrackbar, TRUE);
    }
    else
    {
        // This property is not supported, so disable the control.
        EnableWindow(hTrackbar, FALSE);
    }
}

Camera Settings

The IAMCameraControl interface is similar to IAMVideoProcAmp, but controls various setttings on the camera itself:

  • Exposure
  • Focus
  • Iris
  • Pan
  • Roll
  • Tilt
  • Zoom

To use this interface, follow the same steps used for IAMVideoProcAmp:

  1. Query the capture filter for the IAMCameraControl.
  2. Call IAMCameraControl::GetRange to find which settings are supported, and the possible range for each settings.
  3. Call IAMCameraControl::Get to get the current value of a setting.
  4. Call IAMCameraControl::Set to set the value.

Configuring a Video Capture Device