Python – Writing to video with OpenCV
In this article, we will discuss how to write to a video using OpenCV in Python.
- Import the required libraries into the working space.
- Read the video on which you have to write.
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
cap = cv2.VideoCapture("path")
- Create a output file using cv2.VideoWriter_fourcc() method
output = cv2.VideoWriter(“path”,cv2.VideoWriter_fourcc(*’MPEG’),30,(1080,1920))
- Then edit the frames of the video by adding shapes to it (for the example given here, the same can be applied to any other technique.).
cv2.rectangle(frame, (100,100), (500,500), (0,255,0), 3)
- Then write the video.
Example: Program to write to video