Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python | Program to extract frames using OpenCV

  • Difficulty Level : Easy
  • Last Updated : 15 May, 2018

OpenCV comes with many powerful video editing functions. In current scenario, techniques such as image scanning, face recognition can be accomplished using OpenCV.

OpenCv library can be used to perform multiple operations on videos. Let’s try to do something interesting using CV2. Take a video as input and break the video into frame by frame and save those frame. Now, number of operations can be performed on these frames. Like reversing the video file or crop the video etc. For playing video in reverse mode, we need only to store the frames in a list and iterate reverse in the list of frames. Use reverse method of the list for reversing the order of frames in the list.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Function Used :

VideoCapture(File_path) : Read the video(.mp4 format)

read() : Read data depending upon the type of object that calls

imwrite(filename, img[, params]) : Saves an image to a specified file.

Below is the implementation :

# Program To Read video
# and Extract Frames
import cv2
# Function to extract frames
def FrameCapture(path):
    # Path to video file
    vidObj = cv2.VideoCapture(path)
    # Used as counter variable
    count = 0
    # checks whether frames were extracted
    success = 1
    while success:
        # vidObj object calls read
        # function extract frames
        success, image =
        # Saves the frames with frame-count
        cv2.imwrite("frame%d.jpg" % count, image)
        count += 1
# Driver Code
if __name__ == '__main__':
    # Calling the function

Output :

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!