Skip to content

Instantly share code, notes, and snippets.

@rabssm
Last active May 10, 2024 23:38
Show Gist options
  • Save rabssm/b067e448c1655aabfae6e95a4f7b4967 to your computer and use it in GitHub Desktop.
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
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