Getting specific frames from VideoCapture opencv in python

this is my first post so please don't rip into me if I don't follow protocol completely. I just wanted to respond to June Wang just in case she didn't figure out how to set the number of frames to be extracted, or in case anyone else stumbles upon this thread with that question:

The solution is the good ol' for loop:

    vid = cv2.VideoCapture(video_path)
    for i in range(start_frame, how_many_frames_you_want):
        vid.set(1, i)
        ret, still = vid.read()
        cv2.imwrite(f'{video_path}_frame{i}.jpg', still)

You can use set() function of VideoCapture.

You can calculate total frames:

cap = cv2.VideoCapture("video.mp4")
total_frames = cap.get(7)

Here 7 is the prop-Id. You can find more here http://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html

After that you can set the frame number, suppose i want to extract 100th frame

cap.set(1, 100)
ret, frame = cap.read()
cv2.imwrite("path_where_to_save_image", frame)