PDA

View Full Version : Set fixed FPS



npatil15
11th February 2019, 07:34
Hi Everyone,

I'm working on image processing, where I want to take fixed frames per second.

And in case frames are less than the fixed frame then I have to create dummy frame of previous one and then send the same.

As of now, I have write code which calculate frames per seconds as per the inputs, and I have calculate this on every frame and shows to the user.

double fps = 1000.0 / msElapsed;

But I'm bit confused how I right the logic to set fixed frame rate, can please some one help me ?

Thanks

npatil15
13th February 2019, 10:07
I just need the number of ways to control the Frame rate.

d_stranz
13th February 2019, 22:34
double fps = 1000.0 / msElapsed;

If "msElapsed" is the time since the last frame was retrieved and the current frame, then this is the instantaneous frame rate.

But since you haven't given any code that explains what API you are using to retrieve and process frames it is sort of difficult to give you any help.

If you want to send frames at a fixed fps, then you should create a timer that fires every "n" ms and send a frame each time it fires.

If you can receive frames at a different rate than you want to send them, then you should probably create some sort of double-buffered system - the sending code sends data from one buffer, while the receiving code fills a different buffer. Each time the receiver completes filling the buffer, it swaps pointers with the sending buffer so that the next send action uses the new frame. If the receiver isn't finished filling its buffer before the sender needs to send, then the sender will simply resend its buffer because the pointers haven't been switched yet.

If your application is multithreaded, then you must make sure that the receiver cannot switch the pointers until the sender has finished with its frame, otherwise the receiver could corrupt the sender's data by overwriting it with the next frame.

npatil15
14th February 2019, 09:26
Hi d_stranz,

I have code but this code is just checking frame rate per seconds(fps), but my intention is to handle the frame rate at fixed value.
And yes you guess right, I'm getting fps at different rate and I have to handle it for fixed fps.

As of now I'm not sure what programming concept I should go ahead.
Do you have some example which I can follow to do the same ?

Thanks

d_stranz
14th February 2019, 18:07
As of now I'm not sure what programming concept I should go ahead.
Do you have some example which I can follow to do the same ?

I explained one concept: double-buffering. It has been used since the beginning of computer graphics, when displaying an image on screen took much less time than creating the image. The creation code uses one buffer to draw a new image, the display code uses another buffer with the previous image for display until the next image is ready. When the creation code is done, it switches buffers so now the display code read from the new buffer, while the creation code can fill the other buffer with the next image, and so on. Double-buffering can be used almost any time there is a speed difference between code that creates something and code that uses whatever that is.

Google is your friend - just search for double-buffering.