OpenCV VideoWriter Framerate Issue

若如初见. 提交于 2019-12-01 21:54:18
Aakash Patel

I resolved my issue after a bit of debugging; it was an issue with VideoWriter being picky on the rate at which frames were fed to it.

You need to sync your read and write functions. Your code reads as fast as possible, and writes also as fast as possible. Your output video probably looks slow because writing the output happens faster than reading the input (since capture >> is waiting for your camera), and several identical frames are recorded.

Writing without waiting or syncing means you may write the same content several times (what I think is happening here), or lose frames.

If you want to keep having threads, you may, but you will need to make your write process wait until there is something new to write.

Likewise to avoid losing frames or writing corrupted frames, you need the read process to wait until writing is done, so that frame can be safely overwritten.

Since the threads need to wait for each other anyway, there's little point in threads at all.

I'd rather recommend this much simpler way:

for (;;) {
    capture >> frame;
    process(frame);  // whatever smart you need
    record << frame;
}

If you need parallelism, you'll need much more complex sync mechanism, and maybe some kind of fifo for your frames.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!