Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FPS check #1171

Open
Greazy opened this issue Oct 8, 2024 · 2 comments
Open

FPS check #1171

Greazy opened this issue Oct 8, 2024 · 2 comments

Comments

@Greazy
Copy link

Greazy commented Oct 8, 2024

How to check fps from stream using only python? Is there any examples or somth?

@Anandesh-Sharma
Copy link

Anandesh-Sharma commented Oct 20, 2024

class FPSVideoStreamTrack(VideoStreamTrack):
    def __init__(self, original_track):
        super().__init__()  # Initialize the parent class
        self.original_track = original_track  # Store the original video track
        self.start_time = time.time()
        self.frame_count = 0

    async def recv(self) -> VideoFrame:
        # Receive the next frame from the original track
        frame = await self.original_track.recv()

        # Update the frame count
        self.frame_count += 1

        # Calculate FPS every 1 second
        current_time = time.time()
        elapsed_time = current_time - self.start_time
        if elapsed_time > 1.0:
            fps = self.frame_count / elapsed_time
            print(f"FPS: {fps:.2f}")

            # Reset frame count and timer
            self.frame_count = 0
            self.start_time = current_time

        return frame

used this code, works fine for me.

@R0NAM1
Copy link

R0NAM1 commented Nov 2, 2024

Mine too, very simple, just diff the last frame time with the current time and 1 divide by it.

            lastFrameDrawnDiff = (time.time() - myGlobals.timeLastFrameDrawn)
            fps = round(1 / lastFrameDrawnDiff)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants