aa576aaa 2015-04-22 04:48
浏览 2530

Directshow用setformat进行视频格式转换出现问题

本人刚刚接触Directshow不久,现在遇到了问题。在遍历完设备后,尝试用setformat改变视频格式,将formattype中的VIDEOINFOHEADER改为VIDEOINFOHEADER2,来进行逐行隔行的识别。现在提示hr=pISC->setformat(pmt)为EFAIL,不知道到底哪里有问题,恳请各位大牛指点。以下是相关的代码:
// locate the video capture pin and QI for stream control
CComPtr pISC = NULL;
hr = CDSUtils::FindPinInterface(m_pVideoCapture, &MEDIATYPE_Video, PINDIR_OUTPUT, IID_IAMStreamConfig, reinterpret_cast(&pISC));
if (SUCCEEDED(hr))
{
// loop through all the capabilities (video formats) and populate the control
int count, size;
hr = pISC->GetNumberOfCapabilities(&count, &size);//media type counts, the space of the typedef need.
if (SUCCEEDED(hr))
{
if (sizeof(VIDEO_STREAM_CONFIG_CAPS) == size)
{
AM_MEDIA_TYPE* pmt = NULL;
hr = pISC->GetFormat(&pmt);
if (FAILED(hr))
{
return FALSE;
}
if(SUCCEEDED(hr))
{
VIDEO_STREAM_CONFIG_CAPS vscc;
VIDEOINFOHEADER2* pvih = NULL;

                for (int index=0; index<count; ++index)
                {
                    hr = pISC->GetStreamCaps(index, &pmt, reinterpret_cast<BYTE*>(&vscc));
                    if (SUCCEEDED(hr))
                    {
                        TCHAR       buffer[128];
                        float       frameRate;
                        char*       pixelFormatString;

                        ZeroMemory(buffer, sizeof(buffer));


                        if((pmt->formattype==FORMAT_VideoInfo)&&(pmt->cbFormat>=sizeof(VIDEOINFOHEADER))&&(pmt->pbFormat!=NULL))
                        {
                            pmt->formattype = FORMAT_VideoInfo2;
                            hr = pISC->SetFormat(pmt);
                        }
                        if(FAILED(hr))
                        {
                            FreeMediaType(*pmt);
                        }
                        if(SUCCEEDED(hr))
                        {
                        //成功后继续相关操作
                        }
                        ...
                        }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 有没有帮写代码做实验仿真的
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
    • ¥20 yolov5自定义Prune报错,如何解决?