#saveCameraVideo

import numpy as np
import cv2 as cv

cap = cv.VideoCapture(0)

#Define the codec and create the VideoWriter object
fourcc = cv.cv.CV_FOURCC(*'XVID')
out = cv.VideoWriter('output.avi', fourcc, 20.0, (640,480))

while(cap.isOpened()):
	ret, frame = cap.read()
	if ret == True:
		frame = cv.flip(frame,0)
		
		#write the flipped frame
		out.write(frame)
		
		cv.imshow('frame',frame)
		if cv.waitKey(1) & 0xFF == ord('q'):
			break
	else:
		break
		
#Release everything if job is finished
cap.release()
out.release()
cv.destroyAllWindows()