import sys
import cv2


cap = cv2.VideoCapture(0)
print("Tiempo de grabado:"+sys.argv[1])
# Define the codec and create VideoWriter object
fourcc = cv2.cv.CV_FOURCC(*'XVID')
out = cv2.VideoWriter('/var/www/html/RegislogWeb/videos/'+str(sys.argv[2])+'.avi',fourcc, 10.0, (640,480))

numero_fotogramas = 0
while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,1)
        # write the flipped frame
        out.write(frame)
        numero_fotogramas += 1;
    print("Fotogramas: "+str(numero_fotogramas))
    if numero_fotogramas >= (10*int(sys.argv[1])):
        break
# Release everything if job is finished
print("Finalizando aplicacion")
cap.release()
out.release()
cv2.destroyAllWindows()