0

I am trying to record a video using camera.start_recording from picamerapackage until a specific predefined time is reached. I was trying to counter this problem using code similar to the following MWE.

import picamera
import time

time_to_record = 15

camera = picamera.PiCamera()
camera.resolution = (1920, 1080)
camera.framerate = 24

end_time = time.time() + time_to_record
while time.time() <= end_time:
            camera.start_recording('Test.h264', format='h264')
            # Here is another functions that samples a value from a thermocouple and annotates it in the video

           

Because of the function mentioned in the comment I'm not able to use the method camera.wait_recording() from the picamera package. The camera needs to run for a specific time so the loop has to stay. When I run my code I get the following exception:

camera.PiCameraAlreadyRecording

which mentions that the Camera is already recording. I'm think that this is a problem comming from the while loop because the camera.start_recording() method is called multiple times. I don't have an idea how I can avoid this problem without dropping the ability to record for a specific time. Maybe someone has an idea?

CR36
  • 13
  • 3
  • Is there a reason you cannot simply move `camera.start_recording` to the line before the while loop? – Teejay Bruno Apr 13 '21 at 22:49
  • Yes, as I mentioned the function that retrieves the values from the thermocouple also runs inside this loop and so to have a video that is as long as the measurement helps me to relate the temperature values to other measured data. – CR36 Apr 14 '21 at 05:06
  • So leave that function alone and just start the recording right before the while loop. Maybe I'm missing something? – Teejay Bruno Apr 14 '21 at 16:44
  • I don't think this will solve the problem. Inside the function the camera is also temperature controlled. So there is another if clause that starts the actual recording process when a critical temperature is reached. I'm currently thinking that maybe threading the different tasks will bring a solution. Because I therefore can control the different AiO's, – CR36 Apr 15 '21 at 05:13
  • post your full code and I'd be happy to help. As it stands there's not enough info to come up with an optimal answer. – Teejay Bruno Apr 15 '21 at 18:19

0 Answers0