Extracts a video's frame incrementally. Commonly used for Gimmick accs on Twitter
## Works as a module, so you can call
from {whatever_you_called_the_file} import VideoFrameUtil
self.cap = cv2.VideoCapture(self.video_path) ## USE THIS ONE IF YOU KNOW WHAT YOU ARE DOING
self.current_frame = 0
self.frame_rate = self.cap.get(cv2.CAP_PROP_FPS)
self.frame_total = self.cap.get(cv2.CAP_PROP_FRAME_COUNT)
## Have to be set localy, so video file and output folder in the same directory as the script.
VideoReader = VideoFrameUtil("test.mp4", "output")
## Start and get the closest frame at 3.1 seconds
start = self.SecondsToFrame(3.1)
VideoReader.SetCurrentFrame(0) ## Place at the begining
frames_1 = VideoReader.GetFramesForTime(1, 3)
frames_all = VideoReader.GetAllFrames()
VideoReader.SetCurrentFrame(0)
while True:
data = VideoReader.GetNextFrame()
path = data[0]
image = data[1]
## Do whatever you want, keep reference to the image and add it to the Media Array when tweeting for example.
## Its important to close the reader whenever you are done, to save memory and keep it clean.
VideoReader.Close()