Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions projects/Capture_Video_Frames/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Capture Video Frames
##### Execute
`python capture_video_frames.py <video_file>`
41 changes: 41 additions & 0 deletions projects/Capture_Video_Frames/capture_video_frames.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import shutil
import sys
import cv2

class FrameCapture:
'''
Class definition to capture frames
'''
def __init__(self, file_path):
'''
initializing directory where the captured frames will be stored.
Also truncating the directory where captured frames are stored, if exists.
'''
self.directory = "captured_frames"
self.file_path = file_path
if os.path.exists(self.directory):
shutil.rmtree(self.directory)
os.mkdir(self.directory)

def capture_frames(self):
'''
This method captures the frames from the video file provided.
This program makes use of openCV library
'''
cv2_object = cv2.VideoCapture(self.file_path)

frame_number = 0
frame_found = 1

while frame_found:
frame_found, image = cv2_object.read()
capture = f'{self.directory}/frame{frame_number}.jpg'
cv2.imwrite(capture, image)

frame_number += 1

if __name__ == '__main__':
file_path = sys.argv[1]
fc = FrameCapture(file_path)
fc.capture_frames()