Last active
May 10, 2024 23:38
-
-
Save rabssm/b067e448c1655aabfae6e95a4f7b4967 to your computer and use it in GitHub Desktop.
Record video on the raspberry pi camera module with timestamp annotation on each frame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import picamera | |
import picamera.array | |
import time, datetime | |
# Use the motiondetector analyze callback to annotate the video with a UTC time stamp | |
class MotionDetector(picamera.array.PiMotionAnalysis): | |
def analyze(self, a): | |
camera.annotate_text = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] | |
with picamera.PiCamera() as camera: | |
camera.resolution = (1296, 972) | |
camera.framerate = 24 | |
camera.annotate_text_size = 16 | |
filename = "video-%s.h264" % time.strftime("%Y%m%d-%H%M%S-%Z", time.localtime()) | |
camera.start_recording(filename, motion_output=MotionDetector(camera), sps_timing=True) | |
camera.wait_recording(120) | |
camera.stop_recording() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment