I have a raspberry Pi 4b with bookworm 64-bit installed.
I'm working on a multiprocessing-script. And I cannot get it to work.
What it supposed to do is:
def waiting():
VLC pauses a video on the first frame,
def play():
when motion is detected, 2 functions should run at the same time:
Process1: play the video
def record():
Process2: record with the camera.
When above is finished,VLC pauses a video again on the first frame waiting for motion.
The Code:The output in the terminal show this:
I tested the def record() in a seperat script. That works good.
What is not oke in this script?
I'm working on a multiprocessing-script. And I cannot get it to work.
What it supposed to do is:
def waiting():
VLC pauses a video on the first frame,
def play():
when motion is detected, 2 functions should run at the same time:
Process1: play the video
def record():
Process2: record with the camera.
When above is finished,VLC pauses a video again on the first frame waiting for motion.
The Code:
Code:
from gpiozero import MotionSensorfrom time import sleepfrom picamera2 import Picamera2from picamera2.encoders import H264Encoder, Qualityimport vlcimport datetimefrom multiprocessing import Process# Creating Instance class objectvlc_instance = vlc.Instance()player = vlc_instance.media_player_new()player.set_fullscreen(False) # Define Motion Sensorpir = MotionSensor(4)# Camerapicam2 = Picamera2()video_config = picam2.create_video_configuration()#main={"size":(1280,720)})picam2.configure(video_config)picam2.rotation = 180encoder = H264Encoderoutput = '/home/path-to-dir/Recordings/' + datetime.datetime.now().strftime('%Y-%m-%d_%H.%M.%S.h264')def waiting(): print("Ready") pir.wait_for_no_motion() sleep(.1) player.set_mrl("/home/path-to-dir/Video/Test.mp4") player.play() sleep(.1)def play(): pir.wait_for_motion() sleep(.1) print("Motion detected") sleep(.1) player.set_mrl("/home/path-to-dir/Video/Test.mp4") player.play() sleep(.1)def record(): print ("Start recording") picam2.start_recording(encoder, output, quality=Quality.HIGH) sleep(13) picam2.stop_recording() sleep(15)if __name__ == "__main__": waiting() while True: try: process1 = Process(target=play) process2 = Process(target=record) process1=start() process2=start() process1=join() process2=join() sleep(.1) except KeyboardInterrupt: print("Interrupted") break except: continue
The last line keeps repeating[0000007f4c09b550] wl_xdg_shell window: <<< WL XDG, type=0
[0000007f48001410] wl_dmabuf vout display: <<< Open: DPV0 720x480(720x480 @ 0,0 0/0), cfg.display: 853x480, source: 720x480(720x480 @ 0,0 32/27)
[0000007f4c009fc0] avcodec decoder: Using DRM Video Accel for hardware decoding
[0000007f4c009fc0] avcodec decoder error: more than 5 seconds of late video -> dropping frame (computer too slow ?)
I tested the def record() in a seperat script. That works good.
What is not oke in this script?
Statistics: Posted by Wessiez — Mon Nov 11, 2024 5:04 pm