title: Delphi Change resolution of webcam in directshow
body: <p>i am trying to change the resolution of the frames to 320x240 because my webcam is providing frames in 640x480 and the encoder i am using is not working right with higher resolution, i do it this way</p>
  
  <pre class="lang-pascal prettyprint-override"><code>procedure OnDevieStart()
  begin
    FilterGraph.ClearGraph;
    FilterGraph.Active := False;
    Filter.BaseFilter.Moniker := SysDev.GetMoniker(TMenuItem(Sender).tag);
    FilterGraph.Active := true;
    SetVideoProperties(Filter as iBaseFilter);
  
    with FilterGraph as ICaptureGraphBuilder2 do
    try
      RenderStream(@PIN_CATEGORY_PREVIEW, nil, Filter as IBaseFilter, SampleGrabber as IBaseFilter, VideoWindow as IbaseFilter);
      FilterGraph.Play;
    except
      ShowMessage('Unable to use specified device!')
    end;
  end;
  
  function SetVideoProperties(pVideoCapture: IBaseFilter):Boolean;
  var
    hr:HRESULT;
    pStreamConfig: IAMStreamConfig;
    pAM_Media: PAMMediaType;
    pvih: PVIDEOINFOHEADER;
    pICGP2: ICaptureGraphBuilder2;
  begin
  
    pICGP2 := FilterGraph as ICaptureGraphBuilder2;
    hr := pICGP2.FindInterface(@PIN_CATEGORY_CAPTURE, nil, pVideoCapture,
                               IID_IAMStreamConfig, pStreamConfig);
  
    if (SUCCEEDED(hr)) then begin
  
      pStreamConfig.GetFormat(pAM_Media);
      pvih := pAM_Media.pbFormat ;
      pAM_Media.subtype := MEDIASUBTYPE_RGB24;
      pvih.bmiHeader.biWidth := 320;
      pvih.bmiHeader.biHeight := 240;
      pvih.AvgTimePerFrame := 10000000 div 15;
      pStreamConfig.SetFormat(pAM_Media^);
      DeleteMediaType(pAM_Media);
      pStreamConfig := nil;
    end;
  
  end;
  </code></pre>
  
  <p>But the resolution stays the same when grabbing the frames through the sample grabber</p>
  
  <p>Is there anything wrong with this approach?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Ok i think i am now updating all the members</p>
  
  <pre class="lang-pascal prettyprint-override"><code>function SetVideoProperties(pVideoCapture: IBaseFilter):Boolean;
  var
    hr:HRESULT;
    pStreamConfig: IAMStreamConfig;
    pAM_Media: PAMMediaType;
    pvih: PVIDEOINFOHEADER;
    pICGP2: ICaptureGraphBuilder2;
  begin
  
    pICGP2 := FilterGraph as ICaptureGraphBuilder2;
    hr := pICGP2.FindInterface(@PIN_CATEGORY_CAPTURE, nil, pVideoCapture,
                               IID_IAMStreamConfig, pStreamConfig);
  
    if (SUCCEEDED(hr)) then begin
  
      pStreamConfig.GetFormat(pAM_Media);
  
      pAM_Media.subtype := MEDIASUBTYPE_RGB24;
      pAM_Media.majortype := MEDIATYPE_Video;
      pAM_Media.bFixedSizeSamples := True;
      pAM_Media.bTemporalCompression := False;
      pAM_Media.lSampleSize := 230400;
      pAM_Media.formattype := FORMAT_VideoInfo;
      pAM_Media.pUnk := nil;
      pAM_Media.cbFormat := 88;
  
      pvih := pAM_Media.pbFormat;
      pvih.dwBitRate := 6912000;
      pvih.AvgTimePerFrame := 10000000 div 15;
      pvih.bmiHeader.biSize := 40;
      pvih.bmiHeader.biWidth := 320;
      pvih.bmiHeader.biHeight := 240;
      pvih.bmiHeader.biPlanes := 1;
      pvih.bmiHeader.biBitCount := 24;
      pvih.bmiHeader.biCompression := 0;
      pvih.bmiHeader.biSizeImage := 230400;
      pvih.bmiHeader.biXPelsPerMeter := 0;
      pvih.bmiHeader.biYPelsPerMeter := 0;
      pvih.bmiHeader.biClrUsed := 0;
      pvih.bmiHeader.biClrImportant := 0;
  
      hr := pStreamConfig.SetFormat(pAM_Media^);
  
      If Succeeded(hr) then ShowMessage('SUCCEED') else ShowMessage(IntToStr(hr));   
      DeleteMediaType(pAM_Media);
      pStreamConfig := nil;
    end;
  
  end;
  </code></pre>