0

I'm working on a code, which reads incoming videos from Raspberry Pi, performs face detection on the frames, places frames around the faces, and then write backs the frames into an MP4 file with the same FPS. I use OpenCV to open and read from the PiCam.

When I looked into the saved video, it looks like it's moving too fast. I let my code to run for around 2 minutes, but my video has a length of 30 second. When I disable all post-processings (face detection), I can observe stable speed on the output video.

I can understand that Raspberry Pi has a small processor for heavy computations, but cannot understand why the video length is shorter? Is it possible that my face detection pipeline running much slower than the camera FPS, so the camera buffer should drop frames that are not going to be grabbed by the pipeline in a timely-fashion?

Any help here is highly appreciated!

saman
  • 199
  • 4
  • 17
  • if you want 2 minutes (`2*60` seconds) with 30 FPS then movie needs `2*60*30` frames - `3600 frames`. If you write less frame then you get shorter video and it will run faster.- Setting 30 FPS will only inform player how fast to display frames but It will not add missing frames. If you run from PiCam then you will have to read and write 30 frames in every second so for every frame you have only 33ms (1000ms / 30). The only idea - run it in two threads - one thread to read frames from camera, process it and put in buffer/variable. Second thread to write buffer every 33ms – furas Jun 18 '21 at 20:09
  • yes, camera with 30FPS can get new image from led sensor every 33ms and put in buffer - but if code run slower then it has no time to get new frame every 33ms so it loose some frames. And if code run faster then it may get the same frame few times and it may generate slower video. – furas Jun 18 '21 at 20:17
  • Interesting. I can see here is mentioned that if the code run faster, then it may get the same frame few times. I was assuming that when we read the frame, then it no longer be read again. If we go back to read from the camera really fast, then I thought the code should get blocked on the function call until it receives the new frame. Now, how can I make sure I read each frame only once? – saman Jun 19 '21 at 02:19

0 Answers0