I'm brand new to DirectShow and am working on adding a video stream to my application. I've looked into many solutions out there (TouchLess, DirectShow.net, etc.) and ended up going with this small project on Code Project There isn't much to it, which is why I selected it; I wanted a small code base to work with, as I need to get this feature implemented quickly.
我是DirectShow的新品牌,正在为我的应用添加一个视频流。我已经研究了许多解决方案(TouchLess, DirectShow.net,等等),最后以代码项目的这个小项目结束,没有太多的东西,这就是我选择它的原因;我想要一个小型的代码库,因为我需要快速实现这个特性。
After a solid day of reading, experimenting and debugging I finally have everything working nicely. There is a delay which is a bummer but I can worry about that later. The issue I have at this point is that the camera is capable of 1280X720 and I want to use this resolution. However it seems determined to capture at 640x480. As I dug deeper and deeper and deeper learning how to set the resolution, I finally thought I had it figured out. I also found code on that Code Project page in the comments that I used as a base.
经过整整一天的阅读、实验和调试,我终于把一切都做好了。有一个延迟,这是一个失败,但我以后可以担心。我现在的问题是,这个相机可以1280X720,我想用这个分辨率。然而,它似乎决定捕获640x480。当我越深越深地学习如何设定这个决心时,我终于想到我已经找到了答案。我还在我用作基础的注释中发现了代码项目页上的代码。
After 6 hours of trying, I cannot get this camera to change its resolution. I'm not receiving any errors and the HRESULT returned from SetFormat() is 0, yet the camera will not change resolution.
经过6个小时的尝试,我无法得到这个相机来改变它的分辨率。我没有收到任何错误,从SetFormat()返回的HRESULT是0,但是摄像机不会改变分辨率。
There is too much code to paste everything, but I would like to include the section that builds up the graph as I imagine that's where the problem is.
有太多的代码可以粘贴所有的东西,但是我想要包括构建图形的部分,我想这就是问题所在。
Here is the code that sets up the graph
下面是设置图表的代码。
void CameraMethods::StartCamera(int camIndex, interior_ptr<int> width,
interior_ptr<int> height)
{
if (g_pGraphBuilder != NULL)
throw gcnew ArgumentException("Graph Builder was null");
IMoniker *pMoniker = GetMoniker(camIndex);
pMoniker->AddRef();
HRESULT hr = S_OK;
// Build all the necessary interfaces to start the capture
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_FilterGraph,
NULL,
CLSCTX_INPROC,
IID_IGraphBuilder,
(LPVOID*)&g_pGraphBuilder);
}
if (SUCCEEDED(hr))
hr = g_pGraphBuilder->QueryInterface(IID_IMediaControl, (LPVOID*)&g_pMediaControl);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2,
NULL,
CLSCTX_INPROC,
IID_ICaptureGraphBuilder2,
(LPVOID*)&g_pCaptureGraphBuilder);
}
// Setup the filter graph
if (SUCCEEDED(hr))
hr = g_pCaptureGraphBuilder->SetFiltergraph(g_pGraphBuilder);
// Build the camera from the moniker
if (SUCCEEDED(hr))
hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, (LPVOID*)&g_pIBaseFilterCam);
// Add the camera to the filter graph
if (SUCCEEDED(hr))
hr = g_pGraphBuilder->AddFilter(g_pIBaseFilterCam, L"WebCam");
// Create a SampleGrabber
if (SUCCEEDED(hr))
hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter,
(void**)&g_pIBaseFilterSampleGrabber);
// Configure the Sample Grabber
if (SUCCEEDED(hr))
hr = ConfigureSampleGrabber(g_pIBaseFilterSampleGrabber);
// Set the resolution - I have NO idea where this should be executed
SetCaptureFormat(camIndex, *width, *height);
// Add Sample Grabber to the filter graph
if (SUCCEEDED(hr))
hr = g_pGraphBuilder->AddFilter(g_pIBaseFilterSampleGrabber, L"SampleGrabber");
// Create the NullRender
if (SUCCEEDED(hr))
hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter,
(void**)&g_pIBaseFilterNullRenderer);
// Add the Null Render to the filter graph
if (SUCCEEDED(hr))
hr = g_pGraphBuilder->AddFilter(g_pIBaseFilterNullRenderer, L"NullRenderer");
// Configure the render stream
if (SUCCEEDED(hr))
hr = g_pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
g_pIBaseFilterCam, g_pIBaseFilterSampleGrabber, g_pIBaseFilterNullRenderer);
// Grab the capture width and height
if (SUCCEEDED(hr))
{
ISampleGrabber* pGrabber = NULL;
hr = g_pIBaseFilterSampleGrabber->QueryInterface(IID_ISampleGrabber, (LPVOID*)&pGrabber);
if (SUCCEEDED(hr))
{
AM_MEDIA_TYPE mt;
hr = pGrabber->GetConnectedMediaType(&mt);
if (SUCCEEDED(hr))
{
VIDEOINFOHEADER *pVih;
if ((mt.formattype == FORMAT_VideoInfo) &&
(mt.cbFormat >= sizeof(VIDEOINFOHEADER)) &&
(mt.pbFormat != NULL) )
{
pVih = (VIDEOINFOHEADER*)mt.pbFormat;
*width = pVih->bmiHeader.biWidth;
*height = pVih->bmiHeader.biHeight;
}
else
{
hr = E_FAIL; // Wrong format
}
// FreeMediaType(mt); (from MSDN)
if (mt.cbFormat != 0)
{
CoTaskMemFree((PVOID)mt.pbFormat);
mt.cbFormat = 0;
mt.pbFormat = NULL;
}
if (mt.pUnk != NULL)
{
// Unecessary because pUnk should not be used, but safest.
mt.pUnk->Release();
mt.pUnk = NULL;
}
}
}
if (pGrabber != NULL)
{
pGrabber->Release();
pGrabber = NULL;
}
}
// Start the capture
if (SUCCEEDED(hr))
hr = g_pMediaControl->Run();
// If init fails then ensure that you cleanup
if (FAILED(hr))
StopCamera();
else
hr = S_OK; // Make sure we return S_OK for success
// Cleanup
if (pMoniker != NULL)
{
pMoniker->Release();
pMoniker = NULL;
}
if (SUCCEEDED(hr))
this->activeCameraIndex = camIndex;
else
throw gcnew COMException("Error Starting Camera", hr);
}
[UPDATE] Added the ConfigureSampleGrabber() method below
[更新]在下面添加了ConfigureSampleGrabber()方法。
HRESULT CameraMethods::ConfigureSampleGrabber(IBaseFilter *pIBaseFilter)
{
HRESULT hr = S_OK;
ISampleGrabber *pGrabber = NULL;
hr = pIBaseFilter->QueryInterface(IID_ISampleGrabber, (void**)&pGrabber);
if (SUCCEEDED(hr))
{
AM_MEDIA_TYPE mt;
ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_RGB24;
mt.formattype = FORMAT_VideoInfo;
hr = pGrabber->SetMediaType(&mt);
}
if (SUCCEEDED(hr))
hr = pGrabber->SetCallback(new SampleGrabberCB(), 1);
if (pGrabber != NULL)
{
pGrabber->Release();
pGrabber = NULL;
}
return hr;
}
That is pretty much the exact code from the CodeProject source code. I then added this method to set the resolution:
这几乎就是CodeProject源代码的精确代码。然后我添加了这个方法来设置分辨率:
void CameraMethods::SetCaptureFormat(int camIndex, int width, int height)
{
HRESULT hr = S_OK;
IMoniker* pMoniker = GetMoniker(camIndex);
IBaseFilter* pCap;
hr=pMoniker->BindToObject(0,0,IID_IBaseFilter,(void **)&pCap);
if(!SUCCEEDED(hr))
return;
IAMStreamConfig *pConfig = NULL;
if(g_pCaptureGraphBuilder == NULL) // no CaptureGraphBuilder initialised
return;
hr = g_pCaptureGraphBuilder->FindInterface(
&PIN_CATEGORY_CAPTURE, // Preview pin.
0, // Any media type.
pCap, // Pointer to the capture filter.
IID_IAMStreamConfig, (void**)&pConfig);
if(!SUCCEEDED(hr))
return;
int iCount = 0, iSize = 0;
hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize);
// Check the size to make sure we pass in the correct structure.
if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS)) {
// Use the video capabilities structure.
for (int iFormat = 0; iFormat < iCount; iFormat++)
{
VIDEO_STREAM_CONFIG_CAPS scc;
AM_MEDIA_TYPE *pmt;
/* Note: Use of the VIDEO_STREAM_CONFIG_CAPS structure to configure a video device is
deprecated. Although the caller must allocate the buffer, it should ignore the
contents after the method returns. The capture device will return its supported
formats through the pmt parameter. */
hr = pConfig->GetStreamCaps(iFormat, &pmt, (BYTE*)&scc);
if (SUCCEEDED(hr))
{
/* Examine the format, and possibly use it. */
if (pmt->formattype == FORMAT_VideoInfo) {
// Check the buffer size.
if (pmt->cbFormat >= sizeof(VIDEOINFOHEADER))
{
VIDEOINFOHEADER *pVih = reinterpret_cast<VIDEOINFOHEADER*>(pmt->pbFormat);
BITMAPINFOHEADER *bmiHeader = &pVih->bmiHeader;
/* Access VIDEOINFOHEADER members through pVih. */
if( bmiHeader->biWidth == width && bmiHeader->biHeight == height &&
bmiHeader->biBitCount == 24)
{
hr = pConfig->SetFormat(pmt);
}
}
}
// Delete the media type when you are done.
DeleteMediaType(pmt);
}
}
}
}
I've stepped through the code and verified that the call to SetFormat() is executed and return a valid HRESULT. No changes to the captured frames though.
我已经完成了代码并验证了对SetFormat()的调用执行并返回一个有效的HRESULT。但是没有对被捕获的帧进行任何更改。
With no error messages it's difficult to know where to start. I'm hoping there are some DirectShow experts here that will see the problem, I'd even be happy with a good ol' fashion condescending "Well yeah, how do you expect the camera to change frame size once the buffer is allocated on the filter stack and the widget is initialized to the foobar! Pft... lol" ;)
没有错误消息,很难知道从哪里开始。我希望这里有一些DirectShow的专家,会看到这个问题,我甚至感到满意时尚谦逊的正名”是的,你希望相机如何改变帧尺寸一旦缓冲过滤堆栈上分配和初始化部件foobar !击球时……笑死我了”。
Teach me, oh DirectShow/COM god!
教教我吧,上帝啊!
[UPDATE #2] (FYI, it's odd that we can't just add a new message to this system and need to edit the original like this)
[更新#2](FYI,奇怪的是我们不能在这个系统中添加一个新消息,并且需要编辑这样的原始信息)
Per Roman's suggestion I have used GraphStudio to look under the hood of my graph. I will admit that I still don't understand what exactly I'm looking at. I found a "text report" function and thought it would be helpful to post that report here in case it shows some valuable information.
根据罗马人的建议,我使用GraphStudio查看我的图表的引擎盖。我承认我还是不明白我到底在看什么。我发现了一个“文本报告”功能,并认为将该报告发布在这里是很有帮助的,以防它显示了一些有价值的信息。
--------------------------------------------------
Filters
--------------------------------------------------
1. Smart Tee
2. MJPEG Decompressor
3. SampleGrabber
4. NullRenderer
5. WebCam
--------------------------------------------------
Connections
--------------------------------------------------
1. [Smart Tee]/(Capture) -> [MJPEG Decompressor]/(XForm In)
Major: MEDIATYPE_Video
Subtype: MEDIASUBTYPE_MJPG
bFixedSizeSamples: TRUE
bTemporalCompression: FALSE
lSampleSize: 921600
cbFormat: 88
Format: FORMAT_VideoInfo
VIDEOINFOHEADER:
rcSource: (0,0,0,0)
rcTarget: (0,0,0,0)
dwBitRate: 221184000
dwBitErrorRate: 0
AvgTimePerFrame: 333333
BITMAPINFOHEADER:
biSize: 40
biWidth: 640
biHeight: 480
biPlanes: 1
biBitCount: 24
biCompression: 0x47504A4D
biSizeImage: 921600
biXPelsPerMeter: 0
biYPelsPerMeter: 0
biClrUsed: 0
biClrImportant: 0
2. [MJPEG Decompressor]/(XForm Out) -> [SampleGrabber]/(Input)
Major: MEDIATYPE_Video
Subtype: MEDIASUBTYPE_RGB24
bFixedSizeSamples: TRUE
bTemporalCompression: FALSE
lSampleSize: 921600
cbFormat: 88
Format: FORMAT_VideoInfo
VIDEOINFOHEADER:
rcSource: (0,0,0,0)
rcTarget: (0,0,0,0)
dwBitRate: 221184221
dwBitErrorRate: 0
AvgTimePerFrame: 333333
BITMAPINFOHEADER:
biSize: 40
biWidth: 640
biHeight: 480
biPlanes: 1
biBitCount: 24
biCompression: 0x00000000
biSizeImage: 921600
biXPelsPerMeter: 0
biYPelsPerMeter: 0
biClrUsed: 0
biClrImportant: 0
3. [SampleGrabber]/(Output) -> [NullRenderer]/(In)
Major: MEDIATYPE_Video
Subtype: MEDIASUBTYPE_RGB24
bFixedSizeSamples: TRUE
bTemporalCompression: FALSE
lSampleSize: 921600
cbFormat: 88
Format: FORMAT_VideoInfo
VIDEOINFOHEADER:
rcSource: (0,0,0,0)
rcTarget: (0,0,0,0)
dwBitRate: 221184221
dwBitErrorRate: 0
AvgTimePerFrame: 333333
BITMAPINFOHEADER:
biSize: 40
biWidth: 640
biHeight: 480
biPlanes: 1
biBitCount: 24
biCompression: 0x00000000
biSizeImage: 921600
biXPelsPerMeter: 0
biYPelsPerMeter: 0
biClrUsed: 0
biClrImportant: 0
4. [WebCam]/(Capture) -> [Smart Tee]/(Input)
Major: MEDIATYPE_Video
Subtype: MEDIASUBTYPE_MJPG
bFixedSizeSamples: TRUE
bTemporalCompression: FALSE
lSampleSize: 921600
cbFormat: 88
Format: FORMAT_VideoInfo
VIDEOINFOHEADER:
rcSource: (0,0,0,0)
rcTarget: (0,0,0,0)
dwBitRate: 221184000
dwBitErrorRate: 0
AvgTimePerFrame: 333333
BITMAPINFOHEADER:
biSize: 40
biWidth: 640
biHeight: 480
biPlanes: 1
biBitCount: 24
biCompression: 0x47504A4D
biSizeImage: 921600
biXPelsPerMeter: 0
biYPelsPerMeter: 0
biClrUsed: 0
biClrImportant: 0
[Update #3] - Holy COW, what have I started?! Why googling deeper than I have ever googled before I came across something that supports Roman's theory of mismatched colorspaces. I downloaded the app and right away had to fix a bug with a buffer that was too small. After solving that I was able to generate the following report:
[更新#3]-天哪,我开始了什么?!在我偶然发现一些支持罗马的不匹配色彩理论的东西之前,为什么要在谷歌上搜索得更深。我下载了这个应用程序,马上就需要修复一个太小的缓冲区。在解决了这个问题之后,我可以生成以下报告:
Dump Version: 1.2
Using device: Microsoft® LifeCam Studio(TM)
Interface: USB
Pin Name: Capture
Pin direction: Output
Pin category: Capture
IAMVideoCompression: No
ISpecifyPropertyPages: Yes
IMediaSeeking: Yes
IPinConnection: No
IPinFlowControl: No
IAMDroppedFrames: No
IAMVideoProcAmp: No
IAMVideoControlCaps: 0
Major Type Sub Type Format Type FixedSamples Temporal Compression Sample Size Max Input Size Min Output Size Max Output Size Min-Max FPS Video Standard
Video YUY2 VideoInfo Fixed NotTemporal 614400 640x480 640x480 640x480 7.50-30.00 {none}
Video YUY2 VideoInfo2 Fixed NotTemporal 614400 640x480 640x480 640x480 7.50-30.00 {none}
Video YUY2 VideoInfo Fixed NotTemporal 1843200 1280x720 1280x720 1280x720 7.50-10.00 {none}
Video YUY2 VideoInfo2 Fixed NotTemporal 1843200 1280x720 1280x720 1280x720 7.50-10.00 {none}
Video YUY2 VideoInfo Fixed NotTemporal 1044480 960x544 960x544 960x544 7.50-20.00 {none}
Video YUY2 VideoInfo2 Fixed NotTemporal 1044480 960x544 960x544 960x544 7.50-20.00 {none}
Video YUY2 VideoInfo Fixed NotTemporal 716800 800x448 800x448 800x448 7.50-30.00 {none}
Video YUY2 VideoInfo2 Fixed NotTemporal 716800 800x448 800x448 800x448 7.50-30.00 {none}
Video YUY2 VideoInfo Fixed NotTemporal 460800 640x360 640x360 640x360 7.50-30.00 {none}
Video YUY2 VideoInfo2 Fixed NotTemporal 460800 640x360 640x360 640x360 7.50-30.00 {none}
Video YUY2 VideoInfo Fixed NotTemporal 203520 424x240 424x240 424x240 7.50-30.00 {none}
Video YUY2 VideoInfo2 Fixed NotTemporal 203520 424x240 424x240 424x240 7.50-30.00 {none}
Video YUY2 VideoInfo Fixed NotTemporal 202752 352x288 352x288 352x288 7.50-30.00 {none}
Video YUY2 VideoInfo2 Fixed NotTemporal 202752 352x288 352x288 352x288 7.50-30.00 {none}
Video YUY2 VideoInfo Fixed NotTemporal 153600 320x240 320x240 320x240 7.50-30.00 {none}
Video YUY2 VideoInfo2 Fixed NotTemporal 153600 320x240 320x240 320x240 7.50-30.00 {none}
Video YUY2 VideoInfo Fixed NotTemporal 960000 800x600 800x600 800x600 7.50-20.00 {none}
Video YUY2 VideoInfo2 Fixed NotTemporal 960000 800x600 800x600 800x600 7.50-20.00 {none}
Video YUY2 VideoInfo Fixed NotTemporal 50688 176x144 176x144 176x144 7.50-30.00 {none}
Video YUY2 VideoInfo2 Fixed NotTemporal 50688 176x144 176x144 176x144 7.50-30.00 {none}
Video YUY2 VideoInfo Fixed NotTemporal 38400 160x120 160x120 160x120 7.50-30.00 {none}
Video YUY2 VideoInfo2 Fixed NotTemporal 38400 160x120 160x120 160x120 7.50-30.00 {none}
Video YUY2 VideoInfo Fixed NotTemporal 4147200 1920x1080 1920x1080 1920x1080 5.00-5.00 {none}
Video YUY2 VideoInfo2 Fixed NotTemporal 4147200 1920x1080 1920x1080 1920x1080 5.00-5.00 {none}
Video MJPG VideoInfo Fixed NotTemporal 921600 640x480 640x480 640x480 7.50-30.00 {none}
Video MJPG VideoInfo2 Fixed NotTemporal 921600 640x480 640x480 640x480 7.50-30.00 {none}
Video MJPG VideoInfo Fixed NotTemporal 6220800 1920x1080 1920x1080 1920x1080 7.50-30.00 {none}
Video MJPG VideoInfo2 Fixed NotTemporal 6220800 1920x1080 1920x1080 1920x1080 7.50-30.00 {none}
Video MJPG VideoInfo Fixed NotTemporal 2764800 1280x720 1280x720 1280x720 7.50-30.00 {none}
Video MJPG VideoInfo2 Fixed NotTemporal 2764800 1280x720 1280x720 1280x720 7.50-30.00 {none}
Video MJPG VideoInfo Fixed NotTemporal 1566720 960x544 960x544 960x544 7.50-30.00 {none}
Video MJPG VideoInfo2 Fixed NotTemporal 1566720 960x544 960x544 960x544 7.50-30.00 {none}
Video MJPG VideoInfo Fixed NotTemporal 1075200 800x448 800x448 800x448 7.50-30.00 {none}
Video MJPG VideoInfo2 Fixed NotTemporal 1075200 800x448 800x448 800x448 7.50-30.00 {none}
Video MJPG VideoInfo Fixed NotTemporal 691200 640x360 640x360 640x360 7.50-30.00 {none}
Video MJPG VideoInfo2 Fixed NotTemporal 691200 640x360 640x360 640x360 7.50-30.00 {none}
Video MJPG VideoInfo Fixed NotTemporal 1440000 800x600 800x600 800x600 7.50-30.00 {none}
Video MJPG VideoInfo2 Fixed NotTemporal 1440000 800x600 800x600 800x600 7.50-30.00 {none}
Video MJPG VideoInfo Fixed NotTemporal 311040 432x240 432x240 432x240 7.50-30.00 {none}
Video MJPG VideoInfo2 Fixed NotTemporal 311040 432x240 432x240 432x240 7.50-30.00 {none}
Video MJPG VideoInfo Fixed NotTemporal 304128 352x288 352x288 352x288 7.50-30.00 {none}
Video MJPG VideoInfo2 Fixed NotTemporal 304128 352x288 352x288 352x288 7.50-30.00 {none}
Video MJPG VideoInfo Fixed NotTemporal 76032 176x144 176x144 176x144 7.50-30.00 {none}
Video MJPG VideoInfo2 Fixed NotTemporal 76032 176x144 176x144 176x144 7.50-30.00 {none}
Video MJPG VideoInfo Fixed NotTemporal 230400 320x240 320x240 320x240 7.50-30.00 {none}
Video MJPG VideoInfo2 Fixed NotTemporal 230400 320x240 320x240 320x240 7.50-30.00 {none}
Video MJPG VideoInfo Fixed NotTemporal 57600 160x120 160x120 160x120 7.50-30.00 {none}
Video MJPG VideoInfo2 Fixed NotTemporal 57600 160x120 160x120 160x120 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 460800 640x480 640x480 640x480 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 460800 640x480 640x480 640x480 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 1382400 1280x720 1280x720 1280x720 7.50-15.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 1382400 1280x720 1280x720 1280x720 7.50-15.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 783360 960x544 960x544 960x544 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 783360 960x544 960x544 960x544 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 537600 800x448 800x448 800x448 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 537600 800x448 800x448 800x448 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 345600 640x360 640x360 640x360 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 345600 640x360 640x360 640x360 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 152640 424x240 424x240 424x240 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 152640 424x240 424x240 424x240 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 152064 352x288 352x288 352x288 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 152064 352x288 352x288 352x288 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 115200 320x240 320x240 320x240 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 115200 320x240 320x240 320x240 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 720000 800x600 800x600 800x600 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 720000 800x600 800x600 800x600 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 38016 176x144 176x144 176x144 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 38016 176x144 176x144 176x144 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 28800 160x120 160x120 160x120 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 28800 160x120 160x120 160x120 7.50-30.00 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 3110400 1920x1080 1920x1080 1920x1080 7.50-7.50 {none}
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 3110400 1920x1080 1920x1080 1920x1080 7.50-7.50 {none}
Pin Name: Video Camera Terminal
Pin direction: Input
Pin category: {3EBC7959-3310-493B-AA81-C7E132D56F71}
IAMVideoCompression: No
ISpecifyPropertyPages: Yes
IMediaSeeking: No
IPinConnection: No
IPinFlowControl: No
IAMDroppedFrames: No
IAMVideoProcAmp: No
IAMVideoControlCaps: 0
Major Type Sub Type Format Type FixedSamples Temporal Compression Sample Size
2 个解决方案
#1
3
You put it into right place - after it's already in the graph by AddFilter, but yet before its output pin is connected. If you have successful HRESULT, then you could be expecting changed format, but there might be exceptions, such as for example this media type was not accepted by downstream filter and they started negotiating from the start.
你把它放到了正确的位置——在它已经被AddFilter在图中,但是在它的输出脚连接之前。如果您获得了成功的HRESULT,那么您可能期望更改格式,但是可能会有例外,例如,这种媒体类型不被下游过滤器接受,他们从一开始就开始进行协商。
You're not showing your ConfigureSampleGrabber here, so it might be the case that this media type you want is not accepted by sample grabber making filter graph to try alternate media types and/or intermediate filters (such as decoders).
您没有在这里显示您的ConfigureSampleGrabber,所以可能是您想要的这种媒体类型不接受示例grabber生成过滤器图来尝试替代的媒体类型和/或中间过滤器(如译码器)。
There are a few things you can actually do.
有几件事你可以做。
-
For troubleshooting you might want to:
对于你可能想要解决的问题:
- add the filter graph to ROT, or instead just install DirectShow Spy to have the same done for you automatically
- 添加过滤器图来腐烂,或者直接安装DirectShow Spy,让你自动完成相同的工作。
- add a MessageBox in your code right after your SetCaptureFormat
- 在您的SetCaptureFormat之后在代码中添加一个MessageBox。
- while the message box is still on the screen, use GraphEdit (GraphStudio) to inspect your filter graph and to see what media types it enumerates on its output pin; typically the first media type will be the one used for real connection, so your successfull HRESULT in SetFormat basically assumes the media type is now on top of this list
- 当消息框仍然在屏幕上时,使用GraphEdit (GraphStudio)检查您的筛选器图,并查看它在其输出pin上枚举的媒体类型;通常,第一个媒体类型将是用于真正连接的一个类型,因此,您的成功HRESULT in SetFormat基本假定媒体类型现在位于该列表的顶部。
-
To force the media type, you might want to use IFilterGraph::ConnectDirect with the configured pin, it's immediate neighbor downstream pin and media type of your interest.
要强制媒体类型,您可能需要使用IFilterGraph::ConnectDirect与配置的pin,它是紧邻的下游pin和您感兴趣的媒体类型。
Hope this helps.
希望这个有帮助。
#2
0
Steve, you should not rebuild the camera (from moniker) in SetCaptureFormat
but use the g_pIBaseFilterCam
.
Steve,你不应该在SetCaptureFormat中重建相机(从moniker),而是使用g_pIBaseFilterCam。
#1
3
You put it into right place - after it's already in the graph by AddFilter, but yet before its output pin is connected. If you have successful HRESULT, then you could be expecting changed format, but there might be exceptions, such as for example this media type was not accepted by downstream filter and they started negotiating from the start.
你把它放到了正确的位置——在它已经被AddFilter在图中,但是在它的输出脚连接之前。如果您获得了成功的HRESULT,那么您可能期望更改格式,但是可能会有例外,例如,这种媒体类型不被下游过滤器接受,他们从一开始就开始进行协商。
You're not showing your ConfigureSampleGrabber here, so it might be the case that this media type you want is not accepted by sample grabber making filter graph to try alternate media types and/or intermediate filters (such as decoders).
您没有在这里显示您的ConfigureSampleGrabber,所以可能是您想要的这种媒体类型不接受示例grabber生成过滤器图来尝试替代的媒体类型和/或中间过滤器(如译码器)。
There are a few things you can actually do.
有几件事你可以做。
-
For troubleshooting you might want to:
对于你可能想要解决的问题:
- add the filter graph to ROT, or instead just install DirectShow Spy to have the same done for you automatically
- 添加过滤器图来腐烂,或者直接安装DirectShow Spy,让你自动完成相同的工作。
- add a MessageBox in your code right after your SetCaptureFormat
- 在您的SetCaptureFormat之后在代码中添加一个MessageBox。
- while the message box is still on the screen, use GraphEdit (GraphStudio) to inspect your filter graph and to see what media types it enumerates on its output pin; typically the first media type will be the one used for real connection, so your successfull HRESULT in SetFormat basically assumes the media type is now on top of this list
- 当消息框仍然在屏幕上时,使用GraphEdit (GraphStudio)检查您的筛选器图,并查看它在其输出pin上枚举的媒体类型;通常,第一个媒体类型将是用于真正连接的一个类型,因此,您的成功HRESULT in SetFormat基本假定媒体类型现在位于该列表的顶部。
-
To force the media type, you might want to use IFilterGraph::ConnectDirect with the configured pin, it's immediate neighbor downstream pin and media type of your interest.
要强制媒体类型,您可能需要使用IFilterGraph::ConnectDirect与配置的pin,它是紧邻的下游pin和您感兴趣的媒体类型。
Hope this helps.
希望这个有帮助。
#2
0
Steve, you should not rebuild the camera (from moniker) in SetCaptureFormat
but use the g_pIBaseFilterCam
.
Steve,你不应该在SetCaptureFormat中重建相机(从moniker),而是使用g_pIBaseFilterCam。