Above is the illustration flow chart of the main function. This is a pi-to-pi communication solution using UDP. Please be sure to check the IP address of both pis and change UDP_IP and DEST_IP accordingly. What's more, please create an empty folder "Video" or "Image" beforehand according to whether you want to take timestamped picture or video after motion detected.
Raspberry pi Setup/Camera Setup/Motion Detection/Taking Picture/Add timestamp/taking video: https://www.youtube.com/watch?v=RlUhDUJfTe8&list=PLNnwglGGYoTvy37TSGFlv-aFkpg7owWrE http://www.meccanismocomplesso.org/en/picamera-python-aggiungiamo-testi-sulle-immagini-e-video/
Python multithreading/thread synchronization: lock https://www.youtube.com/watch?v=XndHx3EaDgA&list=PLXkh7XR1GR6oPFcxYfuFPyiAqah2mBnpb