CAPTURING AND SAVING VIDEO FROM THE WEBCAM USING OPENCV AND PYTHON
The following python program shows how to save the video in your machine which is captured through the webcam. cv2.VideoWriter(filename.mp4, fourcc, fps, frame size) is the method used in the code.
Program :
import cv2
# Capturing videos from the webcam
video = cv2.VideoCapture(0)
# Defining codec
fourcc = cv2.VideoWriter_fourcc(*"XVID")
# Creating videowriter object
out = cv2.VideoWriter("asdf.mp4", fourcc, 20.0, (640, 480))
while video.isOpened():
success, img = video.read()
if success:
# writing frame by frame to the video file
out.write(img)
cv2.imshow("Video", img)
key = cv2.waitKey(1)
if key == 13:
exit()
else:
break
out.release()
Comments