I am currently working on keyframe extraction from videos.
Code :
while success:
success, currentFrame = vidcap.read()
isDuplicate = False
You may use the following code snippet which iterated through all the frames and checks for the difference between the frames as:
import cv2
import numpy as np
video_path = "/Users/anmoluppal/Downloads/SampleVideo_1280x720_1mb.mp4"
p_frame_thresh = 300000 # You may need to adjust this threshold
cap = cv2.VideoCapture(video_path)
# Read the first frame.
ret, prev_frame = cap.read()
while ret:
ret, curr_frame = cap.read()
if ret:
diff = cv2.absdiff(curr_frame, prev_frame)
non_zero_count = np.count_nonzero(diff)
if non_zero_count > p_frame_thresh:
print "Got P-Frame"
prev_frame = curr_frame