Last Updated : 11 Aug, 2025
In video processing, adding a timestamp directly onto video frames is a useful feature for applications like surveillance, monitoring and logging. Using OpenCV in Python, we can capture each video frame and overlay the current date and time fetched from the datetime module, making the video feed more informative and time-aware.
ApproachPrerequisites:
To display the current date and time on video frames:
import cv2
import datetime
vid = cv2.VideoCapture('sample.mp4')
while vid.isOpened():
ret, frame = vid.read()
if not ret:
break
font = cv2.FONT_HERSHEY_SCRIPT_COMPLEX
dt = str(datetime.datetime.now())
frame = cv2.putText(frame, dt,
(10, 100), # Position (x, y)
font, 1, # Font and scale
(210, 155, 155), # Color (B, G, R)
2, # Thickness
cv2.LINE_8) # Line type
cv2.imshow('Video with Date & Time', frame)
key = cv2.waitKey(1)
if key == ord('q') or key == 27: # Quit on 'q' or ESC
break
vid.release()
cv2.destroyAllWindows()
Output
Explanation:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4