Results 1 to 5 of 5

Thread: Set fixed FPS

  1. #1
    Join Date
    Jun 2015
    Posts
    59
    Thanks
    15
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Set fixed FPS

    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.
    Qt Code:
    1. double fps = 1000.0 / msElapsed;
    To copy to clipboard, switch view to plain text mode 

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

    Thanks

  2. #2
    Join Date
    Jun 2015
    Posts
    59
    Thanks
    15
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Set fixed FPS

    I just need the number of ways to control the Frame rate.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,896
    Thanks
    225
    Thanked 607 Times in 597 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Set fixed FPS

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. The following user says thank you to d_stranz for this useful post:

    npatil15 (14th February 2019)

  5. #4
    Join Date
    Jun 2015
    Posts
    59
    Thanks
    15
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Set fixed FPS

    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

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,896
    Thanks
    225
    Thanked 607 Times in 597 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Set 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 ?
    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. turn scientific to fixed
    By ramin.lich in forum Newbie
    Replies: 5
    Last Post: 18th November 2014, 22:25
  2. Replies: 2
    Last Post: 24th June 2012, 02:17
  3. error[fixed]
    By nickb in forum Newbie
    Replies: 1
    Last Post: 17th November 2010, 21:26
  4. QComboBox with fixed text?
    By squidge in forum Qt Programming
    Replies: 0
    Last Post: 14th November 2009, 22:39
  5. Replies: 3
    Last Post: 5th February 2009, 16:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.