如何获得每帧的平均时间? [英] How to get the Average Time Per Frame?
问题描述
我试图在vc ++中使用DirectShow获取视频的每帧平均时间。
我使用IBasicVideo接口获取该值,它具有get_AvgTimePerFrame函数。但是我没有从中获得任何价值。
I am trying to get the Average time per frame of the video using DirectShow in vc++.
And am using the IBasicVideo interface to get that value,it is having the get_AvgTimePerFrame function. But am not getting any value from it.
hr = pGraph->QueryInterface(IID_IBasicVideo,(void **)&pVideo);
hr = InitWindowlessVMR(AfxGetMainWnd()->m_hWnd, pGraph, &pWc);
// Build the graph.
hr = pGraph->RenderFile(L"Video.mp4", NULL);
double df;
hr=pVideo->get_AvgTimePerFrame(&df);
如果我在pGraph-> RenderFile(video.mp4之后调用get_AvgTimePerFrame函数,NULL函数正在获取值。如果我指定过滤器形成我的返回值为E_NOINTERFACE。
我需要做什么来获得每帧平均时间的值?
提前告诉你。
If i call the get_AvgTimePerFrame function after the pGraph->RenderFile("video.mp4",NULL) function am getting the value. If i specify the filter formation am getting the return value as E_NOINTERFACE.
What i need to do to get the value of the average time per frame?
Thaking you in advance.
推荐答案
您应该获得渲染器的连接媒体类型并获取信息来自VIDEOINFOHEADER结构。
You should get connected media type of your renderer and get information from VIDEOINFOHEADER structure.
double GetFPS(IBaseFilter * _filter)
{
double _fps = 0;
if (_filter) // Check if the filter passed
{
IEnumPins * _enum;
// Query Enum pins
if (S_OK == _filter->EnumPins(&_enum))
{
IPin * _pin;
// While we have pins or fps not setted yet
while (_fps == 0 && _enum->Next(1,&_pin,NULL) == S_OK)
{
PIN_DIRECTION _direction;
// Here we check for pin direction
// Assume that we pass the renderer filter as argument
// But checking direction not mandatory
_pin->QueryDirection(&_direction);
if (_direction == PINDIR_INPUT)
{
AM_MEDIA_TYPE mt;
// We try to retrieve connection media type
// In case if connected it returns type and S_OK result
if (S_OK == _pin->ConnectionMediaType(&mt))
{
// We have video type and have format
// At least format shoudl be size of VIDEOINFOHEADER structure
// As all other well known format structures are higher size
if (mt.majortype == MEDIATYPE_Video
&& mt.pbFormat
&& mt.cbFormat >= sizeof(VIDEOINFOHEADER))
{
// We cast directly here without checking format type
// This possible because we had check the size and we need
// only "AvgTimePerFrame" field
// NOTE: do not do this for bmiHeader field
REFERENCE_TIME _time = ((VIDEOINFOHEADER*)mt.pbFormat)->AvgTimePerFrame;
if (_time > 0)
{
// Calculate fps = second / time per frame
_fps = ((double)UNITS / (double)(_time));
}
}
// Free format block
FreeMediaType(mt);
}
}
// Release pin
_pin->Release();
}
// Release enum
_enum->Release();
}
}
return _fps;
}
Maxim。
Maxim.
这篇关于如何获得每帧的平均时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!