Recorded video have 10 fps. RPi 5 - 2 camera V3 Wide Angle - Picamera2

May 2, 2024, 11:02

_.thelegend27._

Hi everyone ! I have a project in which I have 2 wide angle cameras connected on a RPi 5. For context, I work in animal cognition and we have monkey that have free access to touchscreen, the goal of this project is to start filming when they start playing on the screen and stop when they are finished. Since the aim is to an automated tracking of their hand on the touchscreen, I need to have video with a decent fps (50 fps would be great). However everytime I record a video via this code (see below) it results in 2 videos of 11 fps. I tried a lot of thing that I saw on the forums to change the fps but none seems to work, the only thing that ables me to control the fps is to create the video via the cmd but this way is not viable for I want to do 😦

_.thelegend27._

rpi_port = 3148
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.bind(f'tcp://*:{rpi_port}')
trial_id = "none"
msg = "none"
socket.setsockopt_string(zmq.SUBSCRIBE,"")

output_folder = "Video_rpi/"

res=(2304,1296)
framerate= 30.0
frame_duration = int(1_000_000 / framerate)

frontcam = Picamera2(0)
sidecam = Picamera2(1)

#config_front = sidecam.create_video_configuration()
frontcam.video_configuration.controls.FrameRate = framerate
frontcam.video_configuration.size = res

#config_side = sidecam.create_video_configuration()
sidecam.video_configuration.controls.FrameRate = framerate
sidecam.video_configuration.size = res

#frontcam.configure(config_front)
#frontcam.set_controls({"FrameRate": 30})

#sidecam.configure(config_side)
#sidecam.set_controls({"FrameRate": 30})

encoder_front = H264Encoder(bitrate=17000000)
encoder_side = H264Encoder(bitrate=17000000)

socket.RCVTIMEO = 10_000

_.thelegend27._

while True : 
    trial_id=""
    msg = ""

    try:
        print('hello')
        string= socket.recv().decode()
        trial_id, msg = string.split(";")
    except Exception as error:
        print('msg not received'+ str(error))
    print('trial: ',trial_id)
    print('msg: ',msg)

    if msg == "start_recording":
        
        output_name_front = output_folder +trial_id+"_front.mp4"
        output_name_side = output_folder+ trial_id+"_side_0.mp4"

        output_front = FfmpegOutput(output_name_front, audio=False)
        output_side = FfmpegOutput(output_name_side, audio=False)

        front_start = time.time()
        frontcam.start_recording(encoder_front,output_front)
        side_start = time.time()
        sidecam.start_recording(encoder_side,output_side)
        
        start_diff = side_start-front_start
        
        try:
            print('hello')
            string= socket.recv().decode()
            trial_id, msg = string.split(";")
        except Exception as error:
            print('msg not received'+ str(error))
        print('trial: ',trial_id)
        print('msg: ',msg)
        
        side_end = time.time()
        sidecam.stop_recording()

        front_end = time.time()
        frontcam.stop_recording()
        end_diff = side_end - front_start


        first_frame = int(start_diff*framerate)

        os.rename(output_name_front, output_folder +trial_id+"_front_"+str(first_frame)+".mp4")
    time.sleep(0.001)
    

socket.setsockopt(zmq.LINGER, 0)
socket.close()
context.term()