2014-01-21 8 views
0

웹캠이 640x480에서 프레임을 제공하고 있기 때문에 인코더가 고해상도로 올바르게 작동하지 않기 때문에 프레임 해상도를 320x240으로 변경하려고합니다.델파이 DirectShow에서 웹캠의 해상도 변경

샘플 그래버

를 통해 프레임을 잡을 때

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; 

그러나 해상도는이 방법 문제 있나요 동일하게 유지?

UPDATE

좋아, 내가 지금 모든 구성원

를 업데이트하고 생각
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; 
+0

내가 지금 모든 구성원을 업데이트하고 있지만, 여전히, 난 당신이 코드로 설명해 수 –

답변

0
  1. 새로운 해상도와 새로운 미디어 유형의 당신의 초기화가 잘못/불완전 : 업데이트를 다른 회원들뿐만 아니라
  2. 형식 설정에서 오류를 감지하려면 SetFormat 결과를 확인해야합니다.
  3. 코드 자체가 불완전한 것으로 나타나며 형식을 변경하고 소스 필터가 존재하여 필터 그래프에 추가되었다는 증거가 없음
+0

위의 코드를 업데이트 같은 오류를주고있다 선택을위한 GUI 컨트롤 (목록 상자)입니까 ?? 그게 너무 많이 묻지 않으면. 덕분에 –

+0

k를 확인했는데 오류 코드 -2147467259 –

+0

이 반환되었습니다. 이것은 형식 변경 시도를 거부 했으므로 0x80004005'E_FAIL'입니다. –

0

DSPack 데모 "... \ dspack2.3.4 \ Demos \ D6-D7 \ videocap "

사용 가능한 모든 형식의 웹캠을 나열한 다음 설정해야합니다. 거기에서 코드 한게

: (버튼 시작 온 클릭 핸들러)

VideoMediaTypes, 
AudioMediaTypes: TEnumMediaType; 

....... 

     // configure output Video media type 
     if VideoSourceFilter.FilterGraph <> nil then 
     begin 
     PinList := TPinList.Create(VideoSourceFilter as IBaseFilter); 
     if VideoFormats.ItemIndex <> -1 then 
      with (PinList.First as IAMStreamConfig) do 
      SetFormat(VideoMediaTypes.Items[VideoFormats.ItemIndex].AMMediaType^); 
     PinList.Free; 
     end; 

여기

SetFormat(VideoMediaTypes.Items[VideoFormats.ItemIndex].AMMediaType^); 

VideoMediaTypes 사용자가 소스를 선택할 때 채워 가능한 형식의리스트이다.

VideoFormat는 형식