Skip to content

Instantly share code, notes, and snippets.

@AsharFatmi
Created October 7, 2019 07:00
Show Gist options
  • Save AsharFatmi/41b5878998a45cd828537d711a8320f3 to your computer and use it in GitHub Desktop.
Save AsharFatmi/41b5878998a45cd828537d711a8320f3 to your computer and use it in GitHub Desktop.
Python script to record video from camera without cv2.imshow. to stop recording just hit ctrl+c .
import numpy as np
import cv2
cap = cv2.VideoCapture(0) # for IPCamera format : rtsp://admin:[email protected]:554/1
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('traffic_video_back.mp4',fourcc, 15.0, (1920,1080))
frame_count = 0
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
#frame = cv2.flip(frame,0)
# write the flipped frame
out.write(frame)
frame_count += 1
if frame_count % 100 == 0:
print('frame count = ', frame_count)
#cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
pass
# 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