2

Task: grabbing arbitrary frames from mpeg2 video files. Now I use custom render filter for grabbing, but problem with positioning video on required frame.

I use SetPosition(), after Pause() for passing frames through graph, wait for filter receive first frame and Stop().

If I get frame by frame, first i receive exact for this time frame, after this frame repeat some times, and again exact frame.

Why SetPosition get wrong result?

4

2 回答 2

3

解码器需要在前 i 帧开始解码。通常,解复用器将至少在此之前一秒开始推送数据。当您开始接收帧时,您应该检查时间戳以查看它们是否是您想要的。您的过滤器将收到一个“NewSegment”调用,它给出了文件中的搜索开始位置。如果将此开始时间添加到帧上的采样时间,您将获得帧在文件中的绝对位置,您可以将其与您请求的位置进行比较。

G

于 2009-06-15T18:37:14.207 回答
0

渲染图表后,您需要暂停图表。之后,您可以使用 SetPositions 更改要显示的帧。

像这样的东西:

int ShowFrame(long lFrame)
{
    if (FAILED(m_pMC->Pause()))
       return -1;
    LONGLONG llUnknown = 0;
    LONGLONG  llTime = LONGLONG(m_lFrameTime) * lFrame + m_lFrameTime / 2;
    GUID TimeFormat;
    if (FAILED(m_pMS->GetTimeFormat(&TimeFormat))) return -1;
    if (TimeFormat == TIME_FORMAT_MEDIA_TIME)
    {
       llUnknown = llTime;
    }
    else
    {
       if (FAILED(m_pMS->ConvertTimeFormat(&llUnknown, &TimeFormat, llTime, &TIME_FORMAT_MEDIA_TIME))) return -1;
    }
    if (FAILED(m_pMS->SetPositions(&llUnknown, AM_SEEKING_AbsolutePositioning, 0, AM_SEEKING_NoPositioning))) return -1;
    return 0;
}

m_lFrameTime 是每帧的时间,您可以在自定义渲染器中获取。连接视频渲染器引脚后,您可以在该引脚上获得 VIDEOINFO::AvgTimePerFrame。

于 2009-10-27T12:29:25.983 回答