A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/display-date-and-time-in-videos-using-python-opencv/ below:

Display date and time in videos using OpenCV - Python

Display date and time in videos using OpenCV - Python

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.

Prerequisites: 

Approach

To display the current date and time on video frames:

  1. Capture the video using cv2.VideoCapture().
  2. Read video frames in a loop.
  3. Fetch the current system time using datetime.datetime.now().
  4. Use cv2.putText() to overlay the timestamp on each frame.
  5. Display the updated frames until the video ends or the user quits.
Python Implementation Python
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