P
P
Perzh2014-09-15 11:39:24
Qt
Perzh, 2014-09-15 11:39:24

How to achieve smooth frame capture?

Hello.
There is a program that captures frames from the monitor area, compresses them and writes them to avi:

char* frame = getFrame(); // Выполняется быстро
compress(frame); // Выполняется медленно
writeFrame(aviFile, frame);

The problem is that you need to do this with a given fps, but frame processing takes a significant amount of time (performed on the CPU) and fps is not respected. Please advise how to solve this problem?
PS:
For example, there is an option with frame buffering. Raw frames are first written to a buffer in RAM with a given fps. Frame processing and saving is performed in a separate thread. Thus, we achieve the desired smoothness at the cost of RAM and CPU consumption. Can you give me some advice on how best to implement this? Or share a link to an article/example?
Or the second option (weakly believe in it) is similar to the first: run the compress and writeFrame functions asynchronously using QtConcurrent::run. This is easier to implement, but how will it work? Will there be too many threads? Will there be a conflict when writing to a file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NoseyParker, 2014-10-09
@NoseyParker

Frame capture, in my opinion, is best done the old fashioned way - using Bitblt . In the main stream or not to capture - it's up to you. But I highly recommend saving frames and, moreover, processing them in a separate thread so as not to affect FPS.
And so that you, inadvertently, do not pile up any functions of "compressing" the image, I pay special attention to the fact that Bitblt can change the size of the image during the capture process, as well as the color format.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question