I would like to record video to a file using the picamera module, and "save" the file every few seconds so that in the case of a power outage the video is partially saved, instead of being empty all together.

I have tried

import picamera
from time import sleep

fd = open("test.h264", "wb+")
camera = picamera.PiCamera()
camera.start_recording(fd, format='h264', quality=23)

for _ in range(20):


But the resulting file test.h264 is empty. Looking at the documentation, I could also try to create a BytesIO stream object and save that to a file periodically, but I do not really know how to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.