Skip to content
Related Articles

Related Articles

Improve Article
Display date and time in videos using OpenCV – Python
  • Last Updated : 26 Mar, 2020

OpenCV-Python is a library of Python bindings designed to solve computer vision problems. It can process images and videos to identify objects, faces, or even the handwriting of a human

Note: For more information, refer to Introduction to OpenCV

Display date and time in videos

It sometimes becomes necessary to display date and time on videos when we are processing videos of live feed or videos which are of a large duration. Time and date will be helpful to know and analyze any anomaly detected in the video with reference to its time and date. To display date and time on videos we do the following.


# Import libraries
import numpy
import cv2
import datetime
# open the video
vid = cv2.VideoCapture('sample.mp4')
# Process untill end.
    ret, frame =
    if ret:
        # describe the type of 
        # font you want to display
        # Get date and time and 
        # save it inside a variable
        dt = str(
        # put the dt variable over the
        # video frame
        frame = cv2.putText(frame, dt,
                            (10, 100),
                            font, 1,
                            (210, 155, 155), 
                            4, cv2.LINE_8)
        # show the video
        cv2.imshow('frame', frame)
        key = cv2.waitKey(1)
        # define the key to
        # close the window
        if key == 'q' or key == 27:
# release the vid object
# close all the opened windows.


 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :