Skip to content

Instantly share code, notes, and snippets.

@tatesuke
Created April 10, 2019 02:08
Show Gist options
  • Save tatesuke/25a8005566e2a37b9fe09acd3ea4455c to your computer and use it in GitHub Desktop.
Save tatesuke/25a8005566e2a37b9fe09acd3ea4455c to your computer and use it in GitHub Desktop.
pythonで動画撮影(音声なし)
import numpy as np
import cv2
import datetime
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,0)
print(frame.shape)
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (frame.shape[1],frame.shape[0]))
startTime = int(datetime.datetime.now().timestamp())
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,0)
# write the flipped frame
out.write(frame)
now = int(datetime.datetime.now().timestamp())
if (now - startTime) >= 5:
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