if ret == True:
    frame = cv2.flip(frame, 0)
out.write(frame)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 255 == ord('q'):
    break
else:
    break
cap.release()
out.release()
cv2.destroyAllWindows()
openCV video saving in python