我在XE2(see attached file [Demo2])中使用以下示例来捕获网络摄像头视频。它在我的Win7桌面(USB网络摄像头)和Win10(集成网络摄像头)上工作得很好,但它在Win8(集成网络摄像头)平板电脑上失败,我不知道为什么。我设法跟踪VSimple.pas单元"无法运行图表!"。由于某种原因IMediaControl.Run
方法失败(我尝试添加IMediaControl.GetState
但没有运气)。我正在使用GetLastError
,它给了我0(成功)。有没有人经历过这样的事情?我如何追踪错误?
编辑:已安装的K-Media编解码器包现在通过IMediaControl.Run
,它显示未知压缩Datasize 86400 FourCC NV12 。插入USB网络摄像头会产生视频。我还能做什么?
FUNCTION TVideoSample.RestartVideoEx(Visible: boolean):HRESULT;
VAR
pCut, pTyp : pGuiD;
{
pAMVidControl: IAMVideoControl;
pPin : IPin;
}
BEGIN
if (pIAMVideoProcAmp = nil) then
if not(S_OK = pIBFVideoSource.QueryInterface(IID_IAMVideoProcAmp, pIAMVideoProcAmp)) then
pIAMVideoProcAmp := nil;
if (pIKsPropertySet = nil) then
if not(S_OK = pIBFVideoSource.QueryInterface(IID_IKsPropertySet, pIKsPropertySet)) then
pIKsPropertySet := nil;
// Add Capture filter to our graph.
Result := pIGraphBuilder.AddFilter(pIBFVideoSource, Widestring('Video Capture'));
if (FAILED(Result)) then
begin
// Couldn''t add the capture filter to the graph!
exit;
end;
Result := pIGraphBuilder.AddFilter(piBFSampleGrabber, Widestring('Sample Grabber'));
if (FAILED(Result)) then
EXIT;
if not(Visible) then
begin
Result := pIGraphBuilder.AddFilter(pIBFNullRenderer, WideString('Null Renderer'));
if (FAILED(Result)) then
EXIT;
end;
// Render the preview pin on the video capture filter
// Use this instead of pIGraphBuilder->RenderFile
New(pCut);
New(pTyp);
//pCut^ := PIN_CATEGORY_PREVIEW;
pCut^ := PIN_CATEGORY_CAPTURE;
pTyp^ := MEDIATYPE_Video;
try
if Visible
then Result := pICapGraphBuild2.RenderStream (pCut, pTyp,
//Addr(PIN_CATEGORY_PREVIEW), Addr(MEDIATYPE_Video),
pIBFVideoSource, piBFSampleGrabber, nil)
else Result := pICapGraphBuild2.RenderStream (pCut, pTyp,
//Addr(PIN_CATEGORY_PREVIEW), Addr(MEDIATYPE_Video),
pIBFVideoSource, piBFSampleGrabber, pIBFNullRenderer);
except
Result := -1;
end;
if (FAILED(Result)) then
begin
// Couldn''t render the video capture stream.
// The capture device may already be in use by another application.
Dispose(pTyp);
Dispose(pCut);
exit;
end;
// Set video window style and position
if Visible then
begin
Result := SetupVideoWindow();
if (FAILED(Result)) then
begin
// Couldn't initialize video window!
Dispose(pTyp);
Dispose(pCut);
exit;
end;
end;
{$ifdef REGISTER_FILTERGRAPH}
// Add our graph to the running object table, which will allow
// the GraphEdit application to "spy" on our graph
try
hr := AddGraphToRot(IUnknown(pIGraphBuilder), g_dwGraphRegister);
except
// Failed to register filter graph with ROT!
end;
if (FAILED(Result)) then
begin
// Failed to register filter graph with ROT!
g_dwGraphRegister := 0;
end;
{$endif}
// if Visible then
begin
SetLastError(0);
// Start previewing video data
Result := pIMediaControl.Run(); // Returns something like -27XXXX...
if (FAILED(Result)) then
begin
// Couldn't run the graph! - GetLastError gives 0
end;
end;
// Remember current state
g_psCurrent := PS_Running;
(*
// !!!!!!!!!
// Prepare getting images in higher resolution than video stream
// See DirectX9 Help "Capturing an Image From a Still Image Pin"
// Not working yet.....
pAMVidControl := nil;
Result := pIBFVideoSource.QueryInterface(IID_IAMVideoControl, pAMVidControl);
IF succeeded(Result) then
begin
pTyp := 0;
pPin := nil;
Result := pICapGraphBuild2.FindPin(pIBFVideoSource, PINDIR_OUTPUT, PIN_CATEGORY_STILL, pTyp^, false, 0, pPin);
if (SUCCEEDED(Result)) then
Result := pAMVidControl.SetMode(pPin, VideoControlFlag_Trigger);
end;
*)
Dispose(pTyp);
Dispose(pCut);
end; {RestartVideoEx}