raspberrypi / picamera2

New libcamera based python library
BSD 2-Clause "Simplified" License
901 stars 190 forks source link

[OTHER] DRM Preview interrupts the video recording #742

Open jameshesser opened 1 year ago

jameshesser commented 1 year ago

We have a multi camera synchronized application, currently written in PiCamera1, that records video at exactly 30fps in one minute chunks, with no frames lost between files. The first and last frames of each file are timestamped from system time. We are trying to port this application to PiCamera2 and we have a problem recording a video with the preview window visible.

When I try to record the video with the preview window using the picamera2 library, I can easily see that the FPS drops. I ran another test without the preview window and was able to get the 30 FPS video as expected.

I tried using the libcamera-vid command to reproduce the same problem, but it seems that libcamera works fine without any problems. When I ran the following command, it displayed a preview window and recorded the video at the same time. libcamera-vid -t 60000 -o sample.h264. I was able to confirm that the FPS appears to be exactly 30 fps.

Someone said it's because the DRM preview display is waiting for the display vsync (https://forums.raspberrypi.com/viewtopic.php?t=344880). We are running the code on the latest Raspberry Pi OS Lite (Bullseye) and using DRM preview as it is highly recommended for Raspberry Pi OS Lite users. Is there a solution to record the video with the preview window visible without a decrease in FPS? Thank you.

davidplowman commented 1 year ago

Hi, I think you're correct about what's happening. There isn't a workaround at the moment. Obviously the solution would be to delegate the DRM calls to another thread, but obviously there's some effort required to do that.