视频录制逻辑问题;填充空框架和同步FPS
我的视频录制逻辑有一些问题。 我的录音算法以伪代码为下面。
fps = 30
msPerFrame = 1000 / fps
videoRecorder = VideoRecorder(fps)
timer.start()
while (true) {
if ((timer.elapsed() >= msPerFrame) && (newFrame.isReady() == true)) {
videoRecorder.push(newFrame)
timer.restart()
}
}
请注意,videorecorder
在创建视频文件并开始录制时确定视频文件的fps。
问题在下面:
(timer.elapsed()> = msperFrame)& amp; (newframe.isready()== false)
?如果我只等待帧准备就绪,尽管fps
记录了此差距,尽管大于实际msperframe
。- 如何校准记录FPS错误?如果
fps = 30
,msperframe = 33.3333 ...
。但是,timer.elapsed()
返回毫秒值sotimer.elapsed()> = msperframe
当msperframe> = 34
时可能是正确的。因此,将1020毫秒的30newFrame
s推到1000毫秒的结果视频。
I got some problems with my video recording logic.
My recording algorithm is below as pseudo code.
fps = 30
msPerFrame = 1000 / fps
videoRecorder = VideoRecorder(fps)
timer.start()
while (true) {
if ((timer.elapsed() >= msPerFrame) && (newFrame.isReady() == true)) {
videoRecorder.push(newFrame)
timer.restart()
}
}
Note that the videoRecorder
determines the fps of the video file as soon as it is created and starts recording.
The problem is below:
- What is the best way to handle when
(timer.elapsed() >= msPerFrame) && (newFrame.isReady() == false)
? If I just wait for a frame to be ready, this gap is recorded atfps
despite being larger than the actualmsPerFrame
. - How to calibrate recording fps error? If
fps=30
,msPerFrame=33.3333...
. However, thetimer.elapsed()
returns milliseconds value sotimer.elapsed() >= msPerFrame
may true whenmsPerFrame >= 34
. So the 30newFrame
s at 1020 milliseconds are pushed to 1000 milliseconds of resulting video.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我简单地使用包含
newFrame
作为FIFO订单的框架缓冲区解决了问题(1)。录音机现在在需要将框架推向记录缓冲区时引用框架缓冲区的最后帧。因此,如果newFrame
在timer.elapsed()> = msperframe
时还没有准备好,则录音机再按下最后一个帧。另外,运行
StarTrecordingFunction()
的线程对时间至关重要,因此给出更高的工作优先级,这给了我更稳定的结果。I simply solved the question (1) using frame buffer which contains
newFrame
as FIFO order. The recorder now references the last frame of the frame buffer when needing to push the frame to the recording buffer. So, ifnewFrame
is not ready whentimer.elapsed() >= msPerFrame
, then the recorder push the last frame one more.Plus, the thread running
startRecordingFunction()
is critical for time, so giving higher job priority of that thread gave me more stable result.