Qt录像机 [英] Qt Video Recorder

查看:281
本文介绍了Qt录像机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Qt创建一个录像机。我到目前为止是在屏幕上截取一个矩形的屏幕截图并保存。最后我使用ffmpeg从图像中获取视频文件。

I am trying to create a video recorder with Qt. What I did so far was taking a screenshot of a rectangle on the screen and save it. At the end I use ffmpeg to get a video file out of the images.

我连接了一个定时器的信号 timeout()到我的自定义槽,它接受快照并将它保存到我的tmp夹。定时器具有1000/30的间隔。这应该是每秒30次。但是1000/30是一个有点超过33毫秒,所以我真的不能得到30 fps。

I connected a timer's signal timeout() to my custom slot which takes the snapshot and saves it to my tmp folder. The timer has an intervall of 1000 / 30. That should be 30 times per second. But 1000 / 30 is a little bit more than 33 milliseconds so I cannot really get 30 fps. It's a bit more.

我用录音机录制了一个YouTube视频,一切都很顺利,但根据intervall,它有点快/慢一些。

I recorded a youtube video with my recorder and everything was smooth but a little bit faster / slower depending on the intervall.

所以我的问题基本上是如何得到真正的30/40/50 / ... fps?

So my question basically is how do I get really 30 / 40 / 50 / ... fps?

推荐答案


  1. 开始

  1. Start a QElapsedTimer when you start the capture.

当您完成捕获帧(在快照时隙结束时)时,您可以使用nofollow> QElapsedTimer 。将下一个帧数乘以以毫秒为单位的近似帧持续时间(双精度浮点值)(例如对于30 fps,它〜33.33333333333 ,但不要写 - 写(double)1000/30 )。

When you are done capturing a frame (at the end of your snapshot slot), multiply the next frame number by the approximate frame duration (a double precision floating point value) in milliseconds (e.g. for 30 fps, it is ~33.33333333333, but don't write that - write (double)1000/30). Call this value next_timestamp.

调用 elapsed() 。调用此值 current_timestamp

调用静态函数 QTimer :: singleShot() 睡眠 next_timestamp - current_timestamp 。再次将插槽参数设置为快照插槽。注意,如果睡眠时间<= 0,你落后;

Call the static function QTimer::singleShot() to sleep for next_timestamp - current_timestamp. Set the slot argument to your snapshot slot again. Note that if the time to sleep is <= 0, you are falling behind; your system can't keep up with the load of capturing that fast.

QTimer时,系统无法跟上捕获速度的负载。 :: singleShot()激发,您的快照插槽将再次调用,在时间上有一些错误。但是,在非实时操作系统(如Windows和Unix(OS X / Linux / etc))下,此错误是不可避免的。这是因为你不能决定代码何时执行 - 操作系统内核。然而,平均而言,你将每秒精确到30帧(假设你的计算机可以跟上负载!),因为QElapsedTimer报告的时间将是相当准确的,如果系统落后,它将捕获帧更快,如果它提前,它会捕获帧更慢。

When QTimer::singleShot() fires, your snapshot slot will be called again with some error in timing. However, this error is inevitable under non-realtime operating systems such as Windows and Unix (OS X/Linux/etc). This is because you don't get to decide when code executes - the OS kernel does. On average, though, you will end up with exactly 30 frames per second (assuming your computer can keep up with the load!), because the time elapsed reported by the QElapsedTimer will be quite accurate, and if the system falls behind, it will capture frames more quickly, and if it gets ahead, it will capture frames more slowly.

这篇关于Qt录像机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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