c++ - Filtergraph 在第一次数据通过后停止

标签 c++ directshow

编辑:最初的问题是在调用我的自定义过滤器时过滤器图停止了。我们通过在交付方法中设置样本的时间属性来解决这个问题。

我简化了图表 basic file recorder

这适用于将视频从网络摄像头录制到文件中。

但是,如果我将过滤器放在两者之间:

enter image description here

我得到奇怪的结果:

enter image description here

所以看起来它没有编码。但是如果没有这个过滤器,avi mux 也不会对来自网络摄像头的视频进行编码。 这是更新后的输出引脚传递方法:

 HRESULT MCMyOutputPin::Deliver(IMediaSample* sample)
{
    CAutoLock mylock(this->m_pLock);
    HRESULT hr = NO_ERROR;
    myLogger->LogDebug("In Outputpin Deliver", L"D:\\TEMP\\yc.log");
    if (sample->GetActualDataLength() > 0)
    {
        IMediaSample *outsample;


        if (!m_pAllocator)
            return E_FAIL;
        hr = m_pAllocator->GetBuffer(&outsample, NULL, NULL, NULL);
        if (FAILED(hr))
        {
            myLogger->LogDebug("Could not get buffer", L"D:\\TEMP\\yc.log");
            return hr;
        }
        BYTE* sampleBuffer = NULL;
        BYTE*  newBuffer = NULL;
        long lSizeSample = sample->GetSize();
        long lSizeOutSample = outsample->GetSize();
        outsample->GetPointer(&newBuffer);
        sample->GetPointer(&sampleBuffer);
        LONGLONG timeStart = NULL;
        LONGLONG timeEnd = NULL;
        REFERENCE_TIME refTime = NULL;
        REFERENCE_TIME reftimeend = NULL;
        sample->GetMediaTime(&timeStart, &timeEnd);
        sample->GetTime(&refTime, &reftimeend);
        ASSERT(lSizeOutSample >= lSizeSample);
        memcpy((void *)newBuffer, (void *)sampleBuffer, lSizeSample);
        outsample->SetMediaTime(&timeStart, &timeEnd);
        outsample->SetTime(&refTime, &reftimeend);
        m_pInputPin->Receive(outsample);







        outsample->Release();
        sample->Release();




    }

    return hr;
    //Forward to filter
}

所以我的问题是:如果我现在所有的过滤器都是转发样本而不是改变它们,为什么我会得到这个结果。

最佳答案

AVI Mux 对样本媒体时间非常敏感。在您的代码中,我没有看到为传递给 AVI Mux 的示例设置正确的媒体时间。如果没有这些时间,它就无法确定正确的帧速率和帧顺序,因此它可能会停止。

关于c++ - Filtergraph 在第一次数据通过后停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22501162/

相关文章:

c++ - unique_ptr : So I can't reference to a deleted function anymore

c++ - 对 boost::locale:conv::between 的 undefined reference

c# - 媒体样本长时间保存在图形中(累积效果)

c++ - 如何在 directshow 源过滤器中渲染 direct3d

c++ - DirectShow 使用 C++ 无限循环视频

c++ - C++中的字符到整数的转换

c++ - 从堆栈和堆中释放内存

c++ - 使用指针 c++ 违反 const 变量

c++ - FFmpeg 在我的应用程序中禁用 Window 桌面管理器

delphi - 如果在主机选项卡不可见时启动图形 (TVideoWindow),DirectShow 渲染窗口将显示黑色