计算fps(每秒帧数)并能够以2x / 4x播放视频。 [英] Calculate the fps (frame per second) and able to play video by 2x/4x.

查看:222
本文介绍了计算fps(每秒帧数)并能够以2x / 4x播放视频。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家好,以下是我的问题我需要一些解决方案, 


1.我的要求是计算加载的媒体元素的帧率(FPS)。首先,如果我得到FPS,那么我可以逐帧定位/播放我的视频。



我尝试过以下事项:



A.使用Microsoft.WindowsAPICodePack.Shell;  (stackoverflow questions / 9818826 / any-way-to-programically-get-the-fps-of-a-video) 



代码:ShellFile shellFile = ShellFile .FromFilePath(@" filepathname");

            string fps =(shellFile.Properties.System.Video.FrameRate.Value / 1000).ToString();

但问题是,它为shell文件/路径名提供fps。我需要编写system.video.framerate的代码.....与mediaelement id,这是迄今为止我找不到的这个librabry。你有什么参考吗?



B.使用  CompositionTarget.Rendering + =  ....代码



  CompositionTarget.Rendering + =(s,a)=>

            {

                ++ m_frames;

            }; b

            DispatcherTimer fpsTimer = new DispatcherTimer();

            fpsTimer.Interval = TimeSpan.FromSeconds(1);

            fpsTimer.Tick + =(s,a)=>

            {

                lbl_fps.Content = string.Format(" FPS:{0}",m_frames);

                m_frames = 0;

            };
            fpsTimer.Start();
$


$
但首先没有得到正确的帧速率。在页面加载时调用此方法(MainWindow.xaml.cs的构造函数)。你能建议更好的方法来放置/调用这种方法(即从Media_Loaded方法或任何其他方法)?



C.使用API​​ - ffmediaelement FROM  github / StevenGilligan / ffmediaelement,这是最后一个选项,但是非常冗长的api,需要实现大量文件才能找到fps。



D.来自viscomsoft的插件/ API ,但这是付费的。 .viscomsoft popular-solution / 106 / movieplayerpro



2.下一个要求是能够播放速度2x& 4x。为此,



A.编写代码MediaElelemtID.SpeedRatio = 2.0;  &安培; MediaElelemtID.SpeedRatio = 4.0这是有效的,但通过这个10分钟视频& 2x滑杆正在跳过一秒即ie。 ...... 1.02,1.04,1.06 ....等等所以它正在跳过一些帧
但是根据要求,它不应该跳过它应该与..1.02,1.03,1.04,1.05,1.06,.....(但是点击2倍的双倍速度)



B.使用API​​ - ffmediaelement, 它可以做到,但再次需要实现大量的文件只是为了计算增加speedratio 但是到目前为止的最后一个选项。



总而言之,我请求您尽快为这两个要求提供最佳可能性或任何其他解决方案。非常感谢您的努力。



解决方案



嗨    Coder122,



>>但问题是,它为fps提供了shell文件/按路径名。我需要编写system.video.framerate的代码.....与mediaelement id,这是迄今为止我找不到的这个librabry。你有关于此的任何
参考吗?




我们也无法确定我们的位置正确引用Microsoft.WindowsAPICodePack.Shell。



>>。下一个要求是能够发挥速度2x& 4x。为此,



您可以使用MediaElement.SpeedRatio属性来调整媒体的播放速度。 />


更详细:
如何:控制MediaElement(播放) ,暂停,停止,音量和速度):

$


以下链接可能对您有所帮助。$


WPF中的自定义媒体播放器(第1部分)





此外,如果这些不能满足您的需求,您可以尝试一些专业的三方播放器控制或你可以编写自己的播放器,只能在一秒钟内渲染n帧(低级别的vi deo APIs)。 
$


最好的问候,



Yong路

Hi Guys, Here are my issues For which i need some solution, 

1. My Requirement is calculate the framerate (FPS) of a loaded mediaelement. First if i get the FPS, then I can position/play my video frame by frame.

I have tried with following things :

A. using Microsoft.WindowsAPICodePack.Shell;  (stackoverflow questions/9818826/any-way-to-programmatically-get-the-fps-of-a-video) 

Code : ShellFile shellFile = ShellFile.FromFilePath(@"filepathname");
            string fps = (shellFile.Properties.System.Video.FrameRate.Value / 1000).ToString();
But issue is, It gives fps for a shell file/by path name. I need to write code of system.video.framerate..... with mediaelement id which i couldn't find with this librabry till now. Do you have any reference about this?

B. By Using  CompositionTarget.Rendering +=  ....code

 CompositionTarget.Rendering += (s, a) =>
            {
                ++m_frames;
            };

            DispatcherTimer fpsTimer = new DispatcherTimer();
            fpsTimer.Interval = TimeSpan.FromSeconds(1);
            fpsTimer.Tick += (s, a) =>
            {
                lbl_fps.Content = string.Format("FPS:{0}", m_frames);
                m_frames = 0;
            };
            fpsTimer.Start();


But with this first of all not getting the correct frame rate. Calling this method at page load (Constructor of MainWindow.xaml.cs) . Can you suggest better approach of placing/calling this method (ie from Media_Loaded method or from any other method)?

C. By Using API - ffmediaelement FROM  github /StevenGilligan/ffmediaelement , This is the last option but very lengthy api, need to implement lots of file just to find fps.

D. Plugin/API from viscomsoft, but this is the paid one. .viscomsoft popular-solution/106/movieplayerpro

2. Next requirement is to able play the speed 2x & 4x . For this,

A. wrote code MediaElelemtID.SpeedRatio = 2.0;  & MediaElelemtID.SpeedRatio = 4.0 This is effective but by this for a 10 min video & 2x slider bar is moving by skipping one second ie. ...1.02,1.04,1.06.... etc  so it is skipping some frame but as per requirement, it should not skip it should play with ..1.02,1.03,1.04,1.05,1.06,..... (but with double speed at click on 2x)

B. By Using API - ffmediaelement,  it can do it, but again need to implement lots of file just to calculate increase speedratio  however the last option till now.

So in summary, i request you to please let me the best possibilities or any other solutions for these 2 requirements asap. Highly appreciate your efforts.


解决方案


Hi   Coder122,

>>But issue is, It gives fps for a shell file/by path name. I need to write code of system.video.framerate..... with mediaelement id which i couldn't find with this librabry till now. Do you have any reference about this?

We are also can not make sure where we can quote the Microsoft.WindowsAPICodePack.Shell correctly.

>>. Next requirement is to able play the speed 2x & 4x . For this,

You can use the MediaElement.SpeedRatio Property to adjust the playback speed of the media.

For more detailed: How to: Control a MediaElement (Play, Pause, Stop, Volume, and Speed):

The following links may helpful for you.

Custom Media Player in WPF (Part 1)


Besides, if these can't meet your needs, you can try some professional three-party player controls or you could write your own player and only render n-frames a second (low-level video APIs). 

Best Regards,

Yong Lu


这篇关于计算fps(每秒帧数)并能够以2x / 4x播放视频。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆