Skip to content

Instantly share code, notes, and snippets.

@TheAnonymous
Last active September 18, 2015 13:25
Show Gist options
  • Save TheAnonymous/8aeaebeb884a1c29599f to your computer and use it in GitHub Desktop.
Save TheAnonymous/8aeaebeb884a1c29599f to your computer and use it in GitHub Desktop.
import numpy as np
import cv2
#from matplotlib import pyplot as plt
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FPS, 20)
# Define the codec and create VideoWriter object
#fourcc = cv2.cv.CV_FOURCC(*'DIVX')
###width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH) + 0.5)
###height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT) + 0.5)
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
#w=int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH ))
#h=int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT ))
out = cv2.VideoWriter('~/Desktop/output.mp4',fourcc, 20.0, size, True)
while cap.isOpened():
ret, frame = cap.read()
if ret:
if frame is not None:
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment