abhiTronix / vidgear

A High-performance cross-platform Video Processing Python framework powerpacked with unique trailblazing features :fire:
https://abhitronix.github.io/vidgear
Apache License 2.0
3.37k stars 254 forks source link

FPS Performance Issues using ScreenGear and WriteGear #270

Closed aza547 closed 2 years ago

aza547 commented 2 years ago

Hi, first off thanks for this library, it's been really interesting to explore.

The issue I have is that I'm unable to get desireable FPS using the combination of ScreenGear and WriteGear. I want to record my screen at a reasonable FPS for playback (anything above 25 would be fine). I'm recording in 1080p.

However the using the code from the usage example under WriteGear I find that I can only write at about 10 FPS. I was using the default of 25 FPS for WriteGear which resulted in my videos playing back as if they were being fast forwarded.

Question

I have a good computer as far as I'm aware and I'm writing to an SSD. Is this low performance a suprise? It appears the write step is taking the longest

What is the correct way to ensure that recording FPS and video FPS are the same? I want real-time video playback in an app I'm writing so videos that don't match up 1:1 in time spent recording / time spent playing is a problem for me. My idea is to use a combination of cv2.waitKey to "slow down" the recording to match a targeted FPS which can then be passed to WriteGear.

That doesn't solve my performance problems but would allow me to create video at a fixed FPS within my performance limit. I think the example in WriteGear usage doesn't do this and I've not found anything in the docs to assist but this feels like a major thing, so maybe I'm missing something obvious?

I did some analysis by timing each step in the write loop. The below snippet was consistently the profile of where the time was spent.

read time: 0.0005109310150146484 time spent in "frame = stream.read()" write time: 0.03965616226196289 time spent in "writer.write(frame)" total time: 0.04016709327697754

As shown the write is taking the majority of the time. Is it essential the write is done in this loop? I could imagine a structure where we pass the frame to another thread with some enforcement of the ordering.

Acknowledgment

Context

I'm writing a python app that records screen and performs some analysis on the video before adding timestamps. This is causing my videos to play back in ~2/3rds of the real duration and skew my timestamps.

Your Environment

Thanks again, Alex

prmehta24 commented 1 year ago

@abhiTronix In my use case, I am using the execute_ffmpeg_cmd call to record live audio from a microphone to a file. In parallel, I would like to use writeGear to record live video from a camera to a separate file. I would like to stop both recordings on user input(pressing q maybe?) However, the current thread waits for the call execute_ffmpeg_cmd to finish.

  1. Is there any way to run both in parallel/together?
  2. How can I stop the call of execute_ffmpeg_cmd?