将帧计数转换为时间码的最佳代码/算法?
我正在寻找 C++ 中的最佳源代码/算法 将帧计数转换为给定 fps 中的时间代码 hh:mm:ss:ff,例如。 25fps...
这个代码非常好 - http://www.andrewduncan.ws/Timecodes/Timecodes .html(页面底部) 但它很昂贵 - 它包含 4 个 mod 和 6 个 div 操作
我需要在每一帧上显示时间代码,所以计算这个算法 可能需要一些时间。
我当然可以存储评估的时间码以避免计算。
但了解更好的算法会非常有帮助......
提前致谢 你的 米。
I am searching for optimal sourcecode/algorithm in c++
to convert frames count into time code hh:mm:ss:ff in given fps, ex. 25fps...
this code is preety good - http://www.andrewduncan.ws/Timecodes/Timecodes.html (bottom of page)
but it is expensive - it contains 4 mod and 6 div operations
I need to show time code on every frame, so calculating this algorithm
could take some time.
I can of course store evaluated timecode to avoid calculations.
But it would be very helpful to know better algorithm...
thanks in advance
yours
m.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一般经验法则:在包括视频播放器的图像处理系统中,您会为每个像素运行一次的操作而流血,然后您会为每个图像“补丁”(通常是一行像素)运行一次的操作而流血,而且你不用担心每帧运行一次的东西。
原因是每像素的内容将比每补丁的内容运行数百甚至数千倍,而每补丁的内容将比每帧的内容运行数百甚至数千倍。
这意味着每像素的内容可能会比每帧的内容运行数百万倍。每像素一条指令可能会花费每帧数百万条指令,而每帧几百甚至几千条指令会在相对于每像素指令数的本底噪声中丢失。
换句话说,你可能买得起 mod 和 div。
话虽如此,运行自定义计数器而不是执行 mods 和 divs 可能是合理的。
General rule of thumb: In image-processing systems, which include video players, you sweat blood over the operations that run once per pixel, then you sweat over the operations that run once per image "patch" (typically a line of pixels), and you don't sweat the stuff that runs once per frame.
The reason is that the per-pixel stuff will run hundreds, maybe thousands, of times as often as the per-patch stuff, and the per-patch stuff will run hundreds, maybe thousands, of times as often as the per-frame stuff.
This means that the per-pixel stuff may run millions of times as often as the per-frame stuff. One instruction per pixel may cost millions of instructions per frame, and a few hundred, or even a few thousand, instructions per frame is lost in the noise floor against the per-pixel instruction counts.
In other words, you can probably afford the mods and divs.
Having said that, it MIGHT be reasonable to run custom counters instead of doing mods and divs.
首先,问题可能是秒到小时、分钟、秒之间转换的最佳代码。此时,如果帧是按顺序排列的,则可以简单地使用加法来增加先前的时间。
First of all, the question might better be optimal code for conversion between seconds to hours, minutes, seconds. At this point, if frames come in order, you can simply use addition to increase the previous time.
首先,我同意其他人的观点,即您可能不需要对此进行优化,除非您特别发现问题。然而,由于尝试找到方法很有趣,所以我会给你一些我第一眼看到的东西来减少鸿沟的数量。
它的代码行数更多,但划分更少。基本上,由于秒、分钟和小时使用一些相同的数学运算,因此我在下一个公式中使用其中一个的结果。
First off, I agree with everyone else that you probably don't need to optimize this, unless you are specifically seeing problems. However, since it's entertaining to try to find ways to, I'll give you something I saw at first glance to reduce the number of divides.
It's more lines of code, but fewer divides. Basically, since seconds, minutes and hours use some of the same math, I use the results from one in the formula for the next.
Mod 和 div 运算(到一个小的常数值)可以通过乘以某些预先计算的倒数来有效地执行。所以它们并不贵。
Mod and div operations (to a small constant value) may be effectively performed with multiplication to some precalculated reciprocal. So they are not expensive.