I am building a wildlife camera (referenced from this wonderful guide: https://peaknature.co.uk/blog/how-to-bu ... e-hardware) but instead of just recording video when detecting motion, I would like to also snap a photo (maybe 15 seconds in) that would tweet the photo or send it to my phone, for example.
Is it possible to do that while the recording is happening?
Here's an example of my code:
Code: Select all
while True:
pir.wait_for_motion()
logging.info('Motion detected')
print('Motion detected')
while pir.motion_detected:
print('Beginning capture')
ts = '{:%Y%m%d-%H%M%S}'.format(datetime.now())
logging.info('Beginning capture: '+ str(ts)+'.h264')
with picamera.PiCamera() as cam:
cam.resolution=(1024,768)
cam.annotate_background = picamera.Color('black')
cam.start_recording('/home/pi/video.h264')
start = datetime.now()
while (datetime.now() - start).seconds < duration:
cam.annotate_text = datetime.now().strftime('%d-%m-%y %H:%M:%S')
cam.wait_recording(0.2)
cam.stop_recording()
time.sleep(1)
print('Stopped recording')EDIT: So I did some digging, and I read that it is possible, but I'm not quite sure where to place the code. I have it in the while loop here, right before "cam.stop_recording()":
Code: Select all
cam.start_recording('/home/pi/video.h264')
start = datetime.now()
while (datetime.now() - start).seconds < duration:
cam.annotate_text = datetime.now().strftime('%m-%d-%Y_(%I-%M-%S_%p)')
cam.wait_recording(0.2)
camera.capture('image.jpg', use_video_port=True)
cam.stop_recording()