gpt4 book ai didi

c++ - 如何在自定义 DirectShow 过滤器中以秒为单位获得正确的帧时间?

转载 作者:行者123 更新时间:2023-11-28 04:12:14 24 4
gpt4 key购买 nike

我想从视频文件中抓取帧。由于 Directshow 的 SampleGrabber 中的一些错误,我决定创建一个类似的过滤器(不是转换过滤器而是渲染器)。

我正在尝试创建一个基于 Windows SDK 转储过滤器 (Microsoft SDKs\Windows\v7.1\Samples\multimedia\directshow\filters\dump) 的 DirectShow 过滤器。我的过滤器只接受 RGB24 格式。

class CDumpInputPin : public CRenderedInputPin
{

//...

STDMETHODIMP Receive(IMediaSample *pSample) override {
//...
REFERENCE_TIME tStart=0, tStop=0;
if (FAILED(pSample->GetTime(&tStart, &tStop))) {
LOG(ERROR) << "Unable to get sample time";
}
LOG(INFO) << "tStart=" << tStart << " tStop=" << tStop ;
}

HRESULT CheckMediaType(const CMediaType *pmt){
if (*pmt->Type() != MEDIATYPE_Video) {
return S_FALSE;
}
if ((*pmt->FormatType() != FORMAT_VideoInfo)) {
return S_FALSE;
}

if ((*pmt->Subtype() != MEDIASUBTYPE_RGB24)) {
return S_FALSE;
}
return S_OK;
}

}

我获得了正确的 RGB 帧,但我不明白如何解释从 IMediaSample::GetTime() 方法返回的值。我使用 pSeeking->SetPositions( &Start, AM_SEEKING_AbsolutePositioning | AM_SEEKING_SeekToKeyFrame, 0, AM_SEEKING_NoPositioning); 寻找源文件中的不同位置。当我尝试抓取 8 帧时,请查看我的日志。

tStart=222223 tStop=622223
tStart=266668 tStop=666668
tStart=311113 tStop=711113
tStart=355558 tStop=755558
tStart=3 tStop=400003
tStart=44448 tStop=444448
tStart=88893 tStop=488893
tStart=133338 tStop=533338

我不明白这些数字是什么意思,为什么它们没有组成一个递增的序列。

这些帧的正确时间戳应该是:

00:00:12
00:00:37
00:01:01
00:01:26
00:01:51
00:02:15
00:02:40
00:03:05

最佳答案

您获得正确的时间 - 以 100ns 为单位的 64 位值。参见 REFERENCE_TIMETime and Clocks in DirectShow .

The REFERENCE_TIME data type defines the units for reference times in DirectShow. Each unit of reference time is 100 nanoseconds.

...

The time stamp defines a media sample's start and finish times, measured in stream time. The time stamp is sometimes called the presentation time

...

File playback: The first sample is time stamped with a start time of zero. Subsequent time stamps are determined by the sample length and the playback rate, which itself is determined by the file format. The filter that parses the file is responsible for calculating the correct time stamps.

所以,

How to get correct frame time in seconds...

DOUBLE Time = tStart / 1E7; // <<--- presentation time (see above) in seconds

关于c++ - 如何在自定义 DirectShow 过滤器中以秒为单位获得正确的帧时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57448590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com