Skip to content

Instantly share code, notes, and snippets.

@tohansg
Forked from cooncesean/opencv.py
Last active August 29, 2015 14:13
Show Gist options
  • Save tohansg/6f1a889f10c92bd933c6 to your computer and use it in GitHub Desktop.
Save tohansg/6f1a889f10c92bd933c6 to your computer and use it in GitHub Desktop.
import cv
CAMERA_INDEX = 0
# CODEC = cv.CV_FOURCC('D','I','V','3') # MPEG 4.3
# CODEC = cv.CV_FOURCC('M','P','4','2') # MPEG 4.2
# CODEC = cv.CV_FOURCC('M','J','P','G') # Motion Jpeg
# CODEC = cv.CV_FOURCC('U','2','6','3') # H263
# CODEC = cv.CV_FOURCC('I','2','6','3') # H263I
# CODEC = cv.CV_FOURCC('F','L','V','1') # FLV
CODEC = cv.CV_FOURCC('P','I','M','1') # MPEG-1
CODEC = cv.CV_FOURCC('D','I','V','X') # MPEG-4 = MPEG-1
# Initialize the camera for video capture
capture = cv.CaptureFromCAM(CAMERA_INDEX)
# Initialize the video writer to write the file
writer = cv.CreateVideoWriter(
'/Users/sean/Desktop/out.avi', # Filename
CODEC, # Codec for compression
25, # Frames per second
(640, 480), # Width / Height tuple
True # Color flag
)
# Capture 50 frames and write each one to the file
for i in range(0, 25):
print 'frame #:', i
frame = cv.QueryFrame(capture)
cv.ShowImage("w1", frame)
cv.WriteFrame(writer, frame)
# Release the capture
del(capture)
del(writer)
print 'released capture'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment