From 1ea3bd32ff4d667244e039b4146bb29892934a50 Mon Sep 17 00:00:00 2001 From: phileinSophos Date: Fri, 10 Jul 2020 18:39:04 +0530 Subject: [PATCH] Capture Video Frames --- projects/Capture_Video_Frames/README.md | 3 ++ .../capture_video_frames.py | 41 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 projects/Capture_Video_Frames/README.md create mode 100644 projects/Capture_Video_Frames/capture_video_frames.py diff --git a/projects/Capture_Video_Frames/README.md b/projects/Capture_Video_Frames/README.md new file mode 100644 index 00000000..7dc4a171 --- /dev/null +++ b/projects/Capture_Video_Frames/README.md @@ -0,0 +1,3 @@ +# Capture Video Frames +##### Execute +`python capture_video_frames.py ` diff --git a/projects/Capture_Video_Frames/capture_video_frames.py b/projects/Capture_Video_Frames/capture_video_frames.py new file mode 100644 index 00000000..4dc844f2 --- /dev/null +++ b/projects/Capture_Video_Frames/capture_video_frames.py @@ -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()