Skip to content
Related Articles

Related Articles

Extract Video Frames from Webcam and Save to Images using Python

Improve Article
Save Article
Like Article
  • Last Updated : 19 Aug, 2021

OpenCV library can be used to perform multiple operations on videos. Let’s try to do something interesting using CV2. Le’s record a video as form webcam and break the video into the frame by frame and save those frames. 


This module does not come built-in with Python. To install it type the below command in the terminal.

pip install opencv-python

Steps Required.

  1. Open the Video file using cv2.VideoCapture(<path_of_video>) or If you do not have any video you can directly use your inbuilt camera using  cv2.VideoCapture(0)  command.
  2. Read frame by frame
  3. Save each frame using cv2.imwrite()
  4. Release the VideoCapture and destroy all windows

Below is the implementation.


import cv2
# Opens the inbuilt camera of laptop to capture video.
cap = cv2.VideoCapture(0)
i = 0
    ret, frame =
    # This condition prevents from infinite looping
    # incase video ends.
    if ret == False:
    # Save Frame by Frame into disk using imwrite method
    cv2.imwrite('Frame'+str(i)+'.jpg', frame)
    i += 1


python opencv extract frames from video


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!