def_extract_frames(self,video_file_path:str)->list:try:importcv2fromcv2.typingimportMatLikeexceptImportErrorase:raiseImportError("Unable to import cv2, please install it with ""`pip install -U opencv-python`")fromevideo_models:List[VideoModel]=[]def_add_model(start_time:int,end_time:int)->None:middle_frame_time=start_time/end_timecap.set(cv2.CAP_PROP_POS_MSEC,middle_frame_time)# Convert the frame to bytes_,encoded_frame=cv2.imencode(".jpg",frame)notable_frame_bytes=encoded_frame.tobytes()cap.set(cv2.CAP_PROP_POS_MSEC,end_time)# Create an instance of the ImageCaptionLoaderloader=ImageCaptionLoader(images=notable_frame_bytes)# Load captions for the imageslist_docs=loader.load()video_model=VideoModel(start_time,end_time,list_docs[len(list_docs)-1].page_content.replace("[SEP]","").strip(),)video_models.append(video_model)def_is_notable_frame(frame1:MatLike,frame2:MatLike,threshold:int)->bool:# Convert frames to grayscalegray1=cv2.cvtColor(frame1,cv2.COLOR_BGR2GRAY)gray2=cv2.cvtColor(frame2,cv2.COLOR_BGR2GRAY)# Compute absolute difference between framesframe_diff=cv2.absdiff(gray1,gray2)# Apply threshold to identify notable differences_,thresholded_diff=cv2.threshold(frame_diff,30,255,cv2.THRESH_BINARY)# Count the number of white pixels (indicating differences)num_diff_pixels=np.sum(thresholded_diff)returnnum_diff_pixels>threshold# Open the video filecap=cv2.VideoCapture(video_file_path)ifself.frame_skip==-1:self.frame_skip=int(cap.get(cv2.CAP_PROP_FPS))//self._SAMPLES_PER_SECOND# Read the first frameret,prev_frame=cap.read()# Loop through the video framesstart_time=0end_time=0whileTrue:# Read the next frameret,frame=cap.read()ifnotret:break# Break the loop if there are no more frames# Check if the current frame is notableif_is_notable_frame(prev_frame,frame,self.threshold):end_time=int(cap.get(cv2.CAP_PROP_POS_MSEC))_add_model(start_time,end_time)start_time=end_time# Update the previous frameprev_frame=frame.copy()# Increment the frame position by the skip valuecap.set(cv2.CAP_PROP_POS_FRAMES,cap.get(cv2.CAP_PROP_POS_FRAMES)+self.frame_skip,)# Release the video capture objectcap.release()returnvideo_models