在C#中获取视频片段的帧速率

时间:2011-11-09 08:30:56

标签: c# .net frame-rate

如何在C#中获取视频片段的帧速率?视频片段采用WMV,MP4,MPG格式。

2 个答案:

答案 0 :(得分:1)

您可以使用IWMPNetwork::frameRate属性来获取视频的帧速率(您需要在项目中添加Interop.WMPLib.dll.dll)。

示例代码(取自上面的链接):

// Add a delegate for the PlayStateChange event.
player.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(player_PlayStateChange);

// Create an event handler for the PlayStateChange event.
private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
    // Display the frameRate when the player is playing. 
    switch (e.newState)
    {
        case 3:  // Play State = WMPLib.WMPPlayState.wmppsPlaying = 3
            if (player.network.frameRate != 0)
            {
                frameRateLabel.Text = "Current Frame Rate: " + player.network.frameRate + " K bits/second";
            }
            break;

        default:
            break;
    }
}

答案 1 :(得分:0)

我使用here描述的代码来做到这一点,并为我提供了很多帮助。

实际上,每次打印新框架时,我都会调用以下函数:

private void FPS_Counter()
{
    _framesRendered++;
    if ((DateTime.Now - _lastTime).TotalSeconds >= 1)
    {
       Log.Debug("FPS: one second has elapsed (fps: " + _fps + ")");
       _fps = _framesRendered;
       _framesRendered = 0;
       _lastTime = DateTime.Now;
    }
}