In [1]:
import cv2
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline

In [ ]:
print(camera.get(cv2.CAP_PROP_FPS), camera.get(cv2.CAP_PROP_FORMAT), camera.get(cv2.CAP_PROP_FOURCC), camera.get(cv2.CAP_PROP_POS_MSEC))
print(camera.get(cv2.CAP_PROP_FRAME_COUNT))

In [4]:
def resize(image, width = None, height = None, inter = cv2.INTER_AREA):
	# initialize the dimensions of the image to be resized and
	# grab the image size
	dim = None
	(h, w) = image.shape[:2]

	# if both the width and height are None, then return the
	# original image
	if width is None and height is None:
		return image

	# check to see if the width is None
	if width is None:
		# calculate the ratio of the height and construct the
		# dimensions
		r = height / float(h)
		dim = (int(w * r), height)

	# otherwise, the height is None
	else:
		# calculate the ratio of the width and construct the
		# dimensions
		r = width / float(w)
		dim = (width, int(h * r))

	# resize the image
	resized = cv2.resize(image, dim, interpolation = inter)

	# return the resized image
	return resized

In [7]:
video_file = 'd:/tmp/video/a1.mp4'
camera = cv2.VideoCapture(video_file)
count = 0
fps = int(camera.get(cv2.CAP_PROP_FPS))
print('fps', fps)
while True:
    (grabbed, frame) = camera.read()
    if not grabbed:
        break
    if count % fps == 0:
#         gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        frame = resize(frame, width=300)
        cv2.imwrite('d:/tmp/video/img_{}.jpg'.format(count), frame)
        print('save', count)
    count+=1
#     frame = resize(frame, width=300)
#     gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    if cv2.waitKey(1)&0xFF==ord('q'):
        break
camera.release()


fps 24
save 0
save 24
save 48
save 72
save 96
save 120
save 144
save 168
save 192
save 216
save 240
save 264
save 288
save 312
save 336
save 360
save 384

In [ ]: